From b31ad1d2eec8aeef59a71751f65779bb5812592a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 11:35:38 +0300 Subject: [PATCH] cgen: import submodule of third-party module (fixes #14548) --- vlib/v/gen/c/fn.v | 3 ++- .../path4/.cache/README.md | 4 ++++ .../path4/hunam6/voak/foo/foo.v | 1 + .../path4/hunam6/voak/v.mod | 3 +++ .../path4/hunam6/voak/voak.v | 5 +++++ .../submodule_of_third_party_main.vv | 1 + .../vmodules_overrides_test.v | 13 +++++++++++++ 7 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/multiple_paths_in_vmodules/path4/.cache/README.md create mode 100644 vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/foo/foo.v create mode 100644 vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/v.mod create mode 100644 vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/voak.v create mode 100644 vlib/v/tests/multiple_paths_in_vmodules/submodule_of_third_party_main.vv diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 9cc8e34d4..7e76b9186 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -113,9 +113,10 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) { // TODO: true for not just "builtin" // TODO: clean this up mod := if g.is_builtin_mod { 'builtin' } else { node.name.all_before_last('.') } + module_built_short := g.module_built.all_after_last('/').all_after_last('.') // for now dont skip generic functions as they are being marked as static // when -usecache is enabled, until a better solution is implemented. - if ((mod != g.module_built && node.mod != g.module_built.after('/')) + if ((mod != g.module_built && node.mod != g.module_built && node.mod != module_built_short) || should_bundle_module) && node.generic_names.len == 0 { // Skip functions that don't have to be generated for this module. // println('skip bm ${node.name} mod=${node.mod} module_built=${g.module_built}') diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path4/.cache/README.md b/vlib/v/tests/multiple_paths_in_vmodules/path4/.cache/README.md new file mode 100644 index 000000000..0ad0cc1a7 --- /dev/null +++ b/vlib/v/tests/multiple_paths_in_vmodules/path4/.cache/README.md @@ -0,0 +1,4 @@ +This folder contains cached build artifacts from the V build system. +You can safely delete it, if it is getting too large. +It will be recreated the next time you compile something with V. +You can change its location with the VCACHE environment variable. diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/foo/foo.v b/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/foo/foo.v new file mode 100644 index 000000000..49525808b --- /dev/null +++ b/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/foo/foo.v @@ -0,0 +1 @@ +module foo diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/v.mod b/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/v.mod new file mode 100644 index 000000000..d254554b9 --- /dev/null +++ b/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/v.mod @@ -0,0 +1,3 @@ +Module { + name: 'hunam6.voak' +} diff --git a/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/voak.v b/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/voak.v new file mode 100644 index 000000000..4391e8121 --- /dev/null +++ b/vlib/v/tests/multiple_paths_in_vmodules/path4/hunam6/voak/voak.v @@ -0,0 +1,5 @@ +module voak + +pub fn hello() string { + return 'hello' +} diff --git a/vlib/v/tests/multiple_paths_in_vmodules/submodule_of_third_party_main.vv b/vlib/v/tests/multiple_paths_in_vmodules/submodule_of_third_party_main.vv new file mode 100644 index 000000000..cbca77d73 --- /dev/null +++ b/vlib/v/tests/multiple_paths_in_vmodules/submodule_of_third_party_main.vv @@ -0,0 +1 @@ +import hunam6.voak.foo diff --git a/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v b/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v index 3bf10b5bb..c27429dd3 100644 --- a/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v +++ b/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v @@ -14,6 +14,10 @@ const mainvv = os.join_path(basepath, 'main.vv') const cmd = '${os.quoted_path(vexe)} run ${os.quoted_path(mainvv)}' +const submodule_mainvv = os.join_path(basepath, 'submodule_of_third_party_main.vv') + +const submodule_cmd = '${os.quoted_path(vexe)} ${os.quoted_path(submodule_mainvv)}' + fn test_vexe_is_set() { assert vexe != '' println('vexe: ${vexe}') @@ -38,3 +42,12 @@ fn test_compiling_with_vmodules_works() { assert res.exit_code == 0, res.output assert res.output.trim_space() == "['x', 'y', 'z']" } + +fn test_importing_third_party_submodule_works() { + os.chdir(vroot) or {} + os.setenv('VMODULES', os.join_path(basepath, 'path4'), true) + dump(os.getenv('VMODULES')) + dump(submodule_cmd) + res := os.execute(submodule_cmd) + assert res.exit_code == 0, res.output +} -- 2.39.5