From 5b8402bccb5f0a5b8660dcdb9682ac8ef52334cc Mon Sep 17 00:00:00 2001 From: R cqls Date: Tue, 25 May 2021 06:46:40 +0200 Subject: [PATCH] parser: fix mod_path_to_full_name to be compliant with --path option (#10149) --- vlib/v/parser/parser.v | 2 +- vlib/v/util/module.v | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 371dee48f3..4cdb421acb 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2544,7 +2544,7 @@ fn (mut p Parser) module_decl() ast.Module { } module_pos = attrs_pos.extend(name_pos) } - full_name := util.qualify_module(name, p.file_name) + full_name := util.qualify_module(p.pref, name, p.file_name) p.mod = full_name p.builtin_mod = p.mod == 'builtin' mod_node = ast.Module{ diff --git a/vlib/v/util/module.v b/vlib/v/util/module.v index a2e1abd0fd..b16e791ee7 100644 --- a/vlib/v/util/module.v +++ b/vlib/v/util/module.v @@ -15,20 +15,20 @@ pub fn qualify_import(pref &pref.Preferences, mod string, file_path string) stri for search_path in mod_paths { try_path := os.join_path(search_path, mod_path) if os.is_dir(try_path) { - if m1 := mod_path_to_full_name(mod, try_path) { + if m1 := mod_path_to_full_name(pref, mod, try_path) { trace_mod_path_to_full_name(@LINE, mod, try_path, m1) return m1 } } } - if m1 := mod_path_to_full_name(mod, file_path) { + if m1 := mod_path_to_full_name(pref, mod, file_path) { trace_mod_path_to_full_name(@LINE, mod, file_path, m1) return m1 } return mod } -pub fn qualify_module(mod string, file_path string) string { +pub fn qualify_module(pref &pref.Preferences, mod string, file_path string) string { if mod == 'main' { return mod } @@ -38,7 +38,7 @@ pub fn qualify_module(mod string, file_path string) string { if clean_file_path.replace(os.getwd() + os.path_separator, '') == mod { return mod } - if m1 := mod_path_to_full_name(mod, clean_file_path) { + if m1 := mod_path_to_full_name(pref, mod, clean_file_path) { trace_mod_path_to_full_name(@LINE, mod, clean_file_path, m1) return m1 } @@ -50,10 +50,15 @@ pub fn qualify_module(mod string, file_path string) string { // * if possible split this function in two, one which gets the // parent module path and another which turns it into the full name // * create shared logic between these fns and builder.find_module_path -pub fn mod_path_to_full_name(mod string, path string) ?string { +pub fn mod_path_to_full_name(pref &pref.Preferences, mod string, path string) ?string { // TODO: explore using `pref.lookup_path` & `os.vmodules_paths()` // absolute paths instead of 'vlib' & '.vmodules' - vmod_folders := ['vlib', '.vmodules', 'modules'] + mut vmod_folders := ['vlib', '.vmodules', 'modules'] + for base in pref.lookup_path.map(os.base(it)) { + if !(base in vmod_folders) { + vmod_folders << base + } + } mut in_vmod_path := false for vmod_folder in vmod_folders { if path.contains(vmod_folder + os.path_separator) {