From 866c471b81700525059dbb8acbb139bd145faabc Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 22 Mar 2024 22:36:08 +0700 Subject: [PATCH] refactor: add `configureProject` function from lines in `main` function --- dist/index.js | 50 +++++++++++++++++++++++++++++++------------------- src/cmake.ts | 36 ++++++++++++++++++++++++++++++++++++ src/index.ts | 27 ++------------------------- 3 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 src/cmake.ts diff --git a/dist/index.js b/dist/index.js index 6711925..c6e7846 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27698,6 +27698,35 @@ var __webpack_exports__ = {}; var core = __nccwpck_require__(2340); // EXTERNAL MODULE: ../../../.yarn/berry/cache/@actions-exec-npm-1.1.1-90973d2f96-10c0.zip/node_modules/@actions/exec/lib/exec.js var exec = __nccwpck_require__(4926); +;// CONCATENATED MODULE: ./src/cmake.ts + +/** + * Configures the build system of a CMake project. + * + * @param inputs - The action inputs. + */ +async function configureProject(inputs) { + const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; + if (inputs.generator) { + configureArgs.push(...["-G", inputs.generator]); + } + if (inputs.cCompiler) { + configureArgs.push("-DCMAKE_C_COMPILER=" + inputs.cCompiler); + } + if (inputs.cxxCompiler) { + configureArgs.push("-DCMAKE_CXX_COMPILER=" + inputs.cxxCompiler); + } + if (inputs.cFlags) { + configureArgs.push("-DCMAKE_C_FLAGS=" + inputs.cFlags); + } + if (inputs.cxxFlags) { + configureArgs.push("-DCMAKE_CXX_FLAGS=" + inputs.cxxFlags); + } + configureArgs.push(...inputs.options.map((opt) => "-D" + opt)); + configureArgs.push(...inputs.args); + await (0,exec.exec)("cmake", configureArgs); +} + ;// CONCATENATED MODULE: ./src/inputs.ts function getInputs() { @@ -27720,27 +27749,10 @@ function getInputs() { + async function main() { const inputs = getInputs(); - const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; - if (inputs.generator) { - configureArgs.push(...["-G", inputs.generator]); - } - if (inputs.cCompiler) { - configureArgs.push("-DCMAKE_C_COMPILER=" + inputs.cCompiler); - } - if (inputs.cxxCompiler) { - configureArgs.push("-DCMAKE_CXX_COMPILER=" + inputs.cxxCompiler); - } - if (inputs.cFlags) { - configureArgs.push("-DCMAKE_C_FLAGS=" + inputs.cFlags); - } - if (inputs.cxxFlags) { - configureArgs.push("-DCMAKE_CXX_FLAGS=" + inputs.cxxFlags); - } - configureArgs.push(...inputs.options.map((opt) => "-D" + opt)); - configureArgs.push(...inputs.args); - await (0,exec.exec)("cmake", configureArgs); + await configureProject(inputs); core.setOutput("build-dir", inputs.buildDir); if (inputs.runBuild) { await (0,exec.exec)("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]); diff --git a/src/cmake.ts b/src/cmake.ts new file mode 100644 index 0000000..0a5fc6c --- /dev/null +++ b/src/cmake.ts @@ -0,0 +1,36 @@ +import { exec } from "@actions/exec"; +import type { Inputs } from "./inputs.js"; + +/** + * Configures the build system of a CMake project. + * + * @param inputs - The action inputs. + */ +export async function configureProject(inputs: Inputs): Promise { + const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; + + if (inputs.generator) { + configureArgs.push(...["-G", inputs.generator]); + } + + if (inputs.cCompiler) { + configureArgs.push("-DCMAKE_C_COMPILER=" + inputs.cCompiler); + } + + if (inputs.cxxCompiler) { + configureArgs.push("-DCMAKE_CXX_COMPILER=" + inputs.cxxCompiler); + } + + if (inputs.cFlags) { + configureArgs.push("-DCMAKE_C_FLAGS=" + inputs.cFlags); + } + + if (inputs.cxxFlags) { + configureArgs.push("-DCMAKE_CXX_FLAGS=" + inputs.cxxFlags); + } + + configureArgs.push(...inputs.options.map((opt) => "-D" + opt)); + configureArgs.push(...inputs.args); + + await exec("cmake", configureArgs); +} diff --git a/src/index.ts b/src/index.ts index a470b36..674a0ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,36 +1,13 @@ import * as core from "@actions/core"; import { exec } from "@actions/exec"; +import { configureProject } from "./cmake.js"; import { getInputs } from "./inputs.js"; async function main() { const inputs = getInputs(); - const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; + await configureProject(inputs); - if (inputs.generator) { - configureArgs.push(...["-G", inputs.generator]); - } - - if (inputs.cCompiler) { - configureArgs.push("-DCMAKE_C_COMPILER=" + inputs.cCompiler); - } - - if (inputs.cxxCompiler) { - configureArgs.push("-DCMAKE_CXX_COMPILER=" + inputs.cxxCompiler); - } - - if (inputs.cFlags) { - configureArgs.push("-DCMAKE_C_FLAGS=" + inputs.cFlags); - } - - if (inputs.cxxFlags) { - configureArgs.push("-DCMAKE_CXX_FLAGS=" + inputs.cxxFlags); - } - - configureArgs.push(...inputs.options.map((opt) => "-D" + opt)); - configureArgs.push(...inputs.args); - - await exec("cmake", configureArgs); core.setOutput("build-dir", inputs.buildDir); if (inputs.runBuild) {