adjustment to build rule to fall back to hot directory when file's directory fails

This commit is contained in:
Allen Webster 2016-07-03 16:03:19 -04:00
parent 60d02c4f64
commit 2e87d8bfaa
4 changed files with 72 additions and 40 deletions

View File

@ -1377,18 +1377,24 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
// //
// There is requirement that a custom build system in 4coder actually use the // There is requirement that a custom build system in 4coder actually use the
// directory given by this function. // directory given by this function.
enum Get_Build_Directory_Result{
BuildDir_None,
BuildDir_AtFile,
BuildDir_AtHot
};
static int static int
get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_out){ get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_out){
int result = false; int result = BuildDir_None;
if (buffer->file_name){ if (buffer && buffer->file_name){
if (!match(buffer->file_name, buffer->buffer_name)){ if (!match(buffer->file_name, buffer->buffer_name)){
String dir = make_string(buffer->file_name, String dir = make_string(buffer->file_name,
buffer->file_name_len, buffer->file_name_len,
buffer->file_name_len+1); buffer->file_name_len+1);
remove_last_folder(&dir); remove_last_folder(&dir);
append(dir_out, dir); append(dir_out, dir);
result = true; result = BuildDir_AtFile;
} }
} }
@ -1397,7 +1403,50 @@ get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_
dir_out->memory_size - dir_out->size); dir_out->memory_size - dir_out->size);
if (len + dir_out->size < dir_out->memory_size){ if (len + dir_out->size < dir_out->memory_size){
dir_out->size += len; dir_out->size += len;
result = BuildDir_AtHot;
}
}
return(result);
}
static int
execute_standard_build_search(Application_Links *app, View_Summary *view,
Buffer_Summary *active_buffer,
String *dir, String *command, int perform_backup){
int result = false;
for(;;){
int old_size = dir->size;
append(dir, "build.bat");
if (app->file_exists(app, dir->str, dir->size)){
dir->size = old_size;
append(command, '"');
append(command, *dir);
append(command, "build\"");
app->exec_system_command(app, view,
buffer_identifier(literal("*compilation*")),
dir->str, dir->size,
command->str, command->size,
CLI_OverlapWithConflict);
result = true; result = true;
break;
}
dir->size = old_size;
if (app->directory_cd(app, dir->str, &dir->size, dir->memory_size, literal("..")) == 0){
if (perform_backup){
dir->size = app->directory_get_hot(app, dir->str, dir->memory_size);
String backup_command = make_lit_string("echo couldn't find build.bat");
app->exec_system_command(app, view,
buffer_identifier(literal("*compilation*")),
dir->str, dir->size,
backup_command.str, backup_command.size,
CLI_OverlapWithConflict);
}
break;
} }
} }
@ -1405,45 +1454,26 @@ get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_
} }
static void static void
execute_standard_build(Application_Links *app, View_Summary *view, Buffer_Summary *active_buffer){ execute_standard_build(Application_Links *app, View_Summary *view,
int old_size = 0; Buffer_Summary *active_buffer){
int size = app->memory_size/2; int size = app->memory_size/2;
String dir = make_string(app->memory, 0, size); String dir = make_string(app->memory, 0, size);
get_build_directory(app, active_buffer, &dir);
String command = make_string((char*)app->memory + size, 0, size); String command = make_string((char*)app->memory + size, 0, size);
for(;;){ int build_dir_type = get_build_directory(app, active_buffer, &dir);
old_size = dir.size;
append(&dir, "build.bat");
if (app->file_exists(app, dir.str, dir.size)){ if (build_dir_type == BuildDir_AtFile){
dir.size = old_size; if (!execute_standard_build_search(app, view, active_buffer,
append(&command, '"'); &dir, &command, false)){
append(&command, dir); dir.size = 0;
append(&command, "build\""); command.size = 0;
build_dir_type = get_build_directory(app, 0, &dir);
app->exec_system_command(app, view,
buffer_identifier(literal("*compilation*")),
dir.str, dir.size,
command.str, command.size,
CLI_OverlapWithConflict);
break;
} }
dir.size = old_size; }
if (app->directory_cd(app, dir.str, &dir.size, dir.memory_size, literal("..")) == 0){ if (build_dir_type == BuildDir_AtHot){
dir.size = app->directory_get_hot(app, dir.str, dir.memory_size); execute_standard_build_search(app, view, active_buffer,
command = make_lit_string("echo couldn't find build.bat"); &dir, &command, true);
app->exec_system_command(app, view,
buffer_identifier(literal("*compilation*")),
dir.str, dir.size,
command.str, command.size,
CLI_OverlapWithConflict);
break;
}
} }
} }

View File

@ -800,7 +800,9 @@ view_open_file(Application_Links *app, View_Summary *view,
int result = false; int result = false;
Buffer_Summary buffer = app->get_buffer_by_name(app, filename, filename_len, AccessProtected|AccessHidden); Buffer_Summary buffer = app->get_buffer_by_name(app, filename, filename_len, AccessProtected|AccessHidden);
if (buffer.exists){ if (buffer.exists){
app->view_set_buffer(app, view, buffer.buffer_id, 0); if (!do_in_background){
app->view_set_buffer(app, view, buffer.buffer_id, 0);
}
result = true; result = true;
} }
else{ else{

View File

@ -1,4 +1,4 @@
Distribution Date: 2.7.2016 (dd.mm.yyyy) Distribution Date: 3.7.2016 (dd.mm.yyyy)
Thank you for contributing to the 4coder project! Thank you for contributing to the 4coder project!

View File

@ -1,4 +1,4 @@
Distribution Date: 2.7.2016 (dd.mm.yyyy) Distribution Date: 3.7.2016 (dd.mm.yyyy)
Thank you for contributing to the 4coder project! Thank you for contributing to the 4coder project!