remove os_exit after step failure

This commit is contained in:
jacob 2024-08-09 15:02:51 -05:00
parent 094b64078b
commit eb3c59ac13

311
build.c
View File

@ -8,11 +8,22 @@ typedef struct StepList StepList;
Bool force_rebuild = false; Bool force_rebuild = false;
Arena arena = { 0 }; Arena perm = { 0 };
D_Store store = { 0 }; D_Store store = { 0 };
D_Hist hist = { 0 }; D_Hist hist = { 0 };
StepList *sl = { 0 }; StepList *sl = { 0 };
/* Args */
String arg_outdir = Lit("build");
Bool arg_msvc = false;
Bool arg_rtc = false;
Bool arg_asan = false;
Bool arg_crtlib = false;
Bool arg_debinfo = false;
Bool arg_developer = false;
Bool arg_profiling = false;
Bool arg_unoptimized = false;
/* ========================== * /* ========================== *
* Util * Util
* ========================== */ * ========================== */
@ -34,6 +45,12 @@ Bool IsDirty(D_Tag tag)
return res; return res;
} }
SH_CommandResult RunCommand(Arena *arena, String command)
{
SH_CommandResult res = SH_RunCommandCaptureOutput(arena, command, true);
return res;
}
/* ========================== * /* ========================== *
* Step * Step
* ========================== */ * ========================== */
@ -120,7 +137,7 @@ void BuildStepSimpleCommand(void *arg_raw)
Step *s = arg_raw; Step *s = arg_raw;
BuildStepSimpleCommandArg *arg = s->arg; BuildStepSimpleCommandArg *arg = s->arg;
SH_CommandResult result = SH_RunCommandCaptureOutput(scratch.arena, arg->cmd, true); SH_CommandResult result = RunCommand(scratch.arena, arg->cmd);
{ {
OS_Lock res_lock = OS_MutexLockE(&s->res_mutex); OS_Lock res_lock = OS_MutexLockE(&s->res_mutex);
@ -147,7 +164,7 @@ void BuildStepMsvcCompileCommand(void *arg_raw)
Step *s = arg_raw; Step *s = arg_raw;
BuildStepMsvcCompileCommandArg *arg = s->arg; BuildStepMsvcCompileCommandArg *arg = s->arg;
SH_CommandResult result = SH_RunCommandCaptureOutput(scratch.arena, arg->cmd, true); SH_CommandResult result = RunCommand(scratch.arena, arg->cmd);
if (!result.error && !D_IsNil(arg->depfile_dependent) && !D_IsNil(arg->output_depfile)) { if (!result.error && !D_IsNil(arg->depfile_dependent) && !D_IsNil(arg->output_depfile)) {
String depfile_data = D_DepfileTextFromMsvcOutput(scratch.arena, arg->depfile_dependent, arg->depfile_force_includes, result.output); String depfile_data = D_DepfileTextFromMsvcOutput(scratch.arena, arg->depfile_dependent, arg->depfile_force_includes, result.output);
@ -182,11 +199,11 @@ void OnBuild(StringList cli_args)
I64 worker_count = OS_GetProcessorCount(); I64 worker_count = OS_GetProcessorCount();
T_StartupWorkers(worker_count); T_StartupWorkers(worker_count);
arena = ArenaAlloc(Gigabyte(64)); perm = ArenaAlloc(Gigabyte(64));
store = D_StoreAlloc(); store = D_StoreAlloc();
sl = ArenaPush(&arena, StepList); sl = ArenaPush(&perm, StepList);
sl->arena = ArenaAlloc(Gigabyte(64)); sl->arena = ArenaAlloc(Gigabyte(64));
sl->mutex = OS_MutexAlloc(); sl->mutex = OS_MutexAlloc();
sl->tq = T_QueueAlloc(); sl->tq = T_QueueAlloc();
@ -195,16 +212,6 @@ void OnBuild(StringList cli_args)
* Read args * Read args
* ========================== */ * ========================== */
String arg_outdir = Lit("build");
Bool arg_msvc = false;
Bool arg_rtc = false;
Bool arg_asan = false;
Bool arg_crtlib = false;
Bool arg_debinfo = false;
Bool arg_developer = false;
Bool arg_profiling = false;
Bool arg_unoptimized = false;
{ {
typedef enum ArgState { typedef enum ArgState {
ArgState_None, ArgState_None,
@ -240,12 +247,12 @@ void OnBuild(StringList cli_args)
} }
} }
String hist_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/.dephist"), FmtStr(arg_outdir))); String hist_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F/.dephist"), FmtStr(arg_outdir)));
String build_hash_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/.pp_build_hash"), FmtStr(arg_outdir))); String build_hash_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F/.pp_build_hash"), FmtStr(arg_outdir)));
String out_dep_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/dep/"), FmtStr(arg_outdir))); String out_dep_dir_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F/dep/"), FmtStr(arg_outdir)));
String out_obj_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/obj/"), FmtStr(arg_outdir))); String out_obj_dir_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F/obj/"), FmtStr(arg_outdir)));
String out_inc_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/inc/"), FmtStr(arg_outdir))); String out_inc_dir_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F/inc/"), FmtStr(arg_outdir)));
String out_bin_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/bin/"), FmtStr(arg_outdir))); String out_bin_dir_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F/bin/"), FmtStr(arg_outdir)));
if (!OS_DirExists(out_obj_dir_path)) { if (!OS_DirExists(out_obj_dir_path)) {
OS_CreateDirAtAbsPath(out_obj_dir_path); OS_CreateDirAtAbsPath(out_obj_dir_path);
@ -265,12 +272,12 @@ void OnBuild(StringList cli_args)
SH_CommandResult where_res = { 0 }; SH_CommandResult where_res = { 0 };
if (arg_msvc) { if (arg_msvc) {
compiler = Lit("Msvc"); compiler = Lit("Msvc");
where_res = SH_RunCommandCaptureOutput(&arena, Lit("where cl.exe"), true); where_res = RunCommand(&perm, Lit("where cl.exe"));
} else { } else {
compiler = Lit("Clang"); compiler = Lit("Clang");
where_res = SH_RunCommandCaptureOutput(&arena, Lit("where clang.exe"), true); where_res = RunCommand(&perm, Lit("where clang.exe"));
} }
compiler_loc = where_res.error ? Lit("Not found") : StringReplace(&arena, where_res.output, Lit("\n"), Lit("")); compiler_loc = where_res.error ? Lit("Not found") : StringReplace(&perm, where_res.output, Lit("\n"), Lit(""));
} }
SH_PrintF(Lit("Compiler path: %F\n"), FmtStr(compiler_loc)); SH_PrintF(Lit("Compiler path: %F\n"), FmtStr(compiler_loc));
SH_PrintF(Lit("Build path: \"%F\"\n"), FmtStr(out_bin_dir_path)); SH_PrintF(Lit("Build path: \"%F\"\n"), FmtStr(out_bin_dir_path));
@ -290,13 +297,13 @@ void OnBuild(StringList cli_args)
Bool should_embed_res_dir = !arg_developer; Bool should_embed_res_dir = !arg_developer;
Bool should_embed_in_rc = !!arg_msvc; Bool should_embed_in_rc = !!arg_msvc;
D_Tag executable_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.exe"), FmtStr(out_bin_dir_path)), D_TagKind_File); D_Tag executable_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/PowerPlay.exe"), FmtStr(out_bin_dir_path)), D_TagKind_File);
D_Tag res_dir = D_TagFromPath(&arena, Lit("res"), D_TagKind_Dir); D_Tag res_dir = D_TagFromPath(&perm, Lit("res"), D_TagKind_Dir);
D_Tag shaders_dir = D_TagFromPath(&arena, Lit("src/shaders"), D_TagKind_Dir); D_Tag shaders_dir = D_TagFromPath(&perm, Lit("src/shaders"), D_TagKind_Dir);
D_Tag icon_file = D_TagFromPath(&arena, Lit("icon.ico"), D_TagKind_File); D_Tag icon_file = D_TagFromPath(&perm, Lit("icon.ico"), D_TagKind_File);
D_Tag inc_src_file = D_TagFromPath(&arena, Lit("src/inc.c"), D_TagKind_File); D_Tag inc_src_file = D_TagFromPath(&perm, Lit("src/inc.c"), D_TagKind_File);
D_Tag rc_res_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path)), D_TagKind_File); D_Tag rc_res_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/rc.res"), FmtStr(out_obj_dir_path)), D_TagKind_File);
/* ========================== * /* ========================== *
* Determine compiler args * Determine compiler args
@ -315,32 +322,32 @@ void OnBuild(StringList cli_args)
{ {
if (arg_msvc) { if (arg_msvc) {
/* Msvc */ /* Msvc */
StringListAppend(&arena, &c_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes")); StringListAppend(&perm, &c_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes"));
StringListAppend(&arena, &cpp_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes")); StringListAppend(&perm, &cpp_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes"));
StringListAppend(&arena, &pch_c_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes")); StringListAppend(&perm, &pch_c_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes"));
StringListAppend(&arena, &pch_cpp_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes")); StringListAppend(&perm, &pch_cpp_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes"));
StringListAppend(&arena, &rc_compile_args, Lit("rc /fo\"%F\" \"%F\"")); StringListAppend(&perm, &rc_compile_args, Lit("rc /fo\"%F\" \"%F\""));
StringListAppend(&arena, &link_args, Lit("link.exe /nologo %F /OUT:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF")); StringListAppend(&perm, &link_args, Lit("link.exe /nologo %F /OUT:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF"));
String warnings = Lit("/WX /Wall " String warnings = Lit("/WX /Wall "
"/options:strict " "/options:strict "
"/wd4820 /wd4201 /wd5220 /wd4514 /wd4244 /wd5045 /wd4242 /wd4061 /wd4189 /wd4723 /wd5246"); "/wd4820 /wd4201 /wd5220 /wd4514 /wd4244 /wd5045 /wd4242 /wd4061 /wd4189 /wd4723 /wd5246");
StringListAppend(&arena, &compile_warnings, warnings); StringListAppend(&perm, &compile_warnings, warnings);
StringListAppend(&arena, &link_warnings, Lit("/WX")); StringListAppend(&perm, &link_warnings, Lit("/WX"));
StringListAppend(&arena, &compile_args, StringF(&arena, Lit("/Fd\"%F\\\""), FmtStr(out_bin_dir_path))); StringListAppend(&perm, &compile_args, StringF(&perm, Lit("/Fd\"%F\\\""), FmtStr(out_bin_dir_path)));
} else { } else {
/* Clang */ /* Clang */
StringListAppend(&arena, &c_compile_args, Lit("clang -xc -std=c99 -c \"%F\" -o \"%F\" -MD")); StringListAppend(&perm, &c_compile_args, Lit("clang -xc -std=c99 -c \"%F\" -o \"%F\" -MD"));
StringListAppend(&arena, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c \"%F\" -o \"%F\" -MD")); StringListAppend(&perm, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c \"%F\" -o \"%F\" -MD"));
StringListAppend(&arena, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c \"%F\" -o \"%F\" -MD")); StringListAppend(&perm, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c \"%F\" -o \"%F\" -MD"));
StringListAppend(&arena, &pch_cpp_compile_args, Lit("clang -xc++-header -std=c++20 -c \"%F\" -o \"%F\" -MD")); StringListAppend(&perm, &pch_cpp_compile_args, Lit("clang -xc++-header -std=c++20 -c \"%F\" -o \"%F\" -MD"));
StringListAppend(&arena, &rc_compile_args, Lit("llvm-rc /fo\"%F\" \"%F\"")); StringListAppend(&perm, &rc_compile_args, Lit("llvm-rc /fo\"%F\" \"%F\""));
StringListAppend(&arena, &link_args, Lit("clang %F -o \"%F\"")); StringListAppend(&perm, &link_args, Lit("clang %F -o \"%F\""));
StringListAppend(&arena, StringListAppend(&perm,
&compile_and_link_args, &compile_and_link_args,
Lit("-fuse-ld=lld-link " Lit("-fuse-ld=lld-link "
"-fno-strict-aliasing " "-fno-strict-aliasing "
@ -368,8 +375,8 @@ void OnBuild(StringList cli_args)
"-Wno-double-promotion"); "-Wno-double-promotion");
/* -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter */ /* -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter */
StringListAppend(&arena, &compile_warnings, warnings); StringListAppend(&perm, &compile_warnings, warnings);
StringListAppend(&arena, &link_warnings, warnings); StringListAppend(&perm, &link_warnings, warnings);
} }
/* RTC */ /* RTC */
@ -378,56 +385,56 @@ void OnBuild(StringList cli_args)
Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with RTC (runtime checks)")); Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with RTC (runtime checks)"));
OS_Exit(1); OS_Exit(1);
} }
StringListAppend(&arena, &compile_args, Lit("-DRTC=1")); StringListAppend(&perm, &compile_args, Lit("-DRTC=1"));
if (arg_msvc) { if (arg_msvc) {
if (!arg_asan) { if (!arg_asan) {
/* Enable /RTC option (not compatible with ASAN) */ /* Enable /RTC option (not compatible with ASAN) */
StringListAppend(&arena, &compile_args, Lit("/RTCcsu")); StringListAppend(&perm, &compile_args, Lit("/RTCcsu"));
} }
} else { } else {
/* Enable UBSan */ /* Enable UBSan */
StringListAppend(&arena, &compile_and_link_args, Lit("-fsanitize=undefined -fsanitize-trap=all")); StringListAppend(&perm, &compile_and_link_args, Lit("-fsanitize=undefined -fsanitize-trap=all"));
//StringListAppend(&arena, &compile_and_link_args, Lit("-fsanitize=undefined")); //StringListAppend(&arena, &compile_and_link_args, Lit("-fsanitize=undefined"));
} }
} }
/* CRTLIB */ /* CRTLIB */
if (arg_crtlib) { if (arg_crtlib) {
StringListAppend(&arena, &compile_args, Lit("-DCRTLIB=1")); StringListAppend(&perm, &compile_args, Lit("-DCRTLIB=1"));
} else { } else {
if (arg_msvc) { if (arg_msvc) {
/* TODO */ /* TODO */
Error(Lit("TODO\n")); Error(Lit("TODO\n"));
OS_Exit(1); OS_Exit(1);
} else { } else {
StringListAppend(&arena, &compile_and_link_args, Lit("-mno-stack-arg-probe -fno-builtin -nostdlib")); StringListAppend(&perm, &compile_and_link_args, Lit("-mno-stack-arg-probe -fno-builtin -nostdlib"));
} }
} }
/* Optimization */ /* Optimization */
if (arg_unoptimized) { if (arg_unoptimized) {
StringListAppend(&arena, &compile_args, Lit("-DUNOPTIMIZED=1")); StringListAppend(&perm, &compile_args, Lit("-DUNOPTIMIZED=1"));
if (arg_msvc) { if (arg_msvc) {
StringListAppend(&arena, &compile_args, Lit("/Od")); StringListAppend(&perm, &compile_args, Lit("/Od"));
} else { } else {
StringListAppend(&arena, &compile_and_link_args, Lit("-O0")); StringListAppend(&perm, &compile_and_link_args, Lit("-O0"));
} }
} else { } else {
if (arg_msvc) { if (arg_msvc) {
StringListAppend(&arena, &compile_args, Lit("/O2")); StringListAppend(&perm, &compile_args, Lit("/O2"));
StringListAppend(&arena, &link_args, Lit("/LTCG")); StringListAppend(&perm, &link_args, Lit("/LTCG"));
} else { } else {
StringListAppend(&arena, &compile_and_link_args, Lit("-O3 -flto")); StringListAppend(&perm, &compile_and_link_args, Lit("-O3 -flto"));
} }
} }
/* Debug info */ /* Debug info */
if (arg_debinfo) { if (arg_debinfo) {
StringListAppend(&arena, &compile_args, Lit("-DDEBINFO=1")); StringListAppend(&perm, &compile_args, Lit("-DDEBINFO=1"));
if (arg_msvc) { if (arg_msvc) {
StringListAppend(&arena, &compile_args, Lit("/JMC /Zi")); StringListAppend(&perm, &compile_args, Lit("/JMC /Zi"));
} else { } else {
StringListAppend(&arena, &compile_and_link_args, Lit("-g")); StringListAppend(&perm, &compile_and_link_args, Lit("-g"));
} }
} }
@ -437,17 +444,17 @@ void OnBuild(StringList cli_args)
Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with asan enabled")); Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with asan enabled"));
OS_Exit(1); OS_Exit(1);
} }
StringListAppend(&arena, &compile_args, Lit("-DASAN=1")); StringListAppend(&perm, &compile_args, Lit("-DASAN=1"));
if (arg_msvc) { if (arg_msvc) {
StringListAppend(&arena, &compile_args, Lit("/fsanitize=address")); StringListAppend(&perm, &compile_args, Lit("/fsanitize=address"));
} else { } else {
StringListAppend(&arena, &compile_and_link_args, Lit("-fsanitize=address -shared-libasan")); StringListAppend(&perm, &compile_and_link_args, Lit("-fsanitize=address -shared-libasan"));
} }
} }
/* Developer mode */ /* Developer mode */
if (arg_developer) { if (arg_developer) {
StringListAppend(&arena, &compile_args, Lit("-DDEVELOPER=1")); StringListAppend(&perm, &compile_args, Lit("-DDEVELOPER=1"));
} }
/* Profiling */ /* Profiling */
@ -460,19 +467,19 @@ void OnBuild(StringList cli_args)
Error(Lit("MSVC not supported with profiling enabled (Profiling relies on Clang attributes)")); Error(Lit("MSVC not supported with profiling enabled (Profiling relies on Clang attributes)"));
OS_Exit(1); OS_Exit(1);
} }
StringListAppend(&arena, &compile_args, Lit("-DPROFILING=1")); StringListAppend(&perm, &compile_args, Lit("-DPROFILING=1"));
/* Tracy flags */ /* Tracy flags */
StringListAppend(&arena, &compile_args, Lit("-DTRACY_ENABLE=1")); StringListAppend(&perm, &compile_args, Lit("-DTRACY_ENABLE=1"));
StringListAppend(&arena, &compile_args, Lit("-DTRACY_CALLSTACK=5")); StringListAppend(&perm, &compile_args, Lit("-DTRACY_CALLSTACK=5"));
StringListAppend(&arena, &compile_args, Lit("-DTRACY_NO_SAMPLING -DTRACY_NO_SYSTEM_TRACING -DTRACY_NO_CALLSTACK")); StringListAppend(&perm, &compile_args, Lit("-DTRACY_NO_SAMPLING -DTRACY_NO_SYSTEM_TRACING -DTRACY_NO_CALLSTACK"));
/* Disable compile_warnings when compiling tracy client */ /* Disable compile_warnings when compiling tracy client */
compile_warnings = (StringList) { 0 }; compile_warnings = (StringList) { 0 };
link_warnings = (StringList) { 0 }; link_warnings = (StringList) { 0 };
} }
if (!arg_msvc) { if (!arg_msvc) {
String incbin_dir = StringReplace(&arena, out_inc_dir_path, Lit("\\"), Lit("/")); String incbin_dir = StringReplace(&perm, out_inc_dir_path, Lit("\\"), Lit("/"));
StringListAppend(&arena, &compile_args, StringF(&arena, Lit("-DINCBIN_DIR_RAW=\"%F\""), FmtStr(incbin_dir))); StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DINCBIN_DIR_RAW=\"%F\""), FmtStr(incbin_dir)));
} }
} }
@ -481,11 +488,11 @@ void OnBuild(StringList cli_args)
* ========================== */ * ========================== */
{ {
D_Tag build_hash_file = D_TagFromPath(&arena, build_hash_path, D_TagKind_File); D_Tag build_hash_file = D_TagFromPath(&perm, build_hash_path, D_TagKind_File);
U64 build_hash = D_HashString64Basis; U64 build_hash = D_HashString64Basis;
{ {
String args_str = StringFromStringList(&arena, Lit(" "), cli_args); String args_str = StringFromStringList(&perm, Lit(" "), cli_args);
String compile_time_str = Lit(__DATE__ __TIME__); String compile_time_str = Lit(__DATE__ __TIME__);
build_hash = D_HashString64(build_hash, args_str); build_hash = D_HashString64(build_hash, args_str);
build_hash = D_HashString64(build_hash, compile_time_str); build_hash = D_HashString64(build_hash, compile_time_str);
@ -493,7 +500,7 @@ void OnBuild(StringList cli_args)
U64 old_build_hash = 0; U64 old_build_hash = 0;
{ {
String build_hash_file_data = D_ReadAll(&arena, build_hash_file); String build_hash_file_data = D_ReadAll(&perm, build_hash_file);
if (build_hash_file_data.len >= 8) { if (build_hash_file_data.len >= 8) {
MemoryCopy((Byte *)&old_build_hash, build_hash_file_data.text, 8); MemoryCopy((Byte *)&old_build_hash, build_hash_file_data.text, 8);
} }
@ -511,7 +518,7 @@ void OnBuild(StringList cli_args)
* Begin build * Begin build
* ========================== */ * ========================== */
hist = D_HistFromPath(&arena, hist_path); hist = D_HistFromPath(&perm, hist_path);
D_TagList link_files = { 0 }; D_TagList link_files = { 0 };
/* ========================== * /* ========================== *
@ -523,15 +530,15 @@ void OnBuild(StringList cli_args)
D_TagList tar_input_dirs = { 0 }; D_TagList tar_input_dirs = { 0 };
{ {
D_TagListAppend(&arena, &tar_input_dirs, shaders_dir); D_TagListAppend(&perm, &tar_input_dirs, shaders_dir);
if (should_embed_res_dir) { if (should_embed_res_dir) {
D_TagListAppend(&arena, &tar_input_dirs, res_dir); D_TagListAppend(&perm, &tar_input_dirs, res_dir);
} }
} }
for (D_TagListNode *n = tar_input_dirs.first; n; n = n->next) { for (D_TagListNode *n = tar_input_dirs.first; n; n = n->next) {
D_Tag input_dir = n->tag; D_Tag input_dir = n->tag;
D_Tag tar_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(input_dir))), D_TagKind_File); D_Tag tar_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(input_dir))), D_TagKind_File);
D_AddDependency(&store, tar_file, input_dir); D_AddDependency(&store, tar_file, input_dir);
if (should_embed_in_rc) { if (should_embed_in_rc) {
D_AddDependency(&store, rc_res_file, tar_file); D_AddDependency(&store, rc_res_file, tar_file);
@ -539,9 +546,9 @@ void OnBuild(StringList cli_args)
D_AddDependency(&store, inc_src_file, tar_file); D_AddDependency(&store, inc_src_file, tar_file);
} }
if (IsDirty(tar_file)) { if (IsDirty(tar_file)) {
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&arena, BuildStepSimpleCommandArg); BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
bs_arg->cmd = StringF(&arena, Lit("cd %F && tar cvf %F ."), FmtStr(input_dir.full_path), FmtStr(tar_file.full_path)); bs_arg->cmd = StringF(&perm, Lit("cd %F && tar cvf %F ."), FmtStr(input_dir.full_path), FmtStr(tar_file.full_path));
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(input_dir)), FmtStr(D_GetName(tar_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(input_dir)), FmtStr(D_GetName(tar_file)));
AddStep(step_name, &BuildStepSimpleCommand, bs_arg); AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
} }
} }
@ -554,10 +561,10 @@ void OnBuild(StringList cli_args)
if (PlatformWindows) { if (PlatformWindows) {
AddSyncPoint(); AddSyncPoint();
D_Tag rc_input_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/rc.rc"), FmtStr(out_inc_dir_path)), D_TagKind_File); D_Tag rc_input_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/rc.rc"), FmtStr(out_inc_dir_path)), D_TagKind_File);
{ {
D_Tag shaders_tar_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(shaders_dir))), D_TagKind_File); D_Tag shaders_tar_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(shaders_dir))), D_TagKind_File);
D_Tag res_tar_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(res_dir))), D_TagKind_File); D_Tag res_tar_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.tar"), FmtStr(out_inc_dir_path), FmtStr(D_GetName(res_dir))), D_TagKind_File);
D_AddDependency(&store, rc_input_file, icon_file); D_AddDependency(&store, rc_input_file, icon_file);
if (should_embed_in_rc) { if (should_embed_in_rc) {
D_AddDependency(&store, rc_input_file, shaders_tar_file); D_AddDependency(&store, rc_input_file, shaders_tar_file);
@ -567,28 +574,28 @@ void OnBuild(StringList cli_args)
} }
if (IsDirty(rc_input_file)) { if (IsDirty(rc_input_file)) {
D_ClearWrite(rc_input_file, Lit("")); D_ClearWrite(rc_input_file, Lit(""));
D_AppendWrite(rc_input_file, StringF(&arena, Lit("%F %F DISCARDABLE %F\n"), FmtStr(D_GetName(icon_file)), FmtStr(Lit("ICON")), FmtStr(D_GetName(icon_file)))); D_AppendWrite(rc_input_file, StringF(&perm, Lit("%F %F DISCARDABLE %F\n"), FmtStr(D_GetName(icon_file)), FmtStr(Lit("ICON")), FmtStr(D_GetName(icon_file))));
if (should_embed_in_rc) { if (should_embed_in_rc) {
D_AppendWrite(rc_input_file, StringF(&arena, Lit("%F %F DISCARDABLE %F\n"), FmtStr(D_GetName(shaders_tar_file)), FmtStr(Lit("RCDATA")), FmtStr(D_GetName(shaders_tar_file)))); D_AppendWrite(rc_input_file, StringF(&perm, Lit("%F %F DISCARDABLE %F\n"), FmtStr(D_GetName(shaders_tar_file)), FmtStr(Lit("RCDATA")), FmtStr(D_GetName(shaders_tar_file))));
if (should_embed_res_dir) { if (should_embed_res_dir) {
D_AppendWrite(rc_input_file, StringF(&arena, Lit("%F %F DISCARDABLE %F\n"), FmtStr(D_GetName(res_tar_file)), FmtStr(Lit("RCDATA")), FmtStr(D_GetName(res_tar_file)))); D_AppendWrite(rc_input_file, StringF(&perm, Lit("%F %F DISCARDABLE %F\n"), FmtStr(D_GetName(res_tar_file)), FmtStr(Lit("RCDATA")), FmtStr(D_GetName(res_tar_file))));
} }
} }
} }
} }
{ {
String rc_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), rc_compile_args); String rc_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), rc_compile_args);
D_AddDependency(&store, rc_res_file, rc_input_file); D_AddDependency(&store, rc_res_file, rc_input_file);
if (IsDirty(rc_res_file)) { if (IsDirty(rc_res_file)) {
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&arena, BuildStepSimpleCommandArg); BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
bs_arg->cmd = StringF(&arena, rc_compile_args_fmt, FmtStr(rc_res_file.full_path), FmtStr(rc_input_file.full_path)); bs_arg->cmd = StringF(&perm, rc_compile_args_fmt, FmtStr(rc_res_file.full_path), FmtStr(rc_input_file.full_path));
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(rc_input_file)), FmtStr(D_GetName(rc_res_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(rc_input_file)), FmtStr(D_GetName(rc_res_file)));
AddStep(step_name, &BuildStepSimpleCommand, bs_arg); AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
} }
D_TagListAppend(&arena, &link_files, rc_res_file); D_TagListAppend(&perm, &link_files, rc_res_file);
} }
} }
@ -600,51 +607,51 @@ void OnBuild(StringList cli_args)
{ {
AddSyncPoint(); AddSyncPoint();
D_Tag pch_header_file = D_TagFromPath(&arena, Lit("src/common.h"), D_TagKind_File); D_Tag pch_header_file = D_TagFromPath(&perm, Lit("src/common.h"), D_TagKind_File);
D_Tag dep_file; D_Tag dep_file;
{ {
String name = D_GetName(pch_header_file); String name = D_GetName(pch_header_file);
String dep_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name), FmtStr(dep_file_extension)); String dep_file_path = StringF(&perm, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name), FmtStr(dep_file_extension));
dep_file = D_TagFromPath(&arena, dep_file_path, D_TagKind_DepFile); dep_file = D_TagFromPath(&perm, dep_file_path, D_TagKind_DepFile);
} }
D_Tag pch_c_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.c_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File); D_Tag pch_c_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.c_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File);
D_AddDependency(&store, pch_c_file, pch_header_file); D_AddDependency(&store, pch_c_file, pch_header_file);
D_AddDependency(&store, pch_c_file, dep_file); D_AddDependency(&store, pch_c_file, dep_file);
D_Tag pch_cpp_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/%F.cpp_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File); D_Tag pch_cpp_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.cpp_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File);
D_AddDependency(&store, pch_cpp_file, pch_header_file); D_AddDependency(&store, pch_cpp_file, pch_header_file);
D_AddDependency(&store, pch_cpp_file, dep_file); D_AddDependency(&store, pch_cpp_file, dep_file);
if (arg_msvc) { if (arg_msvc) {
D_TagListAppend(&arena, &depfile_force_includes, pch_header_file); D_TagListAppend(&perm, &depfile_force_includes, pch_header_file);
D_Tag pch_c_src_gen_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.c"), FmtStr(out_obj_dir_path)), D_TagKind_File); D_Tag pch_c_src_gen_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.c"), FmtStr(out_obj_dir_path)), D_TagKind_File);
D_Tag pch_c_src_gen_obj_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File); D_Tag pch_c_src_gen_obj_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File);
D_Tag pch_cpp_src_gen_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path)), D_TagKind_File); D_Tag pch_cpp_src_gen_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path)), D_TagKind_File);
D_Tag pch_cpp_src_gen_obj_file = D_TagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File); D_Tag pch_cpp_src_gen_obj_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File);
StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path))); StringListAppend(&perm, &c_compile_args, StringF(&perm, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path)));
StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path))); StringListAppend(&perm, &cpp_compile_args, StringF(&perm, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path)));
StringListAppend(&arena, &pch_c_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path), FmtStr(pch_c_src_gen_obj_file.full_path))); StringListAppend(&perm, &pch_c_compile_args, StringF(&perm, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path), FmtStr(pch_c_src_gen_obj_file.full_path)));
StringListAppend(&arena, &pch_cpp_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path), FmtStr(pch_cpp_src_gen_obj_file.full_path))); StringListAppend(&perm, &pch_cpp_compile_args, StringF(&perm, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path), FmtStr(pch_cpp_src_gen_obj_file.full_path)));
D_TagListAppend(&arena, &link_files, pch_c_src_gen_obj_file); D_TagListAppend(&perm, &link_files, pch_c_src_gen_obj_file);
D_TagListAppend(&arena, &link_files, pch_cpp_src_gen_obj_file); D_TagListAppend(&perm, &link_files, pch_cpp_src_gen_obj_file);
String pch_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args); String pch_c_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args);
String pch_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args); String pch_cpp_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
/* C */ /* C */
D_AddDependency(&store, pch_c_src_gen_obj_file, pch_c_src_gen_file); D_AddDependency(&store, pch_c_src_gen_obj_file, pch_c_src_gen_file);
D_AddDependency(&store, pch_c_file, pch_c_src_gen_obj_file); D_AddDependency(&store, pch_c_file, pch_c_src_gen_obj_file);
if (IsDirty(pch_c_file)) { if (IsDirty(pch_c_file)) {
D_ClearWrite(pch_c_src_gen_file, Lit("")); D_ClearWrite(pch_c_src_gen_file, Lit(""));
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&arena, BuildStepMsvcCompileCommandArg); BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
bs_arg->cmd = StringF(&arena, pch_c_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_c_src_gen_file.full_path)); bs_arg->cmd = StringF(&perm, pch_c_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_c_src_gen_file.full_path));
bs_arg->depfile_dependent = pch_header_file; bs_arg->depfile_dependent = pch_header_file;
bs_arg->output_depfile = dep_file; bs_arg->output_depfile = dep_file;
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_c_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_c_file)));
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg); AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
} }
@ -653,33 +660,33 @@ void OnBuild(StringList cli_args)
D_AddDependency(&store, pch_cpp_file, pch_cpp_src_gen_obj_file); D_AddDependency(&store, pch_cpp_file, pch_cpp_src_gen_obj_file);
if (IsDirty(pch_cpp_file)) { if (IsDirty(pch_cpp_file)) {
D_ClearWrite(pch_cpp_src_gen_file, Lit("")); D_ClearWrite(pch_cpp_src_gen_file, Lit(""));
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&arena, BuildStepMsvcCompileCommandArg); BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
bs_arg->cmd = StringF(&arena, pch_cpp_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_src_gen_file.full_path)); bs_arg->cmd = StringF(&perm, pch_cpp_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_src_gen_file.full_path));
bs_arg->depfile_dependent = pch_header_file; bs_arg->depfile_dependent = pch_header_file;
bs_arg->output_depfile = dep_file; bs_arg->output_depfile = dep_file;
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_cpp_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_cpp_file)));
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg); AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
} }
} else { } else {
StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_c_file.full_path))); StringListAppend(&perm, &c_compile_args, StringF(&perm, Lit("-include-pch %F"), FmtStr(pch_c_file.full_path)));
StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_cpp_file.full_path))); StringListAppend(&perm, &cpp_compile_args, StringF(&perm, Lit("-include-pch %F"), FmtStr(pch_cpp_file.full_path)));
String pch_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args); String pch_c_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args);
String pch_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args); String pch_cpp_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
/* C */ /* C */
if (IsDirty(pch_c_file)) { if (IsDirty(pch_c_file)) {
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&arena, BuildStepSimpleCommandArg); BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
bs_arg->cmd = StringF(&arena, pch_c_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path)); bs_arg->cmd = StringF(&perm, pch_c_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path));
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_c_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_c_file)));
AddStep(step_name, &BuildStepSimpleCommand, bs_arg); AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
} }
/* Cpp */ /* Cpp */
if (IsDirty(pch_cpp_file)) { if (IsDirty(pch_cpp_file)) {
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&arena, BuildStepSimpleCommandArg); BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
bs_arg->cmd = StringF(&arena, pch_cpp_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path)); bs_arg->cmd = StringF(&perm, pch_cpp_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path));
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_cpp_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_cpp_file)));
AddStep(step_name, &BuildStepSimpleCommand, bs_arg); AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
} }
} }
@ -692,14 +699,14 @@ void OnBuild(StringList cli_args)
{ {
D_TagList src_input_files = { 0 }; D_TagList src_input_files = { 0 };
{ {
D_Tag src_dir = D_TagFromPath(&arena, Lit("src"), D_TagKind_Dir); D_Tag src_dir = D_TagFromPath(&perm, Lit("src"), D_TagKind_Dir);
D_TagList src_files = D_GetDirContents(&arena, src_dir, false); D_TagList src_files = D_GetDirContents(&perm, src_dir, false);
if (arg_profiling) { if (arg_profiling) {
D_Tag tracy_src_dir = D_TagFromPath(&arena, Lit("src/third_party/tracy"), D_TagKind_Dir); D_Tag tracy_src_dir = D_TagFromPath(&perm, Lit("src/third_party/tracy"), D_TagKind_Dir);
D_TagList tracy_src_files = D_GetDirContents(&arena, tracy_src_dir, true); D_TagList tracy_src_files = D_GetDirContents(&perm, tracy_src_dir, true);
for (D_TagListNode *n = tracy_src_files.first; n; n = n->next) { for (D_TagListNode *n = tracy_src_files.first; n; n = n->next) {
D_TagListAppend(&arena, &src_files, n->tag); D_TagListAppend(&perm, &src_files, n->tag);
} }
} }
@ -732,7 +739,7 @@ void OnBuild(StringList cli_args)
} }
if (!ignore) { if (!ignore) {
D_TagListAppend(&arena, &src_input_files, file); D_TagListAppend(&perm, &src_input_files, file);
} }
} }
} }
@ -740,8 +747,8 @@ void OnBuild(StringList cli_args)
{ {
AddSyncPoint(); AddSyncPoint();
String c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), c_compile_args, compile_warnings, compile_and_link_args, compile_args); String c_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), c_compile_args, compile_warnings, compile_and_link_args, compile_args);
String cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), cpp_compile_args, compile_warnings, compile_and_link_args, compile_args); String cpp_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
for (D_TagListNode *n = src_input_files.first; n; n = n->next) { for (D_TagListNode *n = src_input_files.first; n; n = n->next) {
D_Tag file = n->tag; D_Tag file = n->tag;
String path = file.full_path; String path = file.full_path;
@ -753,37 +760,37 @@ void OnBuild(StringList cli_args)
D_Tag dep_file; D_Tag dep_file;
{ {
String name_no_extension = StringPathNoExtension(name); String name_no_extension = StringPathNoExtension(name);
String dep_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension)); String dep_file_path = StringF(&perm, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension));
dep_file = D_TagFromPath(&arena, dep_file_path, D_TagKind_DepFile); dep_file = D_TagFromPath(&perm, dep_file_path, D_TagKind_DepFile);
} }
D_Tag obj_file; D_Tag obj_file;
{ {
String name_no_extension = StringPathNoExtension(name); String name_no_extension = StringPathNoExtension(name);
String obj_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(obj_file_extension)); String obj_file_path = StringF(&perm, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(obj_file_extension));
obj_file = D_TagFromPath(&arena, obj_file_path, D_TagKind_File); obj_file = D_TagFromPath(&perm, obj_file_path, D_TagKind_File);
} }
D_AddDependency(&store, obj_file, file); D_AddDependency(&store, obj_file, file);
D_AddDependency(&store, obj_file, dep_file); D_AddDependency(&store, obj_file, dep_file);
if (IsDirty(obj_file)) { if (IsDirty(obj_file)) {
String comp_cmd_fmt = is_c ? c_compile_args_fmt : cpp_compile_args_fmt; String comp_cmd_fmt = is_c ? c_compile_args_fmt : cpp_compile_args_fmt;
String step_name = StringF(&arena, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(obj_file))); String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(obj_file)));
if (arg_msvc) { if (arg_msvc) {
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&arena, BuildStepMsvcCompileCommandArg); BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
bs_arg->cmd = StringF(&arena, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path)); bs_arg->cmd = StringF(&perm, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path));
bs_arg->depfile_dependent = obj_file; bs_arg->depfile_dependent = obj_file;
bs_arg->output_depfile = dep_file; bs_arg->output_depfile = dep_file;
bs_arg->depfile_force_includes = depfile_force_includes; bs_arg->depfile_force_includes = depfile_force_includes;
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg); AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
} else { } else {
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&arena, BuildStepSimpleCommandArg); BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
bs_arg->cmd = StringF(&arena, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path)); bs_arg->cmd = StringF(&perm, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path));
AddStep(step_name, &BuildStepSimpleCommand, bs_arg); AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
} }
} }
D_TagListAppend(&arena, &link_files, obj_file); D_TagListAppend(&perm, &link_files, obj_file);
} }
} }
} }
@ -800,16 +807,16 @@ void OnBuild(StringList cli_args)
StringList link_files_quoted_list = { 0 }; StringList link_files_quoted_list = { 0 };
for (D_TagListNode *n = link_files.first; n; n = n->next) { for (D_TagListNode *n = link_files.first; n; n = n->next) {
D_Tag file = n->tag; D_Tag file = n->tag;
String path = StringF(&arena, Lit("\"%F\""), FmtStr(file.full_path)); String path = StringF(&perm, Lit("\"%F\""), FmtStr(file.full_path));
StringListAppend(&arena, &link_files_quoted_list, path); StringListAppend(&perm, &link_files_quoted_list, path);
D_AddDependency(&store, executable_file, file); D_AddDependency(&store, executable_file, file);
} }
link_files_str = StringFromStringList(&arena, Lit(" "), link_files_quoted_list); link_files_str = StringFromStringList(&perm, Lit(" "), link_files_quoted_list);
} }
if (link_files_str.len > 0 && IsDirty(executable_file)) { if (link_files_str.len > 0 && IsDirty(executable_file)) {
String link_args_fmt = StringFromStringLists(&arena, Lit(" "), link_args, link_warnings, compile_and_link_args); String link_args_fmt = StringFromStringLists(&perm, Lit(" "), link_args, link_warnings, compile_and_link_args);
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&arena, BuildStepSimpleCommandArg); BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
bs_arg->cmd = StringF(&arena, link_args_fmt, FmtStr(link_files_str), FmtStr(executable_file.full_path)); bs_arg->cmd = StringF(&perm, link_args_fmt, FmtStr(link_files_str), FmtStr(executable_file.full_path));
String step_name = Lit("Linking"); String step_name = Lit("Linking");
AddStep(step_name, &BuildStepSimpleCommand, bs_arg); AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
} }
@ -844,7 +851,6 @@ void OnBuild(StringList cli_args)
Assert(false); Assert(false);
success = false; success = false;
SH_PrintF(Lit("%F\n"), FmtStr(output)); SH_PrintF(Lit("%F\n"), FmtStr(output));
break;
} }
s = s->next; s = s->next;
@ -857,7 +863,6 @@ void OnBuild(StringList cli_args)
if (!success) { if (!success) {
Error(Lit("Build failed\n")); Error(Lit("Build failed\n"));
OS_Exit(1);
} }
T_ShutdownWorkers(); T_ShutdownWorkers();