diff --git a/src/bsys.c b/src/bsys.c index b0f4ba79..f7671bb2 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -264,3 +264,11 @@ int bsys_sh(bsys_t const* bsys, int argc, char* argv[]) { int bsys_install(bsys_t const* bsys) { return install(bsys, false); } + +int bsys_clean(bsys_t const* bsys) { + if (bsys->clean == NULL) { + return 0; + } + + return bsys->clean(); +} diff --git a/src/bsys.h b/src/bsys.h index 2121fd0e..47b73d9d 100644 --- a/src/bsys.h +++ b/src/bsys.h @@ -19,6 +19,7 @@ struct bsys_t { int (*build_deps)(dep_node_t* tree); int (*build)(void); int (*install)(void); + int (*clean)(void); int (*run)(int argc, char* argv[]); void (*destroy)(void); }; @@ -49,3 +50,4 @@ int bsys_build(bsys_t const* bsys); int bsys_run(bsys_t const* bsys, int argc, char* argv[]); int bsys_sh(bsys_t const* bsys, int argc, char* argv[]); int bsys_install(bsys_t const* bsys); +int bsys_clean(bsys_t const* bsys); diff --git a/src/bsys/bob/main.c b/src/bsys/bob/main.c index 588f19a2..1051ee2c 100644 --- a/src/bsys/bob/main.c +++ b/src/bsys/bob/main.c @@ -280,6 +280,20 @@ static int build(void) { return run_build_steps(); } +static int clean(void) { + char* STR_CLEANUP err = NULL; + + LOG_INFO("Will remove \"%s\". ^C to cancel now.", abs_out_path); + getchar(); + + if (rm(abs_out_path, &err) < 0) { + LOG_FATAL("Failed to clean output directory (\"%s\"): %s", abs_out_path, err); + return -1; + } + + return 0; +} + static int run(int argc, char* argv[]) { // Find run vector. @@ -367,6 +381,7 @@ bsys_t const BSYS_BOB = { .build_deps = deps_build, .build = build, .install = install_all, + .clean = clean, .run = run, .destroy = destroy, }; diff --git a/src/main.c b/src/main.c index 2031c92f..5720be2d 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ void usage(void) { "usage: %1$s [-j jobs] [-p install_prefix] [-D] [-O] [-C project_directory] [-o out_directory] build\n" " %1$s [-j jobs] [-p install_prefix] [-D] [-O] [-C project_directory] [-o out_directory] run [args ...]\n" " %1$s [-j jobs] [-p install_prefix] [-D] [-O] [-C project_directory] [-o out_directory] sh [args ...]\n" - " %1$s [-j jobs] [-p install_prefix] [-D] [-O] [-C project_directory] [-o out_directory] " "install\n", + " %1$s [-j jobs] [-p install_prefix] [-D] [-O] [-C project_directory] [-o out_directory] install\n" " %1$s [-j jobs] [-p install_prefix] [-D] [-O] [-C project_directory] [-o out_directory] clean\n", progname ); @@ -323,6 +323,12 @@ int main(int argc, char* argv[]) { } } + else if (strcmp(instr, "clean") == 0) { + if (bsys_clean(bsys) == 0) { + rv = EXIT_SUCCESS; + } + } + // This is intentionally undocumented, as it's really only used for communication between Bob parent processes and their Bob children processes. else if (strcmp(instr, "dep-tree") == 0) {