Module relative folders working

This commit is contained in:
Krzosa Karol
2022-06-27 10:24:58 +02:00
parent 6644a2c5ae
commit 15d452cae3
8 changed files with 42 additions and 21 deletions

View File

@@ -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