v.builder: fix compiling code, that imports modules from both src/modules and modules (#19437)

This commit is contained in:
Nemoola 2023-09-25 18:48:43 +09:00 committed by GitHub
parent e7aa6a1870
commit 07bd94fa14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

View File

@ -214,11 +214,14 @@ pub fn (mut v Builder) set_module_lookup_paths() {
if v.pref.is_verbose { if v.pref.is_verbose {
println('x: "${x}"') println('x: "${x}"')
} }
if os.exists(os.join_path(v.compiled_dir, 'src/modules')) { if os.exists(os.join_path(v.compiled_dir, 'src/modules')) {
v.module_search_paths << os.join_path(v.compiled_dir, 'src/modules') v.module_search_paths << os.join_path(v.compiled_dir, 'src/modules')
} else { }
if os.exists(os.join_path(v.compiled_dir, 'modules')) {
v.module_search_paths << os.join_path(v.compiled_dir, 'modules') v.module_search_paths << os.join_path(v.compiled_dir, 'modules')
} }
v.module_search_paths << v.pref.lookup_path v.module_search_paths << v.pref.lookup_path
if v.pref.is_verbose { if v.pref.is_verbose {
v.log('v.module_search_paths:') v.log('v.module_search_paths:')

View File

@ -27,5 +27,5 @@ fn test_projects_should_run() {
assert res.trim_space() == 'v0' assert res.trim_space() == 'v0'
res2 := vrun_ok('run', vroot_path('vlib/v/tests/testdata/modules_in_src/')) res2 := vrun_ok('run', vroot_path('vlib/v/tests/testdata/modules_in_src/'))
assert res2.trim_space() == 'somemodule' assert res2.trim_space() == 'somemodule somemoduletwo'
} }

View File

@ -0,0 +1,7 @@
module somemoduletwo
const name = 'somemoduletwo'
pub fn name() string {
return somemoduletwo.name
}

View File

@ -1,7 +1,8 @@
module main module main
import somemodule import somemodule
import somemoduletwo
fn main() { fn main() {
println(somemodule.name()) println('${somemodule.name()} ${somemoduletwo.name()}')
} }