builder: fix compiling code, importing a local module in src/modules (#19396)

This commit is contained in:
Yamamoto Haruhi 2023-09-21 01:22:00 +09:00 committed by GitHub
parent f93d257d29
commit 7169df3e57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 1 deletions

View File

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

View File

@ -25,4 +25,7 @@ fn test_projects_should_run() {
}
res := vrun_ok('run', vroot_path('vlib/v/tests/testdata/enum_in_builtin') + os.path_separator)
assert res.trim_space() == 'v0'
res2 := vrun_ok('run', vroot_path('vlib/v/tests/testdata/modules_in_src/'))
assert res2.trim_space() == 'somemodule'
}

View File

@ -0,0 +1,7 @@
module main
import somemodule
fn main() {
println(somemodule.name())
}

View File

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

View File

@ -0,0 +1,7 @@
Module {
name: 'somemodule'
description: ''
version: ''
license: ''
dependencies: []
}