mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add --run-once option to delete the output file after running it (#1295)
Add `run-once` option to delete the output file after running it
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
- && doesn't work correctly with lambdas #1279.
|
||||
- Fix incorrect override of optimization levels when using projects.
|
||||
- Add experimental `@noalias` attribute.
|
||||
- Add a `--run-once` option to delete the output file after running it.
|
||||
|
||||
### Fixes
|
||||
|
||||
|
||||
@@ -410,6 +410,7 @@ typedef struct BuildOptions_
|
||||
bool read_stdin;
|
||||
bool print_output;
|
||||
bool print_input;
|
||||
bool run_once;
|
||||
const char *panicfn;
|
||||
const char *benchfn;
|
||||
const char *testfn;
|
||||
@@ -507,6 +508,7 @@ typedef struct
|
||||
const char *asm_file_dir;
|
||||
const char *script_dir;
|
||||
bool run_after_compile;
|
||||
bool delete_after_run;
|
||||
bool generate_benchmark_runner;
|
||||
bool generate_test_runner;
|
||||
bool benchmark_output;
|
||||
@@ -651,4 +653,4 @@ bool command_accepts_files(CompilerCommand command);
|
||||
void update_build_target_with_opt_level(BuildTarget *target, OptimizationSetting level);
|
||||
void create_project(BuildOptions *build_options);
|
||||
void create_library(BuildOptions *build_options);
|
||||
void resolve_libraries(BuildTarget *build_target);
|
||||
void resolve_libraries(BuildTarget *build_target);
|
||||
|
||||
@@ -90,6 +90,7 @@ static void usage(void)
|
||||
PRINTF(" --about - Prints a short description of C3.");
|
||||
PRINTF(" --symtab <value> - Sets the preferred symtab size.");
|
||||
PRINTF(" --max-mem <value> - Sets the preferred max memory size.");
|
||||
PRINTF(" --run-once - After running the output file, delete it immediately.");
|
||||
PRINTF(" -V --version - Print version information.");
|
||||
PRINTF(" -E - Lex only.");
|
||||
PRINTF(" -P - Only parse and output the AST as JSON.");
|
||||
@@ -130,7 +131,6 @@ static void usage(void)
|
||||
PRINTF(" -g - Emit debug info.");
|
||||
PRINTF(" -g0 - Emit no debug info.");
|
||||
PRINTF("");
|
||||
PRINTF("");
|
||||
PRINTF(" -l <library> - Link with the library provided.");
|
||||
PRINTF(" -L <library dir> - Append the directory to the linker search paths.");
|
||||
PRINTF(" -z <argument> - Send the <argument> as a parameter to the linker.");
|
||||
@@ -675,6 +675,10 @@ static void parse_option(BuildOptions *options)
|
||||
print_version();
|
||||
exit_compiler(COMPILER_SUCCESS_EXIT);
|
||||
}
|
||||
if (match_longopt("run-once")) {
|
||||
options->run_once = true;
|
||||
return;
|
||||
}
|
||||
if ((argopt = match_argopt("fp-math")))
|
||||
{
|
||||
options->fp_math = (FpOpt)parse_multi_option(argopt, 3, fp_math);
|
||||
|
||||
@@ -212,6 +212,7 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
|
||||
case COMMAND_COMPILE_RUN:
|
||||
case COMMAND_CLEAN_RUN:
|
||||
target->run_after_compile = true;
|
||||
target->delete_after_run = options->run_once;
|
||||
break;
|
||||
case COMMAND_COMPILE_ONLY:
|
||||
target->type = TARGET_TYPE_OBJECT_FILES;
|
||||
@@ -447,4 +448,4 @@ void init_build_target(BuildTarget *target, BuildOptions *options)
|
||||
if (!file_is_dir(target->build_dir)) error_exit("Expected '%s' to be a directory.", target->build_dir);
|
||||
}
|
||||
load_library_files();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -652,6 +652,12 @@ void compiler_compile(void)
|
||||
printf("Launching %s...\n", name);
|
||||
|
||||
int ret = system(name);
|
||||
|
||||
if (active_target.delete_after_run)
|
||||
{
|
||||
file_delete_file(name);
|
||||
}
|
||||
|
||||
#if PLATFORM_POSIX
|
||||
if (WIFEXITED(ret))
|
||||
{
|
||||
@@ -1311,4 +1317,4 @@ int find_padding_length(const char** arr, const int count)
|
||||
}
|
||||
width += 2;
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user