diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 701293074a..cce6104163 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -197,7 +197,7 @@ fn module_path(mod string) string { pub fn (b Builder) find_module_path(mod, fpath string) ?string { // support @VROOT/v.mod relative paths: - vmod_file_location := vmod.mod_file_cacher.get(fpath) + vmod_file_location := vmod.mod_file_cacher.get_by_file(fpath) mod_path := module_path(mod) mut module_lookup_paths := []string{} if vmod_file_location.vmod_file.len != 0 && vmod_file_location.vmod_folder !in b.module_search_paths { diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index f8f53f6a75..f6bbfc700c 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -22,7 +22,7 @@ fn (mut p Parser) hash() ast.HashStmt { mut flag := val[5..] // expand `@VROOT` to its absolute path if flag.contains('@VROOT') { - vmod_file_location := vmod.mod_file_cacher.get(p.file_name_dir) + vmod_file_location := vmod.mod_file_cacher.get_by_folder(p.file_name_dir) if vmod_file_location.vmod_file.len == 0 { // There was no actual v.mod file found. p.error('To use @VROOT, you need' + ' to have a "v.mod" file in ${p.file_name_dir},' + diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 65c765b4e5..276971df86 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -796,7 +796,7 @@ pub fn (mut s Scanner) scan() token.Token { } if name == 'VMOD_FILE' { if s.vmod_file_content.len == 0 { - vmod_file_location := vmod.mod_file_cacher.get( os.dir( os.real_path(s.file_path) ) ) + vmod_file_location := vmod.mod_file_cacher.get_by_file( s.file_path ) if vmod_file_location.vmod_file.len == 0 { s.error('@VMOD_FILE can be used only in projects, that have v.mod file') } diff --git a/vlib/v/vmod/vmod.v b/vlib/v/vmod/vmod.v index 759698d863..655c7cdfb6 100644 --- a/vlib/v/vmod/vmod.v +++ b/vlib/v/vmod/vmod.v @@ -58,7 +58,13 @@ pub fn (mcache &ModFileCacher) dump() { } } -pub fn (mut mcache ModFileCacher) get(mfolder string) ModFileAndFolder { + +pub fn (mut mcache ModFileCacher) get_by_file(vfile string) ModFileAndFolder { + return mcache.get_by_folder( os.dir( vfile ) ) +} + +pub fn (mut mcache ModFileCacher) get_by_folder(vfolder string) ModFileAndFolder { + mfolder := os.real_path( vfolder ) if mfolder in mcache.cache { return mcache.cache[ mfolder ] }