From 9d1aa32e43fc57dd35e192a16f13acd4e9c0dbd2 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 17 Jun 2023 23:07:59 +0200
Subject: [PATCH] Export SDLx_ROOT environment variable
---
packed/index.js | 18 +++++++++++++-----
src/main.ts | 24 ++++++++++++++++--------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/packed/index.js b/packed/index.js
index af92f09..769c680 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -136,6 +136,17 @@ async function cmake_configure_build(source_dir, build_dir, prefix_dir, build_ty
child_process.execSync(install_command, { stdio: "inherit" });
});
}
+function detect_sdl_major_version(prefix) {
+ const sdl3_dir = `${prefix}/include/SDL3`;
+ if (fs.existsSync(sdl3_dir)) {
+ return 3;
+ }
+ const sdl2_dir = `${prefix}/include/SDL2`;
+ if (fs.existsSync(sdl2_dir)) {
+ return 2;
+ }
+ throw new util_1.SetupSdlError("Could not determine version of SDL");
+}
async function run() {
const SDL_BUILD_PLATFORM = (0, platform_1.get_sdl_build_platform)();
core.info(`build platform=${SDL_BUILD_PLATFORM}`);
@@ -184,11 +195,6 @@ async function run() {
await (0, ninja_1.configure_ninja_build_tool)(SDL_BUILD_PLATFORM);
});
}
- // if (SDL_BUILD_PLATFORM == SdlBuildPlatform.Windows) {
- // await core.group(`Configuring VS environment`, async () => {
- // setup_vc_environment();
- // });
- // }
const source_dir = `${SETUP_SDL_ROOT}/src`;
const build_dir = `${SETUP_SDL_ROOT}/build`;
const install_dir = `${SETUP_SDL_ROOT}`;
@@ -198,6 +204,8 @@ async function run() {
}
await checkout_sdl_git_hash(git_hash, source_dir);
await cmake_configure_build(source_dir, build_dir, install_dir, CMAKE_BUILD_TYPE, cmake_args);
+ const sdl_major_version = detect_sdl_major_version(install_dir);
+ core.exportVariable(`SDL${sdl_major_version}_ROOT`, install_dir);
core.setOutput("prefix", install_dir);
}
run();
diff --git a/src/main.ts b/src/main.ts
index 02ab5c4..70023a4 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -4,7 +4,6 @@ import * as fs from "fs";
import * as core from "@actions/core";
import { SDL_GIT_URL } from "./constants";
-import { setup_vc_environment } from "./msvc";
import { configure_ninja_build_tool } from "./ninja";
import { SetupSdlError } from "./util";
@@ -17,7 +16,6 @@ import {
import {
get_sdl_build_platform,
get_platform_root_directory,
- SdlBuildPlatform,
} from "./platform";
async function convert_git_branch_tag_to_hash(
@@ -96,6 +94,19 @@ async function cmake_configure_build(
});
}
+function detect_sdl_major_version(prefix: string): number {
+ const sdl3_dir = `${prefix}/include/SDL3`;
+ if (fs.existsSync(sdl3_dir)) {
+ return 3;
+ }
+
+ const sdl2_dir = `${prefix}/include/SDL2`;
+ if (fs.existsSync(sdl2_dir)) {
+ return 2;
+ }
+ throw new SetupSdlError("Could not determine version of SDL");
+}
+
async function run() {
const SDL_BUILD_PLATFORM = get_sdl_build_platform();
core.info(`build platform=${SDL_BUILD_PLATFORM}`);
@@ -160,12 +171,6 @@ async function run() {
});
}
- // if (SDL_BUILD_PLATFORM == SdlBuildPlatform.Windows) {
- // await core.group(`Configuring VS environment`, async () => {
- // setup_vc_environment();
- // });
- // }
-
const source_dir = `${SETUP_SDL_ROOT}/src`;
const build_dir = `${SETUP_SDL_ROOT}/build`;
const install_dir = `${SETUP_SDL_ROOT}`;
@@ -184,6 +189,9 @@ async function run() {
cmake_args
);
+ const sdl_major_version = detect_sdl_major_version(install_dir);
+
+ core.exportVariable(`SDL${sdl_major_version}_ROOT`, install_dir);
core.setOutput("prefix", install_dir);
}