setup-sdl: Add verbose option for verbose builds + trace cmake in debug mode

From 478fd1fbd6d266c59cc430d50cb57a16fed4d945 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 19 Jun 2023 20:26:46 +0200
Subject: [PATCH] Add verbose option for verbose builds + trace cmake in debug
 mode

---
 action.yml      |  3 +++
 packed/index.js | 52 +++++++++++++++++++++++++++++++++++++++----------
 src/main.ts     | 52 ++++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 88 insertions(+), 19 deletions(-)

diff --git a/action.yml b/action.yml
index baf1490..99e1a12 100644
--- a/action.yml
+++ b/action.yml
@@ -25,6 +25,9 @@ inputs:
   add-to-environment:
     description: "Add path of the SDL (shared) library to PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH"
     default: "false"
+  verbose:
+    description: "Do a verbose build"
+    default: "false"
 outputs:
   prefix:
     description: "Actual root of the SDL package"
diff --git a/packed/index.js b/packed/index.js
index 525e391..617f50d 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -223,17 +223,44 @@ function execute_child_process(command, shell) {
 }
 function cmake_configure_build(args) {
     return __awaiter(this, void 0, void 0, function () {
-        var cmake_args, configure_command, build_command, install_command;
+        var configure_args, build_args, install_args;
         var _this = this;
         return __generator(this, function (_a) {
             switch (_a.label) {
                 case 0:
-                    cmake_args = args.cmake_args.join(" ");
-                    configure_command = "cmake -S \"".concat(args.source_dir, "\" -B \"").concat(args.build_dir, "\" ").concat(cmake_args);
-                    build_command = "cmake --build \"".concat(args.build_dir, "\" --config ").concat(args.build_type);
-                    install_command = "cmake --install \"".concat(args.build_dir, "\" --prefix ").concat(args.package_dir, " --config ").concat(args.build_type);
+                    configure_args = __spreadArray([
+                        "cmake",
+                        "-S",
+                        args.source_dir,
+                        "-B",
+                        args.build_dir
+                    ], args.cmake_configure_args, true);
+                    if (core.isDebug()) {
+                        configure_args.push("--trace-expand");
+                    }
+                    build_args = [
+                        "cmake",
+                        "--build",
+                        args.build_dir,
+                        "--config",
+                        args.build_type,
+                    ];
+                    if (args.verbose) {
+                        build_args.push("--verbose");
+                    }
+                    install_args = [
+                        "cmake",
+                        "--install",
+                        args.build_dir,
+                        "--prefix",
+                        args.package_dir,
+                        "--config",
+                        args.build_type,
+                    ];
                     return [4 /*yield*/, core.group("Configuring SDL (CMake)", function () { return __awaiter(_this, void 0, void 0, function () {
+                            var configure_command;
                             return __generator(this, function (_a) {
+                                configure_command = configure_args.join(" ");
                                 execute_child_process(configure_command, args.shell);
                                 return [2 /*return*/];
                             });
@@ -241,7 +268,9 @@ function cmake_configure_build(args) {
                 case 1:
                     _a.sent();
                     return [4 /*yield*/, core.group("Building SDL (CMake)", function () { return __awaiter(_this, void 0, void 0, function () {
+                            var build_command;
                             return __generator(this, function (_a) {
+                                build_command = build_args.join(" ");
                                 execute_child_process(build_command, args.shell);
                                 return [2 /*return*/];
                             });
@@ -249,7 +278,9 @@ function cmake_configure_build(args) {
                 case 2:
                     _a.sent();
                     return [4 /*yield*/, core.group("Installing SDL (CMake)", function () { return __awaiter(_this, void 0, void 0, function () {
+                            var install_command;
                             return __generator(this, function (_a) {
+                                install_command = install_args.join(" ");
                                 execute_child_process(install_command, args.shell);
                                 return [2 /*return*/];
                             });
@@ -354,7 +385,7 @@ function get_cmake_toolchain_path() {
 }
 function run() {
     return __awaiter(this, void 0, void 0, function () {
-        var SDL_BUILD_PLATFORM, SETUP_SDL_ROOT, IGNORED_SHELLS, shell_in, SHELL, REQUESTED_VERSION_TYPE, CMAKE_BUILD_TYPE, CMAKE_BUILD_TYPES, git_branch_hash, requested_version, requested_type, sdl_release, GIT_HASH, CMAKE_TOOLCHAIN_FILE, STATE_HASH, PACKAGE_DIR, CACHE_KEY, CACHE_PATHS, sdl_from_cache, SOURCE_DIR, BUILD_DIR, USE_NINJA, cmake_args, SDL_VERSION;
+        var SDL_BUILD_PLATFORM, SETUP_SDL_ROOT, IGNORED_SHELLS, shell_in, SHELL, REQUESTED_VERSION_TYPE, CMAKE_BUILD_TYPE, CMAKE_BUILD_TYPES, git_branch_hash, requested_version, requested_type, sdl_release, GIT_HASH, CMAKE_TOOLCHAIN_FILE, STATE_HASH, PACKAGE_DIR, CACHE_KEY, CACHE_PATHS, sdl_from_cache, SOURCE_DIR, BUILD_DIR, USE_NINJA, cmake_configure_args, SDL_VERSION;
         var _this = this;
         return __generator(this, function (_a) {
             switch (_a.label) {
@@ -460,24 +491,25 @@ function run() {
                     _a.sent();
                     _a.label = 5;
                 case 5:
-                    cmake_args = [
+                    cmake_configure_args = [
                         "-DCMAKE_BUILD_TYPE=".concat(CMAKE_BUILD_TYPE),
                         "-DCMAKE_INSTALL_BINDIR=bin",
                         "-DCMAKE_INSTALL_INCLUDEDIR=include",
                         "-DCMAKE_INSTALL_LIBDIR=lib",
                     ];
                     if (CMAKE_TOOLCHAIN_FILE) {
-                        cmake_args.push("-DCMAKE_TOOLCHAIN_FILE=\"".concat(CMAKE_TOOLCHAIN_FILE, "\""));
+                        cmake_configure_args.push("-DCMAKE_TOOLCHAIN_FILE=\"".concat(CMAKE_TOOLCHAIN_FILE, "\""));
                     }
                     if (USE_NINJA) {
-                        cmake_args.push("-GNinja");
+                        cmake_configure_args.push("-GNinja");
                     }
                     return [4 /*yield*/, cmake_configure_build({
                             source_dir: SOURCE_DIR,
                             build_dir: BUILD_DIR,
                             package_dir: PACKAGE_DIR,
                             build_type: CMAKE_BUILD_TYPE,
-                            cmake_args: cmake_args,
+                            cmake_configure_args: cmake_configure_args,
+                            verbose: core.getBooleanInput("verbose"),
                             shell: SHELL,
                         })];
                 case 6:
diff --git a/src/main.ts b/src/main.ts
index 3c78183..a13349d 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -94,22 +94,53 @@ async function cmake_configure_build(args: {
   build_dir: string;
   package_dir: string;
   build_type: string;
-  cmake_args: string[];
+  cmake_configure_args: string[];
   shell: string;
+  verbose: boolean;
 }) {
-  const cmake_args = args.cmake_args.join(" ");
+  const configure_args = [
+    "cmake",
+    "-S",
+    args.source_dir,
+    "-B",
+    args.build_dir,
+    ...args.cmake_configure_args,
+  ];
+  if (core.isDebug()) {
+    configure_args.push("--trace-expand");
+  }
 
-  const configure_command = `cmake -S "${args.source_dir}" -B "${args.build_dir}" ${cmake_args}`;
-  const build_command = `cmake --build "${args.build_dir}" --config ${args.build_type}`;
-  const install_command = `cmake --install "${args.build_dir}" --prefix ${args.package_dir} --config ${args.build_type}`;
+  const build_args = [
+    "cmake",
+    "--build",
+    args.build_dir,
+    "--config",
+    args.build_type,
+  ];
+  if (args.verbose) {
+    build_args.push("--verbose");
+  }
+
+  const install_args = [
+    "cmake",
+    "--install",
+    args.build_dir,
+    "--prefix",
+    args.package_dir,
+    "--config",
+    args.build_type,
+  ];
 
   await core.group(`Configuring SDL (CMake)`, async () => {
+    const configure_command = configure_args.join(" ");
     execute_child_process(configure_command, args.shell);
   });
   await core.group(`Building SDL (CMake)`, async () => {
+    const build_command = build_args.join(" ");
     execute_child_process(build_command, args.shell);
   });
   await core.group(`Installing SDL (CMake)`, async () => {
+    const install_command = install_args.join(" ");
     execute_child_process(install_command, args.shell);
   });
 }
@@ -340,17 +371,19 @@ async function run() {
       });
     }
 
-    const cmake_args = [
+    const cmake_configure_args = [
       `-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}`,
       "-DCMAKE_INSTALL_BINDIR=bin",
       "-DCMAKE_INSTALL_INCLUDEDIR=include",
       "-DCMAKE_INSTALL_LIBDIR=lib",
     ];
     if (CMAKE_TOOLCHAIN_FILE) {
-      cmake_args.push(`-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}"`);
+      cmake_configure_args.push(
+        `-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}"`
+      );
     }
     if (USE_NINJA) {
-      cmake_args.push("-GNinja");
+      cmake_configure_args.push("-GNinja");
     }
 
     await cmake_configure_build({
@@ -358,7 +391,8 @@ async function run() {
       build_dir: BUILD_DIR,
       package_dir: PACKAGE_DIR,
       build_type: CMAKE_BUILD_TYPE,
-      cmake_args: cmake_args,
+      cmake_configure_args: cmake_configure_args,
+      verbose: core.getBooleanInput("verbose"),
       shell: SHELL,
     });