mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builder: fix a bug with submodule import (#10318)
This commit is contained in:
parent
dc431a3c47
commit
a716a00e38
7
examples/submodule/main.v
Normal file
7
examples/submodule/main.v
Normal file
@ -0,0 +1,7 @@
|
||||
import mymodules { add_xy }
|
||||
import mymodules.submodule { sub_xy }
|
||||
|
||||
fn main() {
|
||||
println(add_xy(2, 3)) // expected: 5
|
||||
println(sub_xy(10, 7)) // expected: 3
|
||||
}
|
5
examples/submodule/mymodules/main_functions.v
Normal file
5
examples/submodule/mymodules/main_functions.v
Normal file
@ -0,0 +1,5 @@
|
||||
module mymodule
|
||||
|
||||
pub fn add_xy(x int, y int) int {
|
||||
return x + y
|
||||
}
|
5
examples/submodule/mymodules/submodule/sub_functions.v
Normal file
5
examples/submodule/mymodules/submodule/sub_functions.v
Normal file
@ -0,0 +1,5 @@
|
||||
module submodule
|
||||
|
||||
pub fn sub_xy(x int, y int) int {
|
||||
return x - y
|
||||
}
|
@ -32,7 +32,7 @@ pub fn qualify_module(pref &pref.Preferences, mod string, file_path string) stri
|
||||
if mod == 'main' {
|
||||
return mod
|
||||
}
|
||||
clean_file_path := file_path.all_before_last('/')
|
||||
clean_file_path := file_path.all_before_last(os.path_separator)
|
||||
// relative module (relative to working directory)
|
||||
// TODO: find most stable solution & test with -usecache
|
||||
if clean_file_path.replace(os.getwd() + os.path_separator, '') == mod {
|
||||
@ -110,5 +110,13 @@ pub fn mod_path_to_full_name(pref &pref.Preferences, mod string, path string) ?s
|
||||
}
|
||||
}
|
||||
}
|
||||
if os.is_abs_path(pref.path) && os.is_abs_path(path) && os.is_dir(path) { // && path.contains(mod )
|
||||
rel_mod_path := path.replace(pref.path.all_before_last(os.path_separator) +
|
||||
os.path_separator, '')
|
||||
if rel_mod_path != path {
|
||||
full_mod_name := rel_mod_path.replace(os.path_separator, '.')
|
||||
return full_mod_name
|
||||
}
|
||||
}
|
||||
return error('module not found')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user