setup-sdl: Add sdl-test input to build SDL_test

From 9eb868190c1900fb2d7569963a92b407e1ff3c0d Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 30 Jun 2023 21:09:30 +0200
Subject: [PATCH] Add sdl-test input to build SDL_test

---
 .gitignore          |  1 -
 action.yml          |  3 +++
 packed/index.js     | 18 +++++++++++++----
 src/main.ts         | 14 ++++++++++---
 src/version.test.ts | 49 ++++++++++++++++++++++-----------------------
 src/version.ts      | 30 ++++++++++++++++-----------
 6 files changed, 70 insertions(+), 45 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0e3574f..6df0f10 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,4 @@
 start/build
 node_modules
 dist
-packed
 build
diff --git a/action.yml b/action.yml
index f25653f..96e3355 100644
--- a/action.yml
+++ b/action.yml
@@ -13,6 +13,9 @@ inputs:
     description: "CMake build type (Release/Debug/RelWithDebInfo/MinSizeRel)"
     default: "Release"
     required: true
+  sdl-test:
+    description: "Build and install SDL_test library"
+    default: "false"
   cmake-toolchain-file:
     description: "Path of a CMake toolchain file"
   ninja:
diff --git a/packed/index.js b/packed/index.js
index 80cab11..7879447 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -280,6 +280,7 @@ function calculate_state_hash(args) {
         "cmake-toolchain-file",
         "discriminator",
         "ninja",
+        "sdl-test",
     ];
     var inputs_state = [];
     for (var _a = 0, ACTION_KEYS_1 = ACTION_KEYS; _a < ACTION_KEYS_1.length; _a++) {
@@ -347,7 +348,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, github_releases, release_db, 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, pkg_config_path, sdl2_config;
+        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, github_releases, release_db, sdl_release, GIT_HASH, CMAKE_TOOLCHAIN_FILE, STATE_HASH, PACKAGE_DIR, CACHE_KEY, CACHE_PATHS, sdl_from_cache, BUILD_SDL_TEST, SOURCE_DIR, BUILD_DIR, USE_NINJA, cmake_configure_args, SDL_VERSION, pkg_config_path, sdl2_config;
         var _this = this;
         return __generator(this, function (_a) {
             switch (_a.label) {
@@ -434,6 +435,7 @@ function run() {
                 case 2:
                     sdl_from_cache = _a.sent();
                     if (!!sdl_from_cache) return [3 /*break*/, 8];
+                    BUILD_SDL_TEST = core.getBooleanInput("sdl-test");
                     SOURCE_DIR = "".concat(SETUP_SDL_ROOT, "/").concat(STATE_HASH, "/source");
                     BUILD_DIR = "".concat(SETUP_SDL_ROOT, "/").concat(STATE_HASH, "/build");
                     return [4 /*yield*/, checkout_sdl_git_hash(GIT_HASH, SOURCE_DIR)];
@@ -456,6 +458,7 @@ function run() {
                     _a.label = 5;
                 case 5:
                     cmake_configure_args = [
+                        "-DSDL_TEST=".concat(BUILD_SDL_TEST),
                         "-DCMAKE_BUILD_TYPE=".concat(CMAKE_BUILD_TYPE),
                         "-DCMAKE_INSTALL_BINDIR=bin",
                         "-DCMAKE_INSTALL_INCLUDEDIR=include",
@@ -508,11 +511,15 @@ function run() {
                     else {
                         pkg_config_path = "";
                     }
-                    pkg_config_path += path.join(PACKAGE_DIR, "lib", "pkgconfig").replace("\\", "/");
+                    pkg_config_path += path
+                        .join(PACKAGE_DIR, "lib", "pkgconfig")
+                        .replace("\\", "/");
                     core.exportVariable("PKG_CONFIG_PATH", pkg_config_path);
                     // Set SDL2_CONFIG environment variable
                     if (SDL_VERSION.major == 2) {
-                        sdl2_config = path.join(PACKAGE_DIR, "bin", "sdl2-config").replace("\\", "/");
+                        sdl2_config = path
+                            .join(PACKAGE_DIR, "bin", "sdl2-config")
+                            .replace("\\", "/");
                         core.exportVariable("SDL2_CONFIG", sdl2_config);
                     }
                     core.exportVariable("SDL".concat(SDL_VERSION.major, "_ROOT"), PACKAGE_DIR);
@@ -839,7 +846,10 @@ var GitHubRelease = /** @class */ (function () {
         return GitHubRelease.from_gh_output(buffer.toString());
     };
     GitHubRelease.from_gh_output = function (text) {
-        return text.trim().split("\n").map(function (line_str) {
+        return text
+            .trim()
+            .split("\n")
+            .map(function (line_str) {
             var line_parts = line_str.split("\t");
             return new GitHubRelease(line_parts[0], line_parts[1].toLowerCase() == "pre-release", line_parts[2], Date.parse(line_parts[3]));
         });
diff --git a/src/main.ts b/src/main.ts
index 55fe088..2dec775 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -177,6 +177,7 @@ function calculate_state_hash(args: {
     "cmake-toolchain-file",
     "discriminator",
     "ninja",
+    "sdl-test",
   ];
   const inputs_state: string[] = [];
   for (const key of ACTION_KEYS) {
@@ -362,6 +363,8 @@ async function run() {
   );
 
   if (!sdl_from_cache) {
+    const BUILD_SDL_TEST = core.getBooleanInput("sdl-test");
+
     const SOURCE_DIR = `${SETUP_SDL_ROOT}/${STATE_HASH}/source`;
     const BUILD_DIR = `${SETUP_SDL_ROOT}/${STATE_HASH}/build`;
 
@@ -375,6 +378,7 @@ async function run() {
     }
 
     const cmake_configure_args = [
+      `-DSDL_TEST=${BUILD_SDL_TEST}`,
       `-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}`,
       "-DCMAKE_INSTALL_BINDIR=bin",
       "-DCMAKE_INSTALL_INCLUDEDIR=include",
@@ -419,14 +423,18 @@ async function run() {
   if (pkg_config_path) {
     pkg_config_path += path.delimiter;
   } else {
-    pkg_config_path = ""
+    pkg_config_path = "";
   }
-  pkg_config_path += path.join(PACKAGE_DIR, "lib", "pkgconfig").replace("\\", "/");
+  pkg_config_path += path
+    .join(PACKAGE_DIR, "lib", "pkgconfig")
+    .replace("\\", "/");
   core.exportVariable("PKG_CONFIG_PATH", pkg_config_path);
 
   // Set SDL2_CONFIG environment variable
   if (SDL_VERSION.major == 2) {
-    const sdl2_config = path.join(PACKAGE_DIR, "bin", "sdl2-config").replace("\\", "/");
+    const sdl2_config = path
+      .join(PACKAGE_DIR, "bin", "sdl2-config")
+      .replace("\\", "/");
     core.exportVariable(`SDL2_CONFIG`, sdl2_config);
   }
 
diff --git a/src/version.test.ts b/src/version.test.ts
index a2e677e..a58b308 100644
--- a/src/version.test.ts
+++ b/src/version.test.ts
@@ -9,31 +9,30 @@ import {
 
 import { describe, expect, test } from "@jest/globals";
 
-const GH_RELEASE_OUTPUT = ""
-  + "3.1.1\tLatest\tprerelease-3.1.1\t2023-12-25T18:45:17Z\n"
-  + "2.28.0\tLatest\trelease-2.28.0\t2023-06-20T18:45:17Z\n"
-  + "2.28.0 RC1\tPre-release\tprerelease-2.27.1\t2023-06-14T03:59:14Z\n"
-  + "2.26.5\t\trelease-2.26.5\t2023-04-05T19:35:40Z\n"
-  + "2.26.4\t\trelease-2.26.4\t2023-03-07T00:17:02Z\n"
-  + "2.26.3\t\trelease-2.26.3\t2023-02-06T23:31:56Z\n"
-  + "2.26.2\t\trelease-2.26.2\t2023-01-03T15:08:11Z\n"
-  + "2.26.1\t\trelease-2.26.1\t2022-12-01T20:33:11Z\n"
-  + "2.26.0\t\trelease-2.26.0\t2022-11-22T00:28:26Z\n"
-  + "2.26.0 RC1\tPre-release\tprerelease-2.25.1\t2022-11-17T17:49:02Z\n"
-  + "2.24.2\t\trelease-2.24.2\t2022-11-01T13:39:15Z\n"
-  + "2.24.1\t\trelease-2.24.1\t2022-10-05T00:16:33Z\n"
-  + "2.24.0\t\trelease-2.24.0\t2022-08-19T16:04:03Z\n"
-  + "2.0.22\t\trelease-2.0.22\t2022-04-25T19:20:25Z\n"
-  + "2.0.20\t\trelease-2.0.20\t2022-01-11T01:03:58Z\n"
-  + "2.0.18\t\trelease-2.0.18\t2021-11-30T17:15:42Z\n"
-  + "2.0.16\t\trelease-2.0.16\t2021-08-10T16:03:15Z\n"
-  + "2.0.14\t\trelease-2.0.14\t2021-07-08T17:14:16Z\n"
-  + "2.0.12\t\trelease-2.0.12\t2022-05-24T22:37:24Z\n"
-  + "2.0.10\t\trelease-2.0.10\t2022-05-24T22:35:08Z\n"
-  + "2.0.9\t\trelease-2.0.9\t2022-05-24T22:33:03Z\n"
-  + "2.0.8\t\trelease-2.0.8\t2022-05-23T22:20:21Z\n"
-;
-
+const GH_RELEASE_OUTPUT =
+  "" +
+  "3.1.1\tLatest\tprerelease-3.1.1\t2023-12-25T18:45:17Z\n" +
+  "2.28.0\tLatest\trelease-2.28.0\t2023-06-20T18:45:17Z\n" +
+  "2.28.0 RC1\tPre-release\tprerelease-2.27.1\t2023-06-14T03:59:14Z\n" +
+  "2.26.5\t\trelease-2.26.5\t2023-04-05T19:35:40Z\n" +
+  "2.26.4\t\trelease-2.26.4\t2023-03-07T00:17:02Z\n" +
+  "2.26.3\t\trelease-2.26.3\t2023-02-06T23:31:56Z\n" +
+  "2.26.2\t\trelease-2.26.2\t2023-01-03T15:08:11Z\n" +
+  "2.26.1\t\trelease-2.26.1\t2022-12-01T20:33:11Z\n" +
+  "2.26.0\t\trelease-2.26.0\t2022-11-22T00:28:26Z\n" +
+  "2.26.0 RC1\tPre-release\tprerelease-2.25.1\t2022-11-17T17:49:02Z\n" +
+  "2.24.2\t\trelease-2.24.2\t2022-11-01T13:39:15Z\n" +
+  "2.24.1\t\trelease-2.24.1\t2022-10-05T00:16:33Z\n" +
+  "2.24.0\t\trelease-2.24.0\t2022-08-19T16:04:03Z\n" +
+  "2.0.22\t\trelease-2.0.22\t2022-04-25T19:20:25Z\n" +
+  "2.0.20\t\trelease-2.0.20\t2022-01-11T01:03:58Z\n" +
+  "2.0.18\t\trelease-2.0.18\t2021-11-30T17:15:42Z\n" +
+  "2.0.16\t\trelease-2.0.16\t2021-08-10T16:03:15Z\n" +
+  "2.0.14\t\trelease-2.0.14\t2021-07-08T17:14:16Z\n" +
+  "2.0.12\t\trelease-2.0.12\t2022-05-24T22:37:24Z\n" +
+  "2.0.10\t\trelease-2.0.10\t2022-05-24T22:35:08Z\n" +
+  "2.0.9\t\trelease-2.0.9\t2022-05-24T22:33:03Z\n" +
+  "2.0.8\t\trelease-2.0.8\t2022-05-23T22:20:21Z\n";
 describe("testing parsing of version string", () => {
   function add_parse_to_version_test(
     input: string,
diff --git a/src/version.ts b/src/version.ts
index eb64351..aaa1282 100644
--- a/src/version.ts
+++ b/src/version.ts
@@ -21,15 +21,18 @@ export class GitHubRelease {
   }
 
   static from_gh_output(text: string): GitHubRelease[] {
-    return text.trim().split("\n").map(line_str => {
-      const line_parts = line_str.split("\t");
-      return new GitHubRelease(
-        line_parts[0],
-        line_parts[1].toLowerCase() == "pre-release",
-        line_parts[2],
-        Date.parse(line_parts[3]),
-      );
-    });
+    return text
+      .trim()
+      .split("\n")
+      .map((line_str) => {
+        const line_parts = line_str.split("\t");
+        return new GitHubRelease(
+          line_parts[0],
+          line_parts[1].toLowerCase() == "pre-release",
+          line_parts[2],
+          Date.parse(line_parts[3])
+        );
+      });
   }
 }
 
@@ -225,9 +228,8 @@ export class SdlReleaseDb {
   }
 
   static create(github_releases: GitHubRelease[]): SdlReleaseDb {
-
     const R = new RegExp("(release-|prerelease-)?([0-9.]+)(-RC([0-9]+))?");
-    const releases = github_releases.map(gh_release => {
+    const releases = github_releases.map((gh_release) => {
       const m = gh_release.tag.match(R);
       if (m == null) {
         throw new SetupSdlError(`Invalid tag: ${gh_release.tag}`);
@@ -239,7 +241,11 @@ export class SdlReleaseDb {
         prerelease = Number(m[4]) + 1;
       }
       const version = m[2];
-      return new SdlRelease(new SdlVersion(version), prerelease, gh_release.tag);
+      return new SdlRelease(
+        new SdlVersion(version),
+        prerelease,
+        gh_release.tag
+      );
     });
     releases.sort((release1, release2) => {
       return release1.compare(release2);