From 91635a58d4c5dac80e6b408b340c5ef5e888933c Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 17 Jun 2023 03:59:20 +0200
Subject: [PATCH] add build-type input
---
action.yml | 4 ++++
packed/index.js | 26 ++++++++++++++++++--------
src/main.ts | 34 ++++++++++++++++++++++++++--------
3 files changed, 48 insertions(+), 16 deletions(-)
diff --git a/action.yml b/action.yml
index 676c7aae7b2f..8d36234c2f88 100644
--- a/action.yml
+++ b/action.yml
@@ -9,6 +9,10 @@ inputs:
description: "Allow pre-releases"
default: "true"
required: true
+ build-type:
+ description: "CMake build type (Release/Debug/RelWithDebInfo/MinSizeRel)"
+ default: "Release"
+ required: true
outputs:
prefix:
description: "Actual root of the SDL package"
diff --git a/packed/index.js b/packed/index.js
index 8b95cb83fd18..d5062eb31a5c 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -114,13 +114,13 @@ async function checkout_sdl_git_hash(branch_tag_hash, directory) {
await echo_command_and_execute(`git checkout FETCH_HEAD`, directory);
});
}
-async function cmake_configure_build(source_dir, build_dir, prefix_dir, cmake_args) {
+async function cmake_configure_build(source_dir, build_dir, prefix_dir, build_type, cmake_args) {
if (!cmake_args) {
cmake_args = "";
}
const configure_command = `cmake -S "${source_dir}" -B ${build_dir} ${cmake_args}`;
- const build_command = `cmake --build "${build_dir}"`;
- const install_command = `cmake --install "${build_dir}" --prefix ${prefix_dir}`;
+ const build_command = `cmake --build "${build_dir}" --config ${build_type}`;
+ const install_command = `cmake --install "${build_dir}" --prefix ${prefix_dir} --config ${build_type}`;
await core.group(`Configuring SDL (CMake)`, async () => {
core.info(configure_command);
child_process.execSync(configure_command, { stdio: "inherit" });
@@ -139,13 +139,23 @@ async function run() {
core.info(`build platform=${SDL_BUILD_PLATFORM}`);
const SETUP_SDL_ROOT = get_platform_root_directory(SDL_BUILD_PLATFORM);
core.info(`root=${SETUP_SDL_ROOT}`);
- const requested_version_type = (0, version_1.parse_requested_sdl_version)(core.getInput("version"));
+ const REQUESTED_VERSION_TYPE = (0, version_1.parse_requested_sdl_version)(core.getInput("version"));
+ const CMAKE_BUILD_TYPE = core.getInput("build-type");
+ const CMAKE_BUILD_TYPES = [
+ "Release",
+ "Debug",
+ "MinSizeRel",
+ "RelWithDebInfo",
+ ];
+ if (!CMAKE_BUILD_TYPES.includes(CMAKE_BUILD_TYPE)) {
+ throw new error_1.SetupSdlError("Invalid build-type");
+ }
let git_branch_hash;
- if (requested_version_type == null) {
+ if (REQUESTED_VERSION_TYPE == null) {
git_branch_hash = core.getInput("version");
}
else {
- const { version: requested_version, type: requested_type } = requested_version_type;
+ const { version: requested_version, type: requested_type } = REQUESTED_VERSION_TYPE;
if (requested_type == version_1.SdlReleaseType.Head) {
if (requested_version.major == 2) {
git_branch_hash = "SDL2";
@@ -169,9 +179,9 @@ async function run() {
const source_dir = `${SETUP_SDL_ROOT}/src`;
const build_dir = `${SETUP_SDL_ROOT}/build`;
const install_dir = `${SETUP_SDL_ROOT}`;
- const cmake_args = undefined;
+ const cmake_args = `-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}`;
await checkout_sdl_git_hash(git_hash, source_dir);
- await cmake_configure_build(source_dir, build_dir, install_dir, cmake_args);
+ await cmake_configure_build(source_dir, build_dir, install_dir, CMAKE_BUILD_TYPE, cmake_args);
core.setOutput("prefix", install_dir);
}
run();
diff --git a/src/main.ts b/src/main.ts
index cdf10542e172..506625b2a58a 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -100,15 +100,16 @@ async function cmake_configure_build(
source_dir: string,
build_dir: string,
prefix_dir: string,
- cmake_args: string | undefined
+ build_type: string,
+ cmake_args: string
) {
if (!cmake_args) {
cmake_args = "";
}
const configure_command = `cmake -S "${source_dir}" -B ${build_dir} ${cmake_args}`;
- const build_command = `cmake --build "${build_dir}"`;
- const install_command = `cmake --install "${build_dir}" --prefix ${prefix_dir}`;
+ const build_command = `cmake --build "${build_dir}" --config ${build_type}`;
+ const install_command = `cmake --install "${build_dir}" --prefix ${prefix_dir} --config ${build_type}`;
await core.group(`Configuring SDL (CMake)`, async () => {
core.info(configure_command);
@@ -131,16 +132,27 @@ async function run() {
const SETUP_SDL_ROOT = get_platform_root_directory(SDL_BUILD_PLATFORM);
core.info(`root=${SETUP_SDL_ROOT}`);
- const requested_version_type = parse_requested_sdl_version(
+ const REQUESTED_VERSION_TYPE = parse_requested_sdl_version(
core.getInput("version")
);
+ const CMAKE_BUILD_TYPE = core.getInput("build-type");
+ const CMAKE_BUILD_TYPES = [
+ "Release",
+ "Debug",
+ "MinSizeRel",
+ "RelWithDebInfo",
+ ];
+ if (!CMAKE_BUILD_TYPES.includes(CMAKE_BUILD_TYPE)) {
+ throw new SetupSdlError("Invalid build-type");
+ }
+
let git_branch_hash: string;
- if (requested_version_type == null) {
+ if (REQUESTED_VERSION_TYPE == null) {
git_branch_hash = core.getInput("version");
} else {
const { version: requested_version, type: requested_type } =
- requested_version_type;
+ REQUESTED_VERSION_TYPE;
if (requested_type == SdlReleaseType.Head) {
if (requested_version.major == 2) {
@@ -172,11 +184,17 @@ async function run() {
const source_dir = `${SETUP_SDL_ROOT}/src`;
const build_dir = `${SETUP_SDL_ROOT}/build`;
const install_dir = `${SETUP_SDL_ROOT}`;
- const cmake_args = undefined;
+ const cmake_args = `-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}`;
await checkout_sdl_git_hash(git_hash, source_dir);
- await cmake_configure_build(source_dir, build_dir, install_dir, cmake_args);
+ await cmake_configure_build(
+ source_dir,
+ build_dir,
+ install_dir,
+ CMAKE_BUILD_TYPE,
+ cmake_args
+ );
core.setOutput("prefix", install_dir);
}