Invalidate component freshness by source generation

This commit is contained in:
udo
2026-07-17 23:14:42 +00:00
parent 075ce0bc07
commit e176ff09d9
5 changed files with 68 additions and 3 deletions
+27
View File
@@ -385,6 +385,11 @@ String compiler_priority_file_name(Request* context)
return(context->server->config["BIN_DIRECTORY"] + "/proactive-priority.txt");
}
String compiler_source_generation_file_name(Request* context)
{
return(context->server->config["BIN_DIRECTORY"] + "/source-generation.txt");
}
int compiler_open_lock_file(String file_name, String purpose, bool nonblocking = false)
{
(void)purpose;
@@ -906,6 +911,7 @@ void compile_shared_unit(Request* context, SharedUnit* su)
file_put_contents(su->compile_output_file_name, su->compiler_messages + "\n");
compiler_untrack_known_unit(context, su->file_name);
compiler_record_compile_result(su, time_precise() - comp_start, false, "missing_source", su->compiler_messages);
compiler_mark_source_generation(context);
return;
}
struct stat source_info;
@@ -922,6 +928,7 @@ void compile_shared_unit(Request* context, SharedUnit* su)
file_unlink(su->wasm_name);
compiler_record_compile_result(su, time_precise() - comp_start, false, "compile_error", su->compiler_messages);
printf("%s \n", compiler_format_source_read_failure(context, su, su->compiler_messages).c_str());
compiler_mark_source_generation(context);
return;
}
@@ -982,6 +989,7 @@ void compile_shared_unit(Request* context, SharedUnit* su)
(su->pre_path + "/" + su->pre_file_name).c_str(),
time_precise() - comp_start);
}
compiler_mark_source_generation(context);
}
SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name, bool force_recompile)
@@ -1074,6 +1082,25 @@ SharedUnit* get_shared_unit(Request* context, String file_name)
return(compiler_get_shared_unit_internal(context, file_name, false));
}
String compiler_source_generation(Request* context)
{
if(!context || !context->server)
return("");
return(trim(file_get_contents(compiler_source_generation_file_name(context))));
}
void compiler_mark_source_generation(Request* context)
{
if(!context || !context->server)
return;
String file_name = compiler_source_generation_file_name(context);
int fdlock = compiler_open_lock_file(file_name + ".lock", "source-generation");
if(fdlock < 0)
return;
file_put_contents(file_name, std::to_string(getpid()) + ":" + std::to_string((u64)(time_precise() * 1000000.0)) + "\n");
compiler_close_lock_file(fdlock);
}
String compiler_error_page_unit(Request* context, String config_key)
{
if(!context || !context->server)