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

cmd/v: rewrite flags

This commit is contained in:
lutherwenxu
2020-03-07 01:53:29 +08:00
committed by GitHub
parent 522de0871a
commit aab31f4b35
37 changed files with 1087 additions and 464 deletions

View File

@ -154,7 +154,6 @@ fn (v &V) module_path(mod string) string {
// 'installed_mod' => '~/.vmodules/installed_mod'
// 'local_mod' => '/path/to/current/dir/local_mod'
fn (v mut V) set_module_lookup_paths() {
mlookup_path := if v.pref.vpath.len > 0 { v.pref.vpath } else { v_modules_path }
// Module search order:
// 0) V test files are very commonly located right inside the folder of the
// module, which they test. Adding the parent folder of the module folder
@ -163,21 +162,18 @@ fn (v mut V) set_module_lookup_paths() {
// 1) search in the *same* directory, as the compiled final v program source
// (i.e. the . in `v .` or file.v in `v file.v`)
// 2) search in the modules/ in the same directory.
// 3) search in vlib/
// 4.1) search in -vpath (if given)
// 4.2) search in ~/.vmodules/ (i.e. modules installed with vpm) (no -vpath)
// 3) search in the provided paths
// By default, these are what (3) contains:
// 3.1) search in vlib/
// 3.2) search in ~/.vmodules/ (i.e. modules installed with vpm)
v.module_lookup_paths = []
if v.pref.is_test {
v.module_lookup_paths << filepath.basedir(v.compiled_dir) // pdir of _test.v
}
v.module_lookup_paths << v.compiled_dir
v.module_lookup_paths << filepath.join(v.compiled_dir,'modules')
v.module_lookup_paths << v.pref.vlib_path
v.module_lookup_paths << mlookup_path
if v.pref.user_mod_path.len > 0 {
v.module_lookup_paths << v.pref.user_mod_path
}
if v.pref.is_verbose {
v.module_lookup_paths << v.pref.lookup_path
if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('v.module_lookup_paths: $v.module_lookup_paths')
}
}
@ -195,11 +191,11 @@ fn (p mut Parser) find_module_path(mod string) ?string {
mod_path := p.v.module_path(mod)
for lookup_path in module_lookup_paths {
try_path := filepath.join(lookup_path,mod_path)
if p.v.pref.is_verbose {
if p.v.pref.verbosity.is_higher_or_equal(.level_three) {
println(' >> trying to find $mod in $try_path ...')
}
if os.is_dir(try_path) {
if p.v.pref.is_verbose {
if p.v.pref.verbosity.is_higher_or_equal(.level_three) {
println(' << found $try_path .')
}
return try_path