Skip to content

Commit

Permalink
clean: Add clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Dec 23, 2024
1 parent 3d263bd commit 754e7ba
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/bsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions src/bsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
15 changes: 15 additions & 0 deletions src/bsys/bob/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -367,6 +381,7 @@ bsys_t const BSYS_BOB = {
.build_deps = deps_build,
.build = build,
.install = install_all,
.clean = clean,
.run = run,
.destroy = destroy,
};
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 754e7ba

Please sign in to comment.