don't include generated math into build_file, use cache, ui

This commit is contained in:
Krzosa Karol
2025-01-17 13:35:35 +01:00
parent 0ad84c9fc7
commit d3c84fd666
18 changed files with 255 additions and 164 deletions

View File

@@ -2296,7 +2296,7 @@ OS_API S8_String OS_GetAbsolutePath(MA_Arena *arena, S8_String relative) {
return path;
}
OS_API bool OS_FileExists(S8_String path) {
OS_API bool os_file_exists(S8_String path) {
wchar_t wbuff[1024];
UTF_CreateWidecharFromChar(wbuff, MA_Lengthof(wbuff), path.str, path.len);
DWORD attribs = GetFileAttributesW(wbuff);
@@ -2664,7 +2664,7 @@ OS_API S8_String OS_GetAbsolutePath(MA_Arena *arena, S8_String relative) {
return result;
}
OS_API bool OS_FileExists(S8_String path) {
OS_API bool os_file_exists(S8_String path) {
MA_Temp scratch = MA_GetScratch();
S8_String copy = S8_Copy(scratch.arena, path);
@@ -4969,7 +4969,7 @@ SRC_Cache *SRC_FromFileCache;
S8_String SRC_CacheFilename;
CL_SearchPaths SRC_SearchPaths = {0}; // @todo;
void SRC_InitCache(MA_Arena *arena, S8_String cachefilename) {
void cache_init(MA_Arena *arena, S8_String cachefilename) {
SRC_CacheFilename = cachefilename;
SRC_InMemoryCache = MA_PushStruct(arena, SRC_Cache);
@@ -4982,12 +4982,12 @@ void SRC_InitCache(MA_Arena *arena, S8_String cachefilename) {
if (cache.len) MA_MemoryCopy(SRC_FromFileCache, cache.str, cache.len);
}
void SRC_SaveCache() {
void cache_save() {
S8_String dump = S8_Make((char *)SRC_InMemoryCache, sizeof(SRC_Cache));
os_write_file(SRC_CacheFilename, dump);
}
SRC_CacheEntry *SRC_AddHash(uint64_t filepath, uint64_t file, uint64_t includes) {
SRC_CacheEntry *cache_add_hash(uint64_t filepath, uint64_t file, uint64_t includes) {
IO_Assert(SRC_InMemoryCache->entry_len + 1 < SRC_InMemoryCache->entry_cap);
SRC_CacheEntry *result = SRC_InMemoryCache->entries + SRC_InMemoryCache->entry_len++;
result->filepath_hash = filepath;
@@ -4997,7 +4997,7 @@ SRC_CacheEntry *SRC_AddHash(uint64_t filepath, uint64_t file, uint64_t includes)
return result;
}
SRC_CacheEntry *SRC_FindCache(SRC_Cache *cache, uint64_t filepath_hash) {
SRC_CacheEntry *cache_find(SRC_Cache *cache, uint64_t filepath_hash) {
for (int cache_i = 0; cache_i < cache->entry_len; cache_i += 1) {
SRC_CacheEntry *it = cache->entries + cache_i;
if (it->filepath_hash == filepath_hash) {
@@ -5007,7 +5007,7 @@ SRC_CacheEntry *SRC_FindCache(SRC_Cache *cache, uint64_t filepath_hash) {
return 0;
}
SRC_CacheEntry *SRC_HashFile(S8_String file, char *parent_file) {
SRC_CacheEntry *cache_hash_file(S8_String file, char *parent_file) {
char *resolved_file = CL_ResolveFilepath(&Perm, &SRC_SearchPaths, file.str, parent_file, false);
if (!resolved_file) {
IO_Printf("Failed to resolve file: %.*s\n", S8_Expand(file));
@@ -5015,7 +5015,7 @@ SRC_CacheEntry *SRC_HashFile(S8_String file, char *parent_file) {
}
uint64_t filepath_hash = HashBytes(resolved_file, S8_Length(resolved_file));
SRC_CacheEntry *entry = SRC_FindCache(SRC_InMemoryCache, filepath_hash);
SRC_CacheEntry *entry = cache_find(SRC_InMemoryCache, filepath_hash);
if (entry) return entry;
S8_String filecontent = OS_ReadFile(&Perm, S8_MakeFromChar(resolved_file));
@@ -5031,7 +5031,7 @@ SRC_CacheEntry *SRC_HashFile(S8_String file, char *parent_file) {
if (token.is_system_include) continue;
S8_String file_it = S8_MakeFromChar(token.string_literal);
SRC_CacheEntry *cache = SRC_HashFile(file_it, resolved_file);
SRC_CacheEntry *cache = cache_hash_file(file_it, resolved_file);
if (!cache) {
// error was reported already IO_Printf("Missing cache for: %.*s\n", S8_Expand(file_it));
continue;
@@ -5040,14 +5040,14 @@ SRC_CacheEntry *SRC_HashFile(S8_String file, char *parent_file) {
includes_hash = HashMix(includes_hash, cache->total_hash);
}
SRC_CacheEntry *result = SRC_AddHash(filepath_hash, file_hash, includes_hash);
SRC_CacheEntry *result = cache_add_hash(filepath_hash, file_hash, includes_hash);
return result;
}
bool SRC_WasModified(S8_String file, S8_String artifact_path) {
bool cache_code_modified(S8_String file, S8_String artifact_path) {
double time_start = OS_GetTime();
if (OS_FileExists(file) == false) {
if (os_file_exists(file) == false) {
IO_Printf("FAILED File doesnt exist: %.*s\n", S8_Expand(file));
exit(0);
}
@@ -5055,17 +5055,16 @@ bool SRC_WasModified(S8_String file, S8_String artifact_path) {
file = OS_GetAbsolutePath(&Perm, file);
}
S8_String without_ext = S8_ChopLastPeriod(file);
S8_String name_only = S8_SkipToLastSlash(without_ext);
bool modified = false;
if (artifact_path.len) {
modified = os_file_exists(artifact_path) == false;
}
if (artifact_path.len == 0) artifact_path = S8_Format(&Perm, "%.*s.%s", S8_Expand(name_only), IF_WINDOWS_ELSE("obj", "o"));
bool modified = OS_FileExists(artifact_path) == false;
SRC_CacheEntry *in_memory = SRC_HashFile(file, 0);
SRC_CacheEntry *in_memory = cache_hash_file(file, 0);
IO_Assert(in_memory);
if (modified == false) {
SRC_CacheEntry *from_file = SRC_FindCache(SRC_FromFileCache, in_memory->filepath_hash);
SRC_CacheEntry *from_file = cache_find(SRC_FromFileCache, in_memory->filepath_hash);
if (from_file == 0 || (in_memory->total_hash != from_file->total_hash)) {
modified = true;
}
@@ -5142,13 +5141,13 @@ int main(int argument_count, char **arguments) {
}
}
SRC_InitCache(&Perm, S8_Lit("build_tool.cache"));
cache_init(&Perm, S8_Lit("build_tool.cache"));
S8_String name_no_ext = S8_GetNameNoExt(build_file);
S8_String exe_name = S8_Format(&Perm, "%.*s.exe", S8_Expand(name_no_ext));
// Compile the build file only if code changed
double time_build_file_compiled = 0;
if (SRC_WasModified(build_file, exe_name)) {
if (cache_code_modified(build_file, exe_name)) {
time_build_file_compiled = OS_GetTime();
int result = 0;
if (S8_AreEqual(cc, S8_Lit("cl"), false)) {
@@ -5180,7 +5179,7 @@ int main(int argument_count, char **arguments) {
}
}
SRC_SaveCache();
cache_save();
if (time_build_file_compiled) IO_Printf("build file compiled in: %f\n", time_build_file_compiled);
IO_Printf("executed in : %f\n", OS_GetTime() - time);
}

View File

@@ -178,7 +178,7 @@ int row_findi(ast_t *row, char *name) {
s8_t s = s8_from_char(name);
int i = 0;
for (ast_t *col = row->first; col; col = col->next) {
if (s8_equal(col->string, s)) {
if (s8_are_equal(col->string, s)) {
return i;
}
i += 1;