Browse Source

nob_linux: use new command API in stage2

rexim 1 month ago
parent
commit
ba220f2afb
2 changed files with 59 additions and 58 deletions
  1. 57 57
      src_build/nob_linux.c
  2. 2 1
      src_build/nob_stage2.c

+ 57 - 57
src_build/nob_linux.c

@@ -3,140 +3,140 @@
 bool build_musializer(void)
 {
     bool result = true;
-    Nob_Cmd cmd = {0};
-    Nob_Procs procs = {0};
+    Cmd cmd = {0};
+    Procs procs = {0};
 
 #ifdef MUSIALIZER_HOTRELOAD
     // TODO: add a way to replace `cc` with something else GCC compatible on POSIX
     // Like `clang` for instance
-    nob_cmd_append(&cmd, "cc",
+    cmd_append(&cmd, "cc",
         "-Wall", "-Wextra", "-ggdb",
         "-I.", "-I"RAYLIB_SRC_FOLDER,
         "-fPIC", "-shared",
         "-o", "./build/libplug.so",
         "./src/plug.c", "./src/ffmpeg_posix.c", "./thirdparty/tinyfiledialogs.c",
-        nob_temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.so",
+        temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.so",
         "-O3", "-march=native", "-ffast-math",
         "-lm", "-ldl", "-flto=auto", "-lpthread");
-    nob_da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
+    if (!cmd_run(&cmd)) return_defer(false);
 
-    nob_cmd_append(&cmd, "cc",
+    cmd_append(&cmd, "cc",
         "-Wall", "-Wextra", "-ggdb",
         "-I.", "-I"RAYLIB_SRC_FOLDER,
         "-o", "./build/musializer",
         "./src/musializer.c", "./src/hotreload_posix.c",
         "-Wl,-rpath=./build/",
         "-Wl,-rpath=./",
-        nob_temp_sprintf("-Wl,-rpath=./build/raylib/%s", MUSIALIZER_TARGET_NAME),
+        temp_sprintf("-Wl,-rpath=./build/raylib/%s", MUSIALIZER_TARGET_NAME),
         // NOTE: just in case somebody wants to run musializer from within the ./build/ folder
-        nob_temp_sprintf("-Wl,-rpath=./raylib/%s", MUSIALIZER_TARGET_NAME),
-        nob_temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
+        temp_sprintf("-Wl,-rpath=./raylib/%s", MUSIALIZER_TARGET_NAME),
+        temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
         "-O3", "-march=native", "-ffast-math",
         "-l:libraylib.so", "-lm", "-ldl", "-flto=auto", "-lpthread");
-    nob_da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
+    if (!cmd_run(&cmd)) return_defer(false);
 
-    if (!nob_procs_wait_and_reset(&procs)) nob_return_defer(false);
+    if (!procs_flush(&procs)) return_defer(false);
 #else
-    nob_cmd_append(&cmd, "cc",
+    cmd_append(&cmd, "cc",
         "-Wall", "-Wextra", "-ggdb",
         "-I.",
         "-I"RAYLIB_SRC_FOLDER,
         "-o", "./build/musializer",
         "./src/plug.c", "./src/ffmpeg_posix.c", "./src/musializer.c", "./thirdparty/tinyfiledialogs.c",
-        nob_temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.a",
+        temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.a",
         "-O3", "-march=native", "-ffast-math",
         "-lm", "-ldl", "-flto=auto", "-lpthread");
-    if (!nob_cmd_run_sync_and_reset(&cmd)) nob_return_defer(false);
+    if (!cmd_run(&cmd)) return_defer(false);
 #endif // MUSIALIZER_HOTRELOAD
 
 defer:
-    nob_cmd_free(cmd);
-    nob_da_free(procs);
+    cmd_free(cmd);
+    da_free(procs);
     return result;
 }
 
 bool build_raylib(void)
 {
     bool result = true;
-    Nob_Cmd cmd = {0};
-    Nob_File_Paths object_files = {0};
+    Cmd cmd = {0};
+    File_Paths object_files = {0};
 
-    if (!nob_mkdir_if_not_exists("./build/raylib")) {
-        nob_return_defer(false);
+    if (!mkdir_if_not_exists("./build/raylib")) {
+        return_defer(false);
     }
 
-    Nob_Procs procs = {0};
+    Procs procs = {0};
 
-    const char *build_path = nob_temp_sprintf("./build/raylib/%s", MUSIALIZER_TARGET_NAME);
+    const char *build_path = temp_sprintf("./build/raylib/%s", MUSIALIZER_TARGET_NAME);
 
-    if (!nob_mkdir_if_not_exists(build_path)) {
-        nob_return_defer(false);
+    if (!mkdir_if_not_exists(build_path)) {
+        return_defer(false);
     }
 
-    for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) {
-        const char *input_path = nob_temp_sprintf(RAYLIB_SRC_FOLDER"%s.c", raylib_modules[i]);
-        const char *output_path = nob_temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
-        output_path = nob_temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
+    for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
+        const char *input_path = temp_sprintf(RAYLIB_SRC_FOLDER"%s.c", raylib_modules[i]);
+        const char *output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
+        output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
 
-        nob_da_append(&object_files, output_path);
+        da_append(&object_files, output_path);
 
-        if (nob_needs_rebuild(output_path, &input_path, 1)) {
-            nob_cmd_append(&cmd, "cc",
+        if (needs_rebuild(output_path, &input_path, 1)) {
+            cmd_append(&cmd, "cc",
                 "-ggdb", "-DPLATFORM_DESKTOP", "-D_GLFW_X11", "-fPIC", "-DSUPPORT_FILEFORMAT_FLAC=1",
                 "-I"RAYLIB_SRC_FOLDER"external/glfw/include",
                 "-c", input_path,
                 "-o", output_path);
-            nob_da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
+            if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
         }
     }
 
-    if (!nob_procs_wait_and_reset(&procs)) nob_return_defer(false);
+    if (!procs_flush(&procs)) return_defer(false);
 
 #ifndef MUSIALIZER_HOTRELOAD
-    const char *libraylib_path = nob_temp_sprintf("%s/libraylib.a", build_path);
+    const char *libraylib_path = temp_sprintf("%s/libraylib.a", build_path);
 
-    if (nob_needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
-        nob_cmd_append(&cmd, "ar", "-crs", libraylib_path);
-        for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) {
-            const char *input_path = nob_temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
-            nob_cmd_append(&cmd, input_path);
+    if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
+        cmd_append(&cmd, "ar", "-crs", libraylib_path);
+        for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
+            const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
+            cmd_append(&cmd, input_path);
         }
-        if (!nob_cmd_run_sync_and_reset(&cmd)) nob_return_defer(false);
+        if (!cmd_run(&cmd)) return_defer(false);
     }
 #else
-    const char *libraylib_path = nob_temp_sprintf("%s/libraylib.so", build_path);
+    const char *libraylib_path = temp_sprintf("%s/libraylib.so", build_path);
 
-    if (nob_needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
-        nob_cmd_append(&cmd, "cc", "-shared", "-o", libraylib_path);
-        for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) {
-            const char *input_path = nob_temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
-            nob_cmd_append(&cmd, input_path);
+    if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
+        cmd_append(&cmd, "cc", "-shared", "-o", libraylib_path);
+        for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
+            const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
+            cmd_append(&cmd, input_path);
         }
-        if (!nob_cmd_run_sync_and_reset(&cmd)) nob_return_defer(false);
+        if (!cmd_run(&cmd)) return_defer(false);
     }
 #endif // MUSIALIZER_HOTRELOAD
 
 defer:
-    nob_cmd_free(cmd);
-    nob_da_free(object_files);
+    cmd_free(cmd);
+    da_free(object_files);
     return result;
 }
 
 bool build_dist()
 {
 #ifdef MUSIALIZER_HOTRELOAD
-    nob_log(NOB_ERROR, "We do not ship with hotreload enabled");
+    nob_log(ERROR, "We do not ship with hotreload enabled");
     return false;
 #else
-    if (!nob_mkdir_if_not_exists("./musializer-linux-x86_64/")) return false;
-    if (!nob_copy_file("./build/musializer", "./musializer-linux-x86_64/musializer")) return false;
-    if (!nob_copy_directory_recursively("./resources/", "./musializer-linux-x86_64/resources/")) return false;
+    if (!mkdir_if_not_exists("./musializer-linux-x86_64/")) return false;
+    if (!copy_file("./build/musializer", "./musializer-linux-x86_64/musializer")) return false;
+    if (!copy_directory_recursively("./resources/", "./musializer-linux-x86_64/resources/")) return false;
     // TODO: should we pack ffmpeg with Linux build?
     // There are some static executables for Linux
-    Nob_Cmd cmd = {0};
-    nob_cmd_append(&cmd, "tar", "fvcz", "./musializer-linux-x86_64.tar.gz", "./musializer-linux-x86_64");
-    bool ok = nob_cmd_run_sync_and_reset(&cmd);
-    nob_cmd_free(cmd);
+    Cmd cmd = {0};
+    cmd_append(&cmd, "tar", "fvcz", "./musializer-linux-x86_64.tar.gz", "./musializer-linux-x86_64");
+    bool ok = cmd_run(&cmd);
+    cmd_free(cmd);
     if (!ok) return false;
 
     return true;

+ 2 - 1
src_build/nob_stage2.c

@@ -2,6 +2,7 @@
 
 #define NOB_IMPLEMENTATION
 #define NOB_STRIP_PREFIX
+// #define NOB_WARN_DEPRECATED
 #include "../thirdparty/nob.h"
 #include "../build/config.h"
 #include "./configurer.c"
@@ -188,7 +189,7 @@ int main(int argc, char **argv)
                     nob_cmd_append(&cmd, "-resize", nob_temp_sprintf("%d", svgs[i].resize));
                 }
                 nob_cmd_append(&cmd, svgs[i].out_path);
-                nob_da_append(&procs, nob_cmd_run_async(cmd));
+                if (!nob_cmd_run(&cmd, .async = &procs)) return 1;
             } else {
                 nob_log(NOB_INFO, "%s is up to date", svgs[i].out_path);
             }