From 6ccc6b7cc383c1fc9c0ffbe7fdc80b69213cb832 Mon Sep 17 00:00:00 2001 From: Yamamoto Haruhi <144327005+nemoola@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:22:00 +0900 Subject: [PATCH] builder: fix compiling code, importing a local module in `src/modules` (#19396) --- vlib/v/builder/compile.v | 6 +++++- vlib/v/tests/projects_that_should_compile_test.v | 3 +++ vlib/v/tests/testdata/modules_in_src/src/main.v | 7 +++++++ .../modules_in_src/src/modules/somemodule/somemodule.v | 7 +++++++ vlib/v/tests/testdata/modules_in_src/v.mod | 7 +++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/testdata/modules_in_src/src/main.v create mode 100644 vlib/v/tests/testdata/modules_in_src/src/modules/somemodule/somemodule.v create mode 100644 vlib/v/tests/testdata/modules_in_src/v.mod diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 71d7db1ce43625..3d790a197075d4 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -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:') diff --git a/vlib/v/tests/projects_that_should_compile_test.v b/vlib/v/tests/projects_that_should_compile_test.v index e6b2277c592c9f..107ca78286a0e6 100644 --- a/vlib/v/tests/projects_that_should_compile_test.v +++ b/vlib/v/tests/projects_that_should_compile_test.v @@ -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' } diff --git a/vlib/v/tests/testdata/modules_in_src/src/main.v b/vlib/v/tests/testdata/modules_in_src/src/main.v new file mode 100644 index 00000000000000..7c91246ee6cc22 --- /dev/null +++ b/vlib/v/tests/testdata/modules_in_src/src/main.v @@ -0,0 +1,7 @@ +module main + +import somemodule + +fn main() { + println(somemodule.name()) +} diff --git a/vlib/v/tests/testdata/modules_in_src/src/modules/somemodule/somemodule.v b/vlib/v/tests/testdata/modules_in_src/src/modules/somemodule/somemodule.v new file mode 100644 index 00000000000000..832dec788e985c --- /dev/null +++ b/vlib/v/tests/testdata/modules_in_src/src/modules/somemodule/somemodule.v @@ -0,0 +1,7 @@ +module somemodule + +const name = 'somemodule' + +pub fn name() string { + return somemodule.name +} diff --git a/vlib/v/tests/testdata/modules_in_src/v.mod b/vlib/v/tests/testdata/modules_in_src/v.mod new file mode 100644 index 00000000000000..dc334bd0efe31e --- /dev/null +++ b/vlib/v/tests/testdata/modules_in_src/v.mod @@ -0,0 +1,7 @@ +Module { + name: 'somemodule' + description: '' + version: '' + license: '' + dependencies: [] +}