From 3e0073e483b25350c5239b862fdfab940a33301b Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 00:57:52 -0800 Subject: [PATCH 1/8] return after build wasm --- nob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nob.c b/nob.c index 8d0470c..3646cdc 100644 --- a/nob.c +++ b/nob.c @@ -207,6 +207,7 @@ int main(int argc, char **argv) const char *src_path = temp_sprintf("./build/demos/%s.wasm", name); const char *dst_path = temp_sprintf("./wasm/%s.wasm", name); if (!copy_file(src_path, dst_path)) return 1; + return 0; } else { usage(program); nob_log(ERROR, "unknown demo platform %s", platform); From 5ad15f7b3618efdacb82bc0f7e850f554b9debd3 Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 00:58:07 -0800 Subject: [PATCH 2/8] return after show help --- nob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nob.c b/nob.c index 3646cdc..c6ef3f0 100644 --- a/nob.c +++ b/nob.c @@ -215,6 +215,7 @@ int main(int argc, char **argv) } } else if(strcmp(subcmd, "help") == 0) { usage(program); + return 0; } else { usage(program); nob_log(ERROR, "Unknown command `%s`", subcmd); From 550e4b83191daf56b048e042515053b79bff78fd Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 01:01:46 -0800 Subject: [PATCH 3/8] return after run tests --- nob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nob.c b/nob.c index c6ef3f0..3295fb8 100644 --- a/nob.c +++ b/nob.c @@ -158,6 +158,7 @@ int main(int argc, char **argv) da_append_many(&cmd, argv, argc); if (!cmd_run_sync_and_reset(&cmd)) return 1; } + return 0; } else if (strcmp(subcmd, "demos") == 0) { if (argc <= 0) { if (!build_all_vc_demos(&cmd, &procs)) return 1; From 92268d83b7c6b205292ab6045e61ccbcb6060804 Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 01:02:19 -0800 Subject: [PATCH 4/8] return after demos --- nob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nob.c b/nob.c index 3295fb8..dac6667 100644 --- a/nob.c +++ b/nob.c @@ -214,6 +214,7 @@ int main(int argc, char **argv) nob_log(ERROR, "unknown demo platform %s", platform); return 1; } + return 0; } else if(strcmp(subcmd, "help") == 0) { usage(program); return 0; From 10fc8749788435cf5b0238cfe685d85c0a6d5d7f Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 01:04:45 -0800 Subject: [PATCH 5/8] return after tools --- nob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nob.c b/nob.c index dac6667..a8ec6b0 100644 --- a/nob.c +++ b/nob.c @@ -149,6 +149,7 @@ int main(int argc, char **argv) const char *subcmd = shift_args(&argc, &argv); if (strcmp(subcmd, "tools") == 0) { if (!build_tools(&cmd)) return 1; + return 0; } else if (strcmp(subcmd, "assets") == 0) { if (!build_assets(&cmd)) return 1; } else if (strcmp(subcmd, "tests") == 0 || strcmp(subcmd, "test") == 0) { From 05f336878a84bf5e33bb03234babfb691c9065a7 Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 01:04:59 -0800 Subject: [PATCH 6/8] return after assets --- nob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nob.c b/nob.c index a8ec6b0..b1e649d 100644 --- a/nob.c +++ b/nob.c @@ -152,6 +152,7 @@ int main(int argc, char **argv) return 0; } else if (strcmp(subcmd, "assets") == 0) { if (!build_assets(&cmd)) return 1; + return 0; } else if (strcmp(subcmd, "tests") == 0 || strcmp(subcmd, "test") == 0) { if (!build_tests(&cmd)) return 1; if (argc > 0) { From 12d440f25831954c78b6b7336ec10ff9030cc002 Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 01:12:14 -0800 Subject: [PATCH 7/8] build all first --- nob.c | 143 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/nob.c b/nob.c index b1e649d..bdf7eaa 100644 --- a/nob.c +++ b/nob.c @@ -145,91 +145,92 @@ int main(int argc, char **argv) const char *program = shift_args(&argc, &argv); - if (argc > 0) { - const char *subcmd = shift_args(&argc, &argv); - if (strcmp(subcmd, "tools") == 0) { - if (!build_tools(&cmd)) return 1; - return 0; - } else if (strcmp(subcmd, "assets") == 0) { - if (!build_assets(&cmd)) return 1; + if (argc <= 0) { + if (!build_tools(&cmd)) return 1; + if (!build_assets(&cmd)) return 1; + if (!build_tests(&cmd)) return 1; + if (!build_all_vc_demos(&cmd, &procs)) return 1; + return 0; + } + + const char *subcmd = shift_args(&argc, &argv); + if (strcmp(subcmd, "tools") == 0) { + if (!build_tools(&cmd)) return 1; + return 0; + } else if (strcmp(subcmd, "assets") == 0) { + if (!build_assets(&cmd)) return 1; + return 0; + } else if (strcmp(subcmd, "tests") == 0 || strcmp(subcmd, "test") == 0) { + if (!build_tests(&cmd)) return 1; + if (argc > 0) { + cmd_append(&cmd, "./build/test"); + da_append_many(&cmd, argv, argc); + if (!cmd_run_sync_and_reset(&cmd)) return 1; + } + return 0; + } else if (strcmp(subcmd, "demos") == 0) { + if (argc <= 0) { + if (!build_all_vc_demos(&cmd, &procs)) return 1; return 0; - } else if (strcmp(subcmd, "tests") == 0 || strcmp(subcmd, "test") == 0) { - if (!build_tests(&cmd)) return 1; - if (argc > 0) { - cmd_append(&cmd, "./build/test"); - da_append_many(&cmd, argv, argc); - if (!cmd_run_sync_and_reset(&cmd)) return 1; - } + } + + const char *name = shift(argv, argc); + if (argc <= 0) { + build_vc_demo(&cmd, &procs, name); + if (!procs_wait_and_reset(&procs)) return 1; + const char *src_path = temp_sprintf("./build/demos/%s.wasm", name); + const char *dst_path = temp_sprintf("./wasm/%s.wasm", name); + if (!copy_file(src_path, dst_path)) return 1; return 0; - } else if (strcmp(subcmd, "demos") == 0) { - if (argc <= 0) { - if (!build_all_vc_demos(&cmd, &procs)) return 1; - return 0; - } + } - const char *name = shift(argv, argc); - if (argc <= 0) { - build_vc_demo(&cmd, &procs, name); - if (!procs_wait_and_reset(&procs)) return 1; - const char *src_path = temp_sprintf("./build/demos/%s.wasm", name); - const char *dst_path = temp_sprintf("./wasm/%s.wasm", name); - if (!copy_file(src_path, dst_path)) return 1; - return 0; + const char *platform = shift(argv, argc); + if (strcmp(platform, "sdl") == 0) { + build_sdl_demo(&cmd, &procs, name); + if (!procs_wait_and_reset(&procs)) return 1; + if (argc <= 0) return 0; + const char *run = shift(argv, argc); + if (strcmp(run, "run") != 0) { + usage(program); + nob_log(ERROR, "unknown action `%s` for SDL demo: %s", run, name); + return 1; } - - const char *platform = shift(argv, argc); - if (strcmp(platform, "sdl") == 0) { - build_sdl_demo(&cmd, &procs, name); - if (!procs_wait_and_reset(&procs)) return 1; - if (argc <= 0) return 0; - const char *run = shift(argv, argc); - if (strcmp(run, "run") != 0) { - usage(program); - nob_log(ERROR, "unknown action `%s` for SDL demo: %s", run, name); - return 1; - } - cmd_append(&cmd, temp_sprintf("./build/demos/%s.sdl", name)); - if (!cmd_run_sync_and_reset(&cmd)) return 1; - return 0; - } else if (strcmp(platform, "term") == 0) { - build_term_demo(&cmd, &procs, name); - if (!procs_wait_and_reset(&procs)) return 1; - if (argc <= 0) return 0; - const char *run = shift(argv, argc); - if (strcmp(run, "run") != 0) { - usage(program); - nob_log(ERROR, "unknown action `%s` for Terminal demo: %s", run, name); - return 1; - } - cmd_append(&cmd, temp_sprintf("./build/demos/%s.term", name)); - if (!cmd_run_sync_and_reset(&cmd)) return 1; - return 0; - } else if (strcmp(platform, "wasm") == 0) { - build_wasm_demo(&cmd, &procs, name); - if (!procs_wait_and_reset(&procs)) return 1; - const char *src_path = temp_sprintf("./build/demos/%s.wasm", name); - const char *dst_path = temp_sprintf("./wasm/%s.wasm", name); - if (!copy_file(src_path, dst_path)) return 1; - return 0; - } else { + cmd_append(&cmd, temp_sprintf("./build/demos/%s.sdl", name)); + if (!cmd_run_sync_and_reset(&cmd)) return 1; + return 0; + } else if (strcmp(platform, "term") == 0) { + build_term_demo(&cmd, &procs, name); + if (!procs_wait_and_reset(&procs)) return 1; + if (argc <= 0) return 0; + const char *run = shift(argv, argc); + if (strcmp(run, "run") != 0) { usage(program); - nob_log(ERROR, "unknown demo platform %s", platform); + nob_log(ERROR, "unknown action `%s` for Terminal demo: %s", run, name); return 1; } + cmd_append(&cmd, temp_sprintf("./build/demos/%s.term", name)); + if (!cmd_run_sync_and_reset(&cmd)) return 1; return 0; - } else if(strcmp(subcmd, "help") == 0) { - usage(program); + } else if (strcmp(platform, "wasm") == 0) { + build_wasm_demo(&cmd, &procs, name); + if (!procs_wait_and_reset(&procs)) return 1; + const char *src_path = temp_sprintf("./build/demos/%s.wasm", name); + const char *dst_path = temp_sprintf("./wasm/%s.wasm", name); + if (!copy_file(src_path, dst_path)) return 1; return 0; } else { usage(program); - nob_log(ERROR, "Unknown command `%s`", subcmd); + nob_log(ERROR, "unknown demo platform %s", platform); return 1; } + return 0; + } else if (strcmp(subcmd, "help") == 0) { + usage(program); + return 0; } else { - if (!build_tools(&cmd)) return 1; - if (!build_assets(&cmd)) return 1; - if (!build_tests(&cmd)) return 1; - if (!build_all_vc_demos(&cmd, &procs)) return 1; + usage(program); + nob_log(ERROR, "Unknown command `%s`", subcmd); + return 1; } return 0; From 548c87ff54bdd2960a3988f121d020473208c52d Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Wed, 5 Mar 2025 01:13:03 -0800 Subject: [PATCH 8/8] removed else if, early return --- nob.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/nob.c b/nob.c index bdf7eaa..852ea74 100644 --- a/nob.c +++ b/nob.c @@ -157,10 +157,12 @@ int main(int argc, char **argv) if (strcmp(subcmd, "tools") == 0) { if (!build_tools(&cmd)) return 1; return 0; - } else if (strcmp(subcmd, "assets") == 0) { + } + if (strcmp(subcmd, "assets") == 0) { if (!build_assets(&cmd)) return 1; return 0; - } else if (strcmp(subcmd, "tests") == 0 || strcmp(subcmd, "test") == 0) { + } + if (strcmp(subcmd, "tests") == 0 || strcmp(subcmd, "test") == 0) { if (!build_tests(&cmd)) return 1; if (argc > 0) { cmd_append(&cmd, "./build/test"); @@ -168,7 +170,8 @@ int main(int argc, char **argv) if (!cmd_run_sync_and_reset(&cmd)) return 1; } return 0; - } else if (strcmp(subcmd, "demos") == 0) { + } + if (strcmp(subcmd, "demos") == 0) { if (argc <= 0) { if (!build_all_vc_demos(&cmd, &procs)) return 1; return 0; @@ -198,7 +201,8 @@ int main(int argc, char **argv) cmd_append(&cmd, temp_sprintf("./build/demos/%s.sdl", name)); if (!cmd_run_sync_and_reset(&cmd)) return 1; return 0; - } else if (strcmp(platform, "term") == 0) { + } + if (strcmp(platform, "term") == 0) { build_term_demo(&cmd, &procs, name); if (!procs_wait_and_reset(&procs)) return 1; if (argc <= 0) return 0; @@ -211,27 +215,25 @@ int main(int argc, char **argv) cmd_append(&cmd, temp_sprintf("./build/demos/%s.term", name)); if (!cmd_run_sync_and_reset(&cmd)) return 1; return 0; - } else if (strcmp(platform, "wasm") == 0) { + } + if (strcmp(platform, "wasm") == 0) { build_wasm_demo(&cmd, &procs, name); if (!procs_wait_and_reset(&procs)) return 1; const char *src_path = temp_sprintf("./build/demos/%s.wasm", name); const char *dst_path = temp_sprintf("./wasm/%s.wasm", name); if (!copy_file(src_path, dst_path)) return 1; return 0; - } else { - usage(program); - nob_log(ERROR, "unknown demo platform %s", platform); - return 1; } - return 0; - } else if (strcmp(subcmd, "help") == 0) { usage(program); - return 0; - } else { - usage(program); - nob_log(ERROR, "Unknown command `%s`", subcmd); + nob_log(ERROR, "unknown demo platform %s", platform); return 1; } + if (strcmp(subcmd, "help") == 0) { + usage(program); + return 0; + } - return 0; + usage(program); + nob_log(ERROR, "Unknown command `%s`", subcmd); + return 1; }