Module relative folders working
This commit is contained in:
@@ -785,7 +785,7 @@ parse_all_modules(){
|
||||
}
|
||||
|
||||
function Ast_Module *
|
||||
add_module(Token *pos, Intern_String filename){
|
||||
add_module(Token *pos, Intern_String filename, B32 command_line_module){
|
||||
For(pctx->modules){
|
||||
if(it->name == filename){
|
||||
log_info("Returning registered module: %Q\n", filename);
|
||||
@@ -793,8 +793,41 @@ add_module(Token *pos, Intern_String filename){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Scratch scratch;
|
||||
Ast_Module *result = ast_new(Ast_Module, AST_MODULE, pos, 0);
|
||||
//
|
||||
// Find in working directory
|
||||
//
|
||||
if(command_line_module){
|
||||
if(os_does_file_exist(filename.s)){
|
||||
String path = os_get_absolute_path(scratch, filename.s);
|
||||
string_path_normalize(path);
|
||||
path = string_chop_last_slash(path);
|
||||
result->base_folder = string_copy(pctx->perm, path);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Find in module folder
|
||||
//
|
||||
else{
|
||||
For(pctx->module_folders){
|
||||
String path = string_fmt(scratch, "%Q/%Q", it, filename);
|
||||
if(os_does_file_exist(path)){
|
||||
path = string_chop_last_slash(path);
|
||||
result->base_folder = string_copy(pctx->perm, path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(result->base_folder.len == 0){
|
||||
compiler_error(pos, "Couldn't find the module with name %Q", filename);
|
||||
}
|
||||
|
||||
log_info("Adding module: %Q\n", filename);
|
||||
Ast_Module *result = ast_new(Ast_Module, AST_MODULE, pos, 0);
|
||||
result->name = filename;
|
||||
result->module = result; // @warning: self referential
|
||||
result->file = result; // @warning: self referential
|
||||
|
||||
Reference in New Issue
Block a user