mirror of
https://github.com/threeal/cmake-action.git
synced 2025-07-27 08:14:23 +00:00
* feat: add `parse` function Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * chore: remoev unused shell-quote from dependencies Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * test: update `context.test.ts` test Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> --------- Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import { getInput } from "gha-utils";
|
|
import path from "node:path";
|
|
import { parse } from "./utils.js";
|
|
|
|
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) {
|
|
options.push(...parse(input).map((opt) => opt.toString()));
|
|
}
|
|
|
|
return {
|
|
sourceDir,
|
|
buildDir: getInput("build-dir") || path.join(sourceDir, "build"),
|
|
configure: {
|
|
generator: getInput("generator"),
|
|
options,
|
|
args: parse(getInput("args")).map((arg) => arg.toString()),
|
|
},
|
|
build: {
|
|
enabled: getInput("run-build") == "true",
|
|
args: parse(getInput("build-args")).map((arg) => arg.toString()),
|
|
},
|
|
};
|
|
}
|