From 07bd94fa14740227e87573802741e87fe2d657c3 Mon Sep 17 00:00:00 2001 From: Nemoola <144327005+nemoola@users.noreply.github.com> Date: Mon, 25 Sep 2023 18:48:43 +0900 Subject: [PATCH] v.builder: fix compiling code, that imports modules from both `src/modules` and `modules` (#19437) --- vlib/v/builder/compile.v | 5 ++++- vlib/v/tests/projects_that_should_compile_test.v | 2 +- .../modules_in_src/modules/somemoduletwo/somemoduletwo.v | 7 +++++++ vlib/v/tests/testdata/modules_in_src/src/main.v | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 vlib/v/tests/testdata/modules_in_src/modules/somemoduletwo/somemoduletwo.v diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index b0a8dd2ce2..0840b03f9f 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -214,11 +214,14 @@ pub fn (mut v Builder) set_module_lookup_paths() { if v.pref.is_verbose { println('x: "${x}"') } + if os.exists(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 << v.pref.lookup_path if v.pref.is_verbose { v.log('v.module_search_paths:') diff --git a/vlib/v/tests/projects_that_should_compile_test.v b/vlib/v/tests/projects_that_should_compile_test.v index 107ca78286..baf9780447 100644 --- a/vlib/v/tests/projects_that_should_compile_test.v +++ b/vlib/v/tests/projects_that_should_compile_test.v @@ -27,5 +27,5 @@ fn test_projects_should_run() { assert res.trim_space() == 'v0' res2 := vrun_ok('run', vroot_path('vlib/v/tests/testdata/modules_in_src/')) - assert res2.trim_space() == 'somemodule' + assert res2.trim_space() == 'somemodule somemoduletwo' } diff --git a/vlib/v/tests/testdata/modules_in_src/modules/somemoduletwo/somemoduletwo.v b/vlib/v/tests/testdata/modules_in_src/modules/somemoduletwo/somemoduletwo.v new file mode 100644 index 0000000000..20b677e1b2 --- /dev/null +++ b/vlib/v/tests/testdata/modules_in_src/modules/somemoduletwo/somemoduletwo.v @@ -0,0 +1,7 @@ +module somemoduletwo + +const name = 'somemoduletwo' + +pub fn name() string { + return somemoduletwo.name +} diff --git a/vlib/v/tests/testdata/modules_in_src/src/main.v b/vlib/v/tests/testdata/modules_in_src/src/main.v index 7c91246ee6..0c246529a7 100644 --- a/vlib/v/tests/testdata/modules_in_src/src/main.v +++ b/vlib/v/tests/testdata/modules_in_src/src/main.v @@ -1,7 +1,8 @@ module main import somemodule +import somemoduletwo fn main() { - println(somemodule.name()) + println('${somemodule.name()} ${somemoduletwo.name()}') }