diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2025-05-22 17:54:15 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2025-05-22 17:58:51 -0400 |
| commit | 5b5822effce461e3ecfdc3b57009736208999959 (patch) | |
| tree | 3c3e31da88d62cc1d6b7edf6fa218000aae06d8d /src/main.cpp | |
| parent | 0536f8626833e6b2938cbedf84b2cf06c95c0ae0 (diff) | |
Delete test executable after running, add `-keep-test-executable`
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5aaadc0d2..faedb9074 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -313,6 +313,7 @@ enum BuildFlagKind { BuildFlag_Define, BuildFlag_BuildMode, BuildFlag_BuildOnly, + BuildFlag_KeepTestExecutable, BuildFlag_Target, BuildFlag_Subtarget, BuildFlag_Debug, @@ -533,6 +534,7 @@ gb_internal bool parse_build_flags(Array<String> args) { add_flag(&build_flags, BuildFlag_Define, str_lit("define"), BuildFlagParam_String, Command__does_check, true); add_flag(&build_flags, BuildFlag_BuildMode, str_lit("build-mode"), BuildFlagParam_String, Command__does_build); // Commands_build is not used to allow for a better error message add_flag(&build_flags, BuildFlag_BuildOnly, str_lit("build-only"), BuildFlagParam_None, Command_test); + add_flag(&build_flags, BuildFlag_KeepTestExecutable, str_lit("keep-test-executable"), BuildFlagParam_None, Command_test); add_flag(&build_flags, BuildFlag_Target, str_lit("target"), BuildFlagParam_String, Command__does_check); add_flag(&build_flags, BuildFlag_Subtarget, str_lit("subtarget"), BuildFlagParam_String, Command__does_check); add_flag(&build_flags, BuildFlag_Debug, str_lit("debug"), BuildFlagParam_None, Command__does_check); @@ -1196,7 +1198,22 @@ gb_internal bool parse_build_flags(Array<String> args) { break; } case BuildFlag_BuildOnly: - build_context.build_only = true; + if (build_context.keep_test_executable) { + gb_printf_err("`-keep-test-executable` is mutually exclusive with `-build-only`.\n"); + gb_printf_err("We either only build or run the test and optionally keep the executable.\n"); + bad_flags = true; + } else { + build_context.build_only = true; + } + break; + case BuildFlag_KeepTestExecutable: + if (build_context.build_only) { + gb_printf_err("`-build-only` is mutually exclusive with `-keep-test-executable`.\n"); + gb_printf_err("We either only build or run the test and optionally keep the executable.\n"); + bad_flags = true; + } else { + build_context.keep_test_executable = true; + } break; case BuildFlag_Debug: @@ -2554,6 +2571,12 @@ gb_internal int print_show_help(String const arg0, String command, String option } } + if (test_only) { + if (print_flag("-keep-test-executable")) { + print_usage_line(2, "Keep the test executable after running it instead of deleting it normally."); + } + } + if (run_or_build) { if (print_flag("-linker:<string>")) { print_usage_line(2, "Specify the linker to use."); @@ -3877,6 +3900,11 @@ end_of_code_gen:; defer (gb_free(heap_allocator(), exe_name.text)); system_must_exec_command_line_app("odin run", "\"%.*s\" %.*s", LIT(exe_name), LIT(run_args_string)); + + if (build_context.command_kind == Command_test && !build_context.keep_test_executable) { + char const *filename = cast(char const *)exe_name.text; + gb_file_remove(filename); + } } return 0; } |