From 3e9ac3e99cf8320386781da9652acaa39390b08a Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 24 May 2024 16:02:08 -0500 Subject: [PATCH] incorporate buildit dep hist --- build.c | 140 +++++++++++++++++++++++++++++---------------------- src/common.h | 1 + src/sys.h | 2 - 3 files changed, 82 insertions(+), 61 deletions(-) diff --git a/build.c b/build.c index 0a7a9a7c..718b90fd 100644 --- a/build.c +++ b/build.c @@ -127,6 +127,7 @@ void OnBuild(StringList cli_args) } } + String hist_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/.dephist"), FmtStr(arg_outdir))); String out_obj_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/obj/"), FmtStr(arg_outdir))); String out_inc_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/inc/"), FmtStr(arg_outdir))); String out_bin_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/bin/"), FmtStr(arg_outdir))); @@ -162,6 +163,12 @@ void OnBuild(StringList cli_args) SH_PrintF(Lit("Building to \"%F\"\n"), FmtStr(out_bin_dir_path)); SH_Print(Lit("------------------------------\n\n")); + /* ========================== * + * Load hist file + * ========================== */ + + D_Hist hist = D_HistFromPath(&arena, hist_path); + /* ========================== * * Constants * ========================== */ @@ -172,25 +179,24 @@ void OnBuild(StringList cli_args) D_Tag executable = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.exe"), FmtStr(out_bin_dir_path))); D_Tag pdb = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.pdb"), FmtStr(out_bin_dir_path))); + /* Pch tags */ D_Tag pch_header = D_FileTagFromPath(&arena, Lit("src/common.h")); - D_Tag pch_c_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.pch"), FmtStr(out_obj_dir_path))); - D_Tag pch_c_obj_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path))); - D_Tag pch_cpp_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.pch"), FmtStr(out_obj_dir_path))); - D_Tag pch_cpp_obj_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path))); - -#if 0 -#if 1 - D_Tag pch_h_input = D_FileTagFromPath(&arena, Lit("src/common.h")); - D_Tag pch_c_src_gen = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c"), FmtStr(out_obj_dir_path))); - D_Tag pch_cpp_src_gen = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path))); + D_Tag pch_c_src_gen_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c"), FmtStr(out_obj_dir_path))); + D_Tag pch_c_src_gen_obj_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path))); D_Tag pch_c_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.pch"), FmtStr(out_obj_dir_path))); D_Tag pch_cpp_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.pch"), FmtStr(out_obj_dir_path))); -#else - D_Tag pch_input = D_FileTagFromPath(&arena, Lit("src/common.h")); - D_Tag pch_c_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common_c.pch"), FmtStr(out_obj_dir_path))); - D_Tag pch_cpp_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common_cpp.pch"), FmtStr(out_obj_dir_path))); -#endif -#endif + D_Tag pch_cpp_src_gen_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path))); + D_Tag pch_cpp_src_gen_obj_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path))); + /* Dependency order: common.h -> common.c (generated for msvc) -> common.c.obj -> common.c.pch -> PowerPlay.exe */ + D_AddDependency(pch_c_src_gen_output, pch_header); + D_AddDependency(pch_c_src_gen_obj_output, pch_c_src_gen_output); + D_AddDependency(pch_c_output, pch_c_src_gen_obj_output); + D_AddDependency(executable, pch_c_output); + /* Dependency order: common.h -> common.cpp (generated for msvc) -> common.cpp.obj -> common.cpp.pch -> PowerPlay.exe*/ + D_AddDependency(pch_cpp_src_gen_output, pch_header); + D_AddDependency(pch_cpp_src_gen_obj_output, pch_cpp_src_gen_output); + D_AddDependency(pch_cpp_output, pch_cpp_src_gen_obj_output); + D_AddDependency(executable, pch_cpp_output); /* ========================== * * Determine compiler args @@ -224,8 +230,8 @@ void OnBuild(StringList cli_args) StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path))); StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path))); - StringListAppend(&arena, &pch_c_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path), FmtStr(pch_c_obj_output.full_path))); - StringListAppend(&arena, &pch_cpp_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path), FmtStr(pch_cpp_obj_output.full_path))); + StringListAppend(&arena, &pch_c_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path), FmtStr(pch_c_src_gen_obj_output.full_path))); + StringListAppend(&arena, &pch_cpp_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path), FmtStr(pch_cpp_src_gen_obj_output.full_path))); StringListAppend(&arena, &link_args, Lit("link.exe /nologo %F")); StringListAppend(&arena, &link_args, StringF(&arena, Lit("/OUT:\"%F\" /PDB:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF"), FmtStr(executable.full_path), FmtStr(pdb.full_path))); @@ -412,7 +418,7 @@ void OnBuild(StringList cli_args) } else { D_AddDependency(inc_file, shaders_tar); } - if (D_IsDirty(shaders_tar)) { + if (D_IsDirty(shaders_tar, &hist)) { String tar_cmd = StringF(&arena, Lit("cd %F && tar cvf %F ."), FmtStr(shaders_dir.full_path), FmtStr(shaders_tar.full_path)); String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(shaders_dir)), FmtStr(D_GetName(shaders_tar))); StepListAppend(&arena, &compile_command_list, step_name, tar_cmd, (String) { 0 }, true); @@ -427,7 +433,7 @@ void OnBuild(StringList cli_args) } else { D_AddDependency(inc_file, res_tar); } - if (D_IsDirty(res_tar)) { + if (D_IsDirty(res_tar, &hist)) { String tar_cmd = StringF(&arena, Lit("cd %F && tar cvf %F ."), FmtStr(res_dir.full_path), FmtStr(res_tar.full_path)); String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(res_dir)), FmtStr(D_GetName(res_tar))); StepListAppend(&arena, &compile_command_list, step_name, tar_cmd, (String) { 0 }, true); @@ -452,7 +458,11 @@ void OnBuild(StringList cli_args) D_AddDependency(rc_file, rin->tag); } - if (D_IsDirty(rc_file)) { + D_Tag rc_res_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path))); + D_AddDependency(rc_res_file, rc_file); + D_AddDependency(executable, rc_res_file); + + if (D_IsDirty(rc_res_file, &hist)) { /* Generate rc file */ D_ClearWrite(rc_file, Lit("")); for (RcIncludeListNode *rin = rc_includes.first; rin; rin = rin->next) { @@ -462,7 +472,6 @@ void OnBuild(StringList cli_args) } /* Append rc -> res compile command */ - D_Tag rc_res_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path))); String rc_compile_cmd = { 0 }; if (arg_msvc) { rc_compile_cmd = StringF(&arena, Lit("rc /fo\"%F\" \"%F\""), FmtStr(rc_res_file.full_path), FmtStr(rc_file.full_path)); @@ -480,36 +489,38 @@ void OnBuild(StringList cli_args) * ========================== */ if (arg_msvc) { - /* C */ { - D_Tag c_src = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F.c"), FmtStr(pch_c_output.full_path))); - D_ClearWrite(c_src, Lit("")); - String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(c_src.full_path)); - String link_file = pch_c_obj_output.full_path; - String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_c_output))); - StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, link_file, true); + if (D_IsDirty(pch_c_output, &hist)) { + D_ClearWrite(pch_c_src_gen_output, Lit("")); + String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_c_src_gen_output.full_path)); + String link_file = pch_c_src_gen_obj_output.full_path; + String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_c_output))); + StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, link_file, true); + } } - /* Cpp */ { - D_Tag cpp_src = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F.cpp"), FmtStr(pch_cpp_output.full_path))); - D_ClearWrite(cpp_src, Lit("")); - String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(cpp_src.full_path)); - String link_file = pch_cpp_obj_output.full_path; - String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_cpp_output))); - StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, link_file, true); + if (D_IsDirty(pch_cpp_src_gen_output, &hist)) { + D_ClearWrite(pch_cpp_src_gen_output, Lit("")); + String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_cpp_src_gen_output.full_path)); + String link_file = pch_cpp_src_gen_obj_output.full_path; + String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_cpp_src_gen_output))); + StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, link_file, true); + } } } else { - /* C */ { - String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path)); - String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_c_output))); - StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, (String) { 0 }, true); + if (D_IsDirty(pch_c_output, &hist)) { + String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path)); + String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_c_output))); + StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, (String) { 0 }, true); + } } - /* Cpp */ { - String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path)); - String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_cpp_output))); - StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, (String) { 0 }, true); + if (D_IsDirty(pch_cpp_output, &hist)) { + String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path)); + String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header)), FmtStr(D_GetName(pch_cpp_output))); + StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, (String) { 0 }, true); + } } } @@ -523,16 +534,16 @@ void OnBuild(StringList cli_args) for (D_TagListNode *n = src_files.first; n; n = n->next) { D_Tag file = n->tag; - Bool include = !file.is_dir; - if (!include) continue; + Bool ignore = !!file.is_dir; + if (ignore) continue; String name = D_GetName(file); String extension = D_GetExtension(file); Bool is_c = StringEqual(extension, Lit("c")); Bool is_cpp = !is_c && StringEqual(extension, Lit("cpp")); - include = (is_c || is_cpp) && D_IsDirty(file); - if (!include) continue; + ignore = !(is_c || is_cpp); + if (ignore) continue; /* Determine platform specific source files */ { @@ -541,18 +552,18 @@ void OnBuild(StringList cli_args) StringBeginsWith(name, Lit("playback_")) || StringBeginsWith(name, Lit("mp3_")) || StringBeginsWith(name, Lit("ttf_"))) { - include = false; + ignore = true; if (PlatformWindows) { - include = StringEqual(name, Lit("sys_win32.c")) || - StringEqual(name, Lit("renderer_d3d11.c")) || - StringEqual(name, Lit("playback_wasapi.c")) || - StringEqual(name, Lit("mp3_mmf.c")) || - StringEqual(name, Lit("ttf_dwrite.cpp")); + ignore = !(StringEqual(name, Lit("sys_win32.c")) || + StringEqual(name, Lit("renderer_d3d11.c")) || + StringEqual(name, Lit("playback_wasapi.c")) || + StringEqual(name, Lit("mp3_mmf.c")) || + StringEqual(name, Lit("ttf_dwrite.cpp"))); } } } - if (!include) continue; + if (ignore) continue; D_Tag obj_file; { @@ -561,9 +572,14 @@ void OnBuild(StringList cli_args) obj_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(obj_file_extension)); obj_file = D_FileTagFromPath(&arena, obj_file_path); } + D_AddDependency(obj_file, file); + D_AddDependency(executable, obj_file); - String comp_cmd_fmt = is_c ? final_c_compile_args_fmt : final_cpp_compile_args_fmt; - String comp_cmd = StringF(&arena, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path)); + String comp_cmd = { 0 }; + if (D_IsDirty(obj_file, &hist)) { + String comp_cmd_fmt = is_c ? final_c_compile_args_fmt : final_cpp_compile_args_fmt; + comp_cmd = StringF(&arena, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path)); + } String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(obj_file))); StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, obj_file.full_path, true); @@ -573,7 +589,7 @@ void OnBuild(StringList cli_args) * Compile / link * ========================== */ - if (compile_command_list.first) { + if (D_IsDirty(executable, &hist)) { Bool success = true; StringList link_files = { 0 }; @@ -622,7 +638,7 @@ void OnBuild(StringList cli_args) Assert(false); success = false; } - D_SetDirty(executable); + //D_SetDirty(executable); } if (!success) { Error(Lit("Build failed")); @@ -633,6 +649,12 @@ void OnBuild(StringList cli_args) SH_Print(Lit("Nothing to build")); } + /* ========================== * + * Write hist file + * ========================== */ + + D_WriteStateToHistFile(hist_path); + #if 0 #if Rtc getchar(); diff --git a/src/common.h b/src/common.h index 348ac1af..4555dedf 100644 --- a/src/common.h +++ b/src/common.h @@ -240,6 +240,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); /* Field macros */ #define FIELD_SIZEOF(type, field) sizeof(((type *)0)->field) + #if COMPILER_MSVC && !defined _CRT_USE_BUILTIN_OFFSETOF # define FIELD_OFFSETOF(type, field) ((u64)&(((type *)0)->field)) #else diff --git a/src/sys.h b/src/sys.h index 7b46e025..11003e86 100644 --- a/src/sys.h +++ b/src/sys.h @@ -191,8 +191,6 @@ f64 sys_timestamp_seconds(sys_timestamp_t ts); struct sys_datetime sys_local_time(void); -i32 sys_datetime_cmp(struct sys_datetime t1, struct sys_datetime t2); - /* ========================== * * File system *