1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vdoc: make vexe_path a const

This commit is contained in:
Don Alfons Nisnoni 2020-06-05 20:22:50 +08:00 committed by GitHub
parent 0aadde2673
commit 44442223a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,9 +11,10 @@ import v.vmod
const ( const (
allowed_formats = ['md', 'markdown', 'json', 'text', 'stdout', 'html', 'htm'] allowed_formats = ['md', 'markdown', 'json', 'text', 'stdout', 'html', 'htm']
exe_path = os.executable() exe_path = os.executable()
exe_dir = os.dir(exe_path) exe_dir = os.dir(exe_path)
res_path = os.join_path(exe_dir, 'vdoc-resources') res_path = os.join_path(exe_dir, 'vdoc-resources')
vexe_path = os.base_dir(@VEXE)
) )
enum OutputType { enum OutputType {
@ -27,18 +28,18 @@ enum OutputType {
struct DocConfig { struct DocConfig {
mut: mut:
pub_only bool = true pub_only bool = true
show_loc bool = false // for plaintext show_loc bool = false // for plaintext
serve_http bool = false // for html serve_http bool = false // for html
is_multi bool = false is_multi bool = false
is_verbose bool = false is_verbose bool = false
include_readme bool = false include_readme bool = false
inline_assets bool = false inline_assets bool = false
output_path string output_path string
input_path string input_path string
output_type OutputType = .unset output_type OutputType = .unset
docs []doc.Doc docs []doc.Doc
manifest vmod.Manifest manifest vmod.Manifest
} }
fn slug(title string) string { fn slug(title string) string {
@ -384,7 +385,7 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
} }
is_vlib := 'vlib' in cfg.input_path is_vlib := 'vlib' in cfg.input_path
dir_path := if is_vlib { dir_path := if is_vlib {
os.base_dir(@VEXE) vexe_path
} else if os.is_dir(cfg.input_path) { } else if os.is_dir(cfg.input_path) {
cfg.input_path cfg.input_path
} else { } else {
@ -486,7 +487,6 @@ fn (cfg DocConfig) vprintln(str string) {
fn lookup_module(mod string) ?string { fn lookup_module(mod string) ?string {
mod_path := mod.replace('.', os.path_separator) mod_path := mod.replace('.', os.path_separator)
vexe_path := os.base_dir(@VEXE)
compile_dir := os.real_path(os.base_dir('.')) compile_dir := os.real_path(os.base_dir('.'))
modules_dir := os.join_path(compile_dir, 'modules', mod_path) modules_dir := os.join_path(compile_dir, 'modules', mod_path)
vlib_path := os.join_path(vexe_path, 'vlib', mod_path) vlib_path := os.join_path(vexe_path, 'vlib', mod_path)
@ -595,7 +595,7 @@ fn main() {
is_path := cfg.input_path.ends_with('.v') || cfg.input_path.split(os.path_separator).len > 1 || cfg.input_path == '.' is_path := cfg.input_path.ends_with('.v') || cfg.input_path.split(os.path_separator).len > 1 || cfg.input_path == '.'
if cfg.input_path == 'vlib' { if cfg.input_path == 'vlib' {
cfg.is_multi = true cfg.is_multi = true
cfg.input_path = os.join_path(os.base_dir(@VEXE), 'vlib') cfg.input_path = os.join_path(vexe_path, 'vlib')
} else if !is_path { } else if !is_path {
cfg.vprintln('Input "$cfg.input_path" is not a valid path. Looking for modules named "$cfg.input_path"...') cfg.vprintln('Input "$cfg.input_path" is not a valid path. Looking for modules named "$cfg.input_path"...')
mod_path := lookup_module(cfg.input_path) or { mod_path := lookup_module(cfg.input_path) or {