import from root (@ prefix)
This commit is contained in:
@@ -25,6 +25,7 @@ State :: struct {
|
||||
allocator: mem.Allocator,
|
||||
c_options: cimport.Options,
|
||||
selected: target.Target,
|
||||
project_root: string,
|
||||
record_identities: [dynamic]string,
|
||||
record_types: [dynamic]types.Type,
|
||||
root_failed: bool,
|
||||
@@ -100,7 +101,13 @@ resolve_import_path :: proc(state: ^State, importing_path, import_path: string)
|
||||
if filepath.is_abs(import_path) {
|
||||
return "", false
|
||||
}
|
||||
joined, join_error := filepath.join({importing_path, import_path}, state.allocator)
|
||||
base := importing_path
|
||||
path := import_path
|
||||
if strings.has_prefix(import_path, "@") {
|
||||
base = state.project_root
|
||||
path = import_path[1:]
|
||||
}
|
||||
joined, join_error := filepath.join({base, path}, state.allocator)
|
||||
if join_error != nil {
|
||||
return "", false
|
||||
}
|
||||
@@ -1406,6 +1413,10 @@ load :: proc(
|
||||
selected := target.DEFAULT,
|
||||
) -> (ast.Module, bool) {
|
||||
module := ast.init_module(allocator)
|
||||
project_root, project_root_ok := filepath.abs(".", allocator)
|
||||
if !project_root_ok {
|
||||
project_root = strings.clone(".", allocator)
|
||||
}
|
||||
state := State{
|
||||
module=&module,
|
||||
sources=sources,
|
||||
@@ -1415,10 +1426,12 @@ load :: proc(
|
||||
allocator=allocator,
|
||||
c_options=c_options,
|
||||
selected=selected,
|
||||
project_root=project_root,
|
||||
}
|
||||
state.record_identities.allocator = allocator
|
||||
state.record_types.allocator = allocator
|
||||
defer {
|
||||
delete(state.project_root, allocator)
|
||||
for identity in state.record_identities {
|
||||
delete(identity, allocator)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user