mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-23 12:01:20 +00:00
* feat: utilize GitHub Actions Utilities package * test: modify get action context test by mocking `getInput` function
66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
import { getInput } from "gha-utils";
|
|
import path from "node:path";
|
|
|
|
export interface Context {
|
|
sourceDir: string;
|
|
buildDir: string;
|
|
configure: {
|
|
generator: string;
|
|
options: string[];
|
|
args: string[];
|
|
};
|
|
build: {
|
|
enabled: boolean;
|
|
args: string[];
|
|
};
|
|
}
|
|
|
|
export function getContext(): Context {
|
|
const sourceDir = getInput("source-dir");
|
|
const options: string[] = [];
|
|
|
|
let input = getInput("c-compiler");
|
|
if (input) options.push(`CMAKE_C_COMPILER=${input}`);
|
|
|
|
input = getInput("cxx-compiler");
|
|
if (input) options.push(`CMAKE_CXX_COMPILER=${input}`);
|
|
|
|
input = getInput("c-flags");
|
|
if (input) {
|
|
const flags = input.replaceAll(/\s+/g, " ");
|
|
options.push(`CMAKE_C_FLAGS=${flags}`);
|
|
}
|
|
|
|
input = getInput("cxx-flags");
|
|
if (input) {
|
|
const flags = input.replaceAll(/\s+/g, " ");
|
|
options.push(`CMAKE_CXX_FLAGS=${flags}`);
|
|
}
|
|
|
|
input = getInput("options");
|
|
if (input) {
|
|
const opts = input.split(/\s+/).filter((arg) => arg != "");
|
|
for (const opt of opts) {
|
|
options.push(opt);
|
|
}
|
|
}
|
|
|
|
return {
|
|
sourceDir,
|
|
buildDir: getInput("build-dir") || path.join(sourceDir, "build"),
|
|
configure: {
|
|
generator: getInput("generator"),
|
|
options,
|
|
args: getInput("args")
|
|
.split(/\s+/)
|
|
.filter((arg) => arg != ""),
|
|
},
|
|
build: {
|
|
enabled: getInput("run-build") == "true",
|
|
args: getInput("build-args")
|
|
.split(/\s+/)
|
|
.filter((arg) => arg != ""),
|
|
},
|
|
};
|
|
}
|