Skip to content

Commit

Permalink
builder: fix compiling code, importing a local module in src/modules (
Browse files Browse the repository at this point in the history
  • Loading branch information
nemoola authored and Wertzui123 committed Oct 8, 2023
1 parent 1cceb2a commit 6ccc6b7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vlib/v/builder/compile.v
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/tests/projects_that_should_compile_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
7 changes: 7 additions & 0 deletions vlib/v/tests/testdata/modules_in_src/src/main.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module main

import somemodule

fn main() {
println(somemodule.name())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module somemodule

const name = 'somemodule'

pub fn name() string {
return somemodule.name
}
7 changes: 7 additions & 0 deletions vlib/v/tests/testdata/modules_in_src/v.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Module {
name: 'somemodule'
description: ''
version: ''
license: ''
dependencies: []
}

0 comments on commit 6ccc6b7

Please sign in to comment.