builder: fix a bug with submodule import (#10318)

pull/10354/head
Yuriy Zymlex 2021-06-05 19:45:23 +10:00 committed by GitHub
parent dc431a3c47
commit a716a00e38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View 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
}

View File

@ -0,0 +1,5 @@
module mymodule
pub fn add_xy(x int, y int) int {
return x + y
}

View File

@ -0,0 +1,5 @@
module submodule
pub fn sub_xy(x int, y int) int {
return x - y
}

View File

@ -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')
}