Add clean as an argument for cleaning build dir

This commit is contained in:
2026-08-25 19:00:05 +03:00
parent 8e4a0c9607
commit 7499dd1b2b
+31 -1
View File
@@ -92,12 +92,42 @@ bool check_kernel(Nob_Cmd *cmd) {
return true;
}
bool clean_build() {
bool clean_dir(const char *dir_path) {
Nob_File_Paths children = {0};
if (!nob_read_entire_dir(dir_path, &children))
return false;
bool ok = true;
for (size_t i = 0; i < children.count; ++i) {
const char *name = children.items[i];
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
continue;
const char *full_path = nob_temp_sprintf("%s/%s", dir_path, name);
if (!nob_delete_file(full_path)) {
nob_log(NOB_ERROR, "could not delete %s", full_path);
ok = false;
}
}
nob_da_free(children);
return ok;
}
int main(int argc, char **argv) {
NOB_GO_REBUILD_URSELF(argc, argv);
if (argc >= 2) {
if (strcmp(argv[1], "clean") == 0) {
if (!clean_dir(BUILD_FOLDER))
return 1;
} else {
nob_log(NOB_INFO, "Usage: %s (clean)", argv[0]);
return 1;
}
}
if (!nob_mkdir_if_not_exists(BUILD_FOLDER))
return 1;