feat: remove redundant specification of CMake source directory (#273)

* feat: remove setting the default of `source-dir` to `.`

* feat: append source dir to configure Cmake args only if specified
This commit is contained in:
Alfi Maulana 2024-03-25 13:03:03 +07:00 committed by GitHub
parent 6c4e2145fb
commit d83693c521
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 20 deletions

8
dist/index.js generated vendored
View File

@ -27735,7 +27735,11 @@ var exec = __nccwpck_require__(4926);
* @param inputs - The action inputs. * @param inputs - The action inputs.
*/ */
async function configureProject(inputs) { async function configureProject(inputs) {
const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; const configureArgs = [];
if (inputs.sourceDir) {
configureArgs.push(inputs.sourceDir);
}
configureArgs.push("-B", inputs.buildDir);
if (inputs.generator) { if (inputs.generator) {
configureArgs.push(...["-G", inputs.generator]); configureArgs.push(...["-G", inputs.generator]);
} }
@ -27771,7 +27775,7 @@ var external_node_path_default = /*#__PURE__*/__nccwpck_require__.n(external_nod
function getInputs() { function getInputs() {
const sourceDir = (0,core.getInput)("source-dir") || "."; const sourceDir = (0,core.getInput)("source-dir");
return { return {
sourceDir, sourceDir,
buildDir: (0,core.getInput)("build-dir") || external_node_path_default().join(sourceDir, "build"), buildDir: (0,core.getInput)("build-dir") || external_node_path_default().join(sourceDir, "build"),

View File

@ -8,7 +8,7 @@ interface TestCase {
} }
const defaultInputs: Inputs = { const defaultInputs: Inputs = {
sourceDir: ".", sourceDir: "",
buildDir: "build", buildDir: "build",
generator: "", generator: "",
cCompiler: "", cCompiler: "",
@ -29,7 +29,7 @@ describe("configure a CMake project", () => {
const testCases: TestCase[] = [ const testCases: TestCase[] = [
{ {
name: "with nothing specified", name: "with nothing specified",
expectedArgs: [".", "-B", "build"], expectedArgs: ["-B", "build"],
}, },
{ {
name: "with source directory specified", name: "with source directory specified",
@ -39,43 +39,37 @@ describe("configure a CMake project", () => {
{ {
name: "with build directory specified", name: "with build directory specified",
inputs: { buildDir: "output" }, inputs: { buildDir: "output" },
expectedArgs: [".", "-B", "output"], expectedArgs: ["-B", "output"],
}, },
{ {
name: "with generator specified", name: "with generator specified",
inputs: { generator: "Ninja" }, inputs: { generator: "Ninja" },
expectedArgs: [".", "-B", "build", "-G", "Ninja"], expectedArgs: ["-B", "build", "-G", "Ninja"],
}, },
{ {
name: "with C compiler specified", name: "with C compiler specified",
inputs: { cCompiler: "clang" }, inputs: { cCompiler: "clang" },
expectedArgs: [".", "-B", "build", "-DCMAKE_C_COMPILER=clang"], expectedArgs: ["-B", "build", "-DCMAKE_C_COMPILER=clang"],
}, },
{ {
name: "with C++ compiler specified", name: "with C++ compiler specified",
inputs: { cxxCompiler: "clang++" }, inputs: { cxxCompiler: "clang++" },
expectedArgs: [".", "-B", "build", "-DCMAKE_CXX_COMPILER=clang++"], expectedArgs: ["-B", "build", "-DCMAKE_CXX_COMPILER=clang++"],
}, },
{ {
name: "with C flags specified", name: "with C flags specified",
inputs: { cFlags: "-Werror -Wall" }, inputs: { cFlags: "-Werror -Wall" },
expectedArgs: [".", "-B", "build", "-DCMAKE_C_FLAGS=-Werror -Wall"], expectedArgs: ["-B", "build", "-DCMAKE_C_FLAGS=-Werror -Wall"],
}, },
{ {
name: "with C++ flags specified", name: "with C++ flags specified",
inputs: { cxxFlags: "-Werror -Wall -Wextra" }, inputs: { cxxFlags: "-Werror -Wall -Wextra" },
expectedArgs: [ expectedArgs: ["-B", "build", "-DCMAKE_CXX_FLAGS=-Werror -Wall -Wextra"],
".",
"-B",
"build",
"-DCMAKE_CXX_FLAGS=-Werror -Wall -Wextra",
],
}, },
{ {
name: "with additional options specified", name: "with additional options specified",
inputs: { options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON"] }, inputs: { options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON"] },
expectedArgs: [ expectedArgs: [
".",
"-B", "-B",
"build", "build",
"-DBUILD_TESTING=ON", "-DBUILD_TESTING=ON",
@ -85,7 +79,7 @@ describe("configure a CMake project", () => {
{ {
name: "with additional arguments specified", name: "with additional arguments specified",
inputs: { args: ["-Wdev", "-Wdeprecated"] }, inputs: { args: ["-Wdev", "-Wdeprecated"] },
expectedArgs: [".", "-B", "build", "-Wdev", "-Wdeprecated"], expectedArgs: ["-B", "build", "-Wdev", "-Wdeprecated"],
}, },
{ {
name: "with all specified", name: "with all specified",

View File

@ -7,7 +7,13 @@ import type { Inputs } from "./inputs.js";
* @param inputs - The action inputs. * @param inputs - The action inputs.
*/ */
export async function configureProject(inputs: Inputs): Promise<void> { export async function configureProject(inputs: Inputs): Promise<void> {
const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; const configureArgs = [];
if (inputs.sourceDir) {
configureArgs.push(inputs.sourceDir);
}
configureArgs.push("-B", inputs.buildDir);
if (inputs.generator) { if (inputs.generator) {
configureArgs.push(...["-G", inputs.generator]); configureArgs.push(...["-G", inputs.generator]);

View File

@ -150,7 +150,7 @@ describe("get action inputs", () => {
}); });
expect(getInputs()).toStrictEqual({ expect(getInputs()).toStrictEqual({
sourceDir: ".", sourceDir: "",
buildDir: "build", buildDir: "build",
generator: "", generator: "",
cCompiler: "", cCompiler: "",

View File

@ -16,7 +16,7 @@ export interface Inputs {
} }
export function getInputs(): Inputs { export function getInputs(): Inputs {
const sourceDir = getInput("source-dir") || "."; const sourceDir = getInput("source-dir");
return { return {
sourceDir, sourceDir,
buildDir: getInput("build-dir") || path.join(sourceDir, "build"), buildDir: getInput("build-dir") || path.join(sourceDir, "build"),