Invalidate units when loaded sources change
This commit is contained in:
+50
-1
@@ -87,6 +87,55 @@ StringMap compiler_parse_unit_metadata(String content)
|
||||
return(metadata);
|
||||
}
|
||||
|
||||
StringList compiler_unit_load_paths(String file_name, String content)
|
||||
{
|
||||
StringList paths;
|
||||
u64 line_start = 0;
|
||||
while(line_start < content.length())
|
||||
{
|
||||
u64 line_end = content.find("\n", line_start);
|
||||
if(line_end == String::npos)
|
||||
break;
|
||||
String line = content.substr(line_start, line_end - line_start);
|
||||
if(str_starts_with(line, "#load "))
|
||||
{
|
||||
u64 first_quote = line.find('"', 6);
|
||||
u64 second_quote = first_quote == String::npos ? String::npos : line.find('"', first_quote + 1);
|
||||
if(first_quote != String::npos && second_quote != String::npos)
|
||||
{
|
||||
String loaded = line.substr(first_quote + 1, second_quote - first_quote - 1);
|
||||
if(loaded != "")
|
||||
paths.push_back(loaded[0] == '/' ? loaded : expand_path(loaded, dirname(file_name)));
|
||||
}
|
||||
}
|
||||
line_start = line_end + 1;
|
||||
}
|
||||
return(paths);
|
||||
}
|
||||
|
||||
void compiler_append_unit_source_signature(String file_name, std::set<String>& visited, String& signature)
|
||||
{
|
||||
String normalized = path_real(file_name);
|
||||
if(normalized == "")
|
||||
normalized = file_name;
|
||||
if(visited.find(normalized) != visited.end())
|
||||
return;
|
||||
visited.insert(normalized);
|
||||
|
||||
String content = file_get_contents(file_name);
|
||||
signature += normalized + ":" + gen_sha1(content) + "\n";
|
||||
for(String loaded : compiler_unit_load_paths(file_name, content))
|
||||
compiler_append_unit_source_signature(loaded, visited, signature);
|
||||
}
|
||||
|
||||
String compiler_unit_source_signature(String file_name)
|
||||
{
|
||||
std::set<String> visited;
|
||||
String signature = "uce-load-graph-v1\n";
|
||||
compiler_append_unit_source_signature(file_name, visited, signature);
|
||||
return(gen_sha1(signature));
|
||||
}
|
||||
|
||||
String compiler_unit_input_signature(Request* context, SharedUnit* su)
|
||||
{
|
||||
if(!context || !su || !file_exists(su->file_name))
|
||||
@@ -94,7 +143,7 @@ String compiler_unit_input_signature(Request* context, SharedUnit* su)
|
||||
|
||||
String setup_template = context->server->config["COMPILER_SYS_PATH"] + "/" + context->server->config["SETUP_TEMPLATE"];
|
||||
return(
|
||||
gen_sha1(file_get_contents(su->file_name)) + ":" +
|
||||
compiler_unit_source_signature(su->file_name) + ":" +
|
||||
gen_sha1(file_get_contents(setup_template)) + ":" +
|
||||
std::to_string(UCE_UNIT_ABI_VERSION)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user