From eecbcad36489241cf107f60edd44d00b373c4603 Mon Sep 17 00:00:00 2001 From: Hans Fredrik Nordhaug Date: Thu, 5 Sep 2024 06:23:00 +0200 Subject: [PATCH] Change Bash to Shell everywhere (#223) * Change Bash to Shell everywhere Updates function names to match the earlier change from "bash" to "sh". Removes last instance of "bash" execution. Resolves #215 * Remove EOL on last line for dist files Trying to fix test / build failure. EOL inserted by editor (vim) automatically. --- README.md | 4 ++-- dist/restore/index.js | 52 +++++++++++++++++++++---------------------- dist/save/index.js | 12 +++++----- src/restore.ts | 52 +++++++++++++++++++++---------------------- src/save.ts | 12 +++++----- 5 files changed, 66 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 4a7bce12..d36185a1 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ Ccache/sccache gets installed by this action if it is not installed yet. ### Notes on Windows support -Note that using Ccache on Windows is still experimental and [works only in Bash](https://github.com/ccache/ccache/issues/1023). -Use Sccache for stable Windows support. +Note that using Ccache on Windows [probably works](https://ccache.dev/platform-compiler-language-support.html), but +Sccache is recommended for stable Windows support. ### If you have multiple jobs diff --git a/dist/restore/index.js b/dist/restore/index.js index b10d6669..d1569db1 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -59632,41 +59632,41 @@ async function restore(ccacheVariant) { async function configure(ccacheVariant, platform) { const maxSize = core.getInput('max-size'); if (ccacheVariant === "ccache") { - await execBash(`ccache --set-config=cache_dir='${cacheDir(ccacheVariant)}'`); - await execBash(`ccache --set-config=max_size='${maxSize}'`); - await execBash(`ccache --set-config=compression=true`); + await execShell(`ccache --set-config=cache_dir='${cacheDir(ccacheVariant)}'`); + await execShell(`ccache --set-config=max_size='${maxSize}'`); + await execShell(`ccache --set-config=compression=true`); if (platform === "darwin") { - await execBash(`ccache --set-config=compiler_check=content`); + await execShell(`ccache --set-config=compiler_check=content`); } if (core.getBooleanInput("create-symlink")) { const ccache = await io.which("ccache"); - await execBash(`ln -s ${ccache} /usr/local/bin/gcc`); - await execBash(`ln -s ${ccache} /usr/local/bin/g++`); - await execBash(`ln -s ${ccache} /usr/local/bin/cc`); - await execBash(`ln -s ${ccache} /usr/local/bin/c++`); - await execBash(`ln -s ${ccache} /usr/local/bin/clang`); - await execBash(`ln -s ${ccache} /usr/local/bin/clang++`); - await execBash(`ln -s ${ccache} /usr/local/bin/emcc`); - await execBash(`ln -s ${ccache} /usr/local/bin/em++`); + await execShell(`ln -s ${ccache} /usr/local/bin/gcc`); + await execShell(`ln -s ${ccache} /usr/local/bin/g++`); + await execShell(`ln -s ${ccache} /usr/local/bin/cc`); + await execShell(`ln -s ${ccache} /usr/local/bin/c++`); + await execShell(`ln -s ${ccache} /usr/local/bin/clang`); + await execShell(`ln -s ${ccache} /usr/local/bin/clang++`); + await execShell(`ln -s ${ccache} /usr/local/bin/emcc`); + await execShell(`ln -s ${ccache} /usr/local/bin/em++`); } core.info("Cccache config:"); - await execBash("ccache -p"); + await execShell("ccache -p"); } else { const options = `SCCACHE_IDLE_TIMEOUT=0 SCCACHE_DIR='${cacheDir(ccacheVariant)}' SCCACHE_CACHE_SIZE='${maxSize}'`; - await execBash(`env ${options} sccache --start-server`); + await execShell(`env ${options} sccache --start-server`); } } async function installCcacheMac() { - await execBash("brew install ccache"); + await execShell("brew install ccache"); } async function installCcacheLinux() { if (await io.which("apt-get")) { - await execBashSudo("apt-get install -y ccache"); + await execShellSudo("apt-get install -y ccache"); return; } else if (await io.which("apk")) { - await execBash("apk add ccache"); + await execShell("apk add ccache"); return; } throw Error("Can't install ccache automatically under this platform, please install it yourself before using this action."); @@ -59679,7 +59679,7 @@ async function installCcacheWindows() { `${external_process_namespaceObject.env.USERPROFILE}\\.cargo\\bin`, "ccache.exe"); } async function installSccacheMac() { - await execBash("brew install sccache"); + await execShell("brew install sccache"); } async function installSccacheLinux() { await installSccacheFromGitHub("v0.7.6", "x86_64-unknown-linux-musl", "8c2bb0805983a6fe334fa8b5c26db2c5fc3a7fc3dbf51522a08f2e4c50e4fbe7", "/usr/local/bin/", "sccache"); @@ -59689,11 +59689,11 @@ async function installSccacheWindows() { // TODO find a better place `${external_process_namespaceObject.env.USERPROFILE}\\.cargo\\bin`, "sccache.exe"); } -async function execBash(cmd) { +async function execShell(cmd) { await exec.exec("sh", ["-xc", cmd]); } -async function execBashSudo(cmd) { - await execBash("$(which sudo) " + cmd); +async function execShellSudo(cmd) { + await execShell("$(which sudo) " + cmd); } async function installCcacheFromGitHub(version, artifactName, binSha256, binDir, binName) { const archiveName = `ccache-${version}-${artifactName}`; @@ -59709,14 +59709,14 @@ async function installSccacheFromGitHub(version, artifactName, binSha256, binDir await downloadAndExtract(url, `*/${binName}`, binPath); checkSha256Sum(binPath, binSha256); core.addPath(binDir); - await execBash(`chmod +x '${binPath}'`); + await execShell(`chmod +x '${binPath}'`); } async function downloadAndExtract(url, srcFile, dstFile) { if (url.endsWith(".zip")) { const tmp = external_fs_default().mkdtempSync(external_path_default().join(external_os_default().tmpdir(), "")); const zipName = external_path_default().join(tmp, "dl.zip"); - await execBash(`curl -L '${url}' -o '${zipName}'`); - await execBash(`unzip '${zipName}' -d '${tmp}'`); + await execShell(`curl -L '${url}' -o '${zipName}'`); + await execShell(`unzip '${zipName}' -d '${tmp}'`); const dstDir = external_path_default().dirname(dstFile); if (!external_fs_default().existsSync(dstDir)) { external_fs_default().mkdirSync(dstDir, { recursive: true }); @@ -59725,7 +59725,7 @@ async function downloadAndExtract(url, srcFile, dstFile) { external_fs_default().rmSync(tmp, { recursive: true }); } else { - await execBash(`curl -L '${url}' | tar xzf - -O --wildcards '${srcFile}' > '${dstFile}'`); + await execShell(`curl -L '${url}' | tar xzf - -O --wildcards '${srcFile}' > '${dstFile}'`); } } function checkSha256Sum(path, expectedSha256) { @@ -59765,7 +59765,7 @@ async function runInner() { core.endGroup(); core.startGroup(`Configure ${ccacheVariant}, ${external_process_namespaceObject.platform}`); await configure(ccacheVariant, external_process_namespaceObject.platform); - await execBash(`${ccacheVariant} -z`); + await execShell(`${ccacheVariant} -z`); core.endGroup(); } async function run() { diff --git a/dist/save/index.js b/dist/save/index.js index cd65ce5a..db7477f9 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -59581,14 +59581,14 @@ function cacheDir(ccacheVariant) { async function ccacheIsEmpty(ccacheVariant, ccacheKnowsVerbosityFlag) { if (ccacheVariant === "ccache") { if (ccacheKnowsVerbosityFlag) { - return !!(await getExecBashOutput("ccache -s -v")).stdout.match(/Files:.+\b0\b/); + return !!(await getExecShellOutput("ccache -s -v")).stdout.match(/Files:.+\b0\b/); } else { - return !!(await getExecBashOutput("ccache -s")).stdout.match(/files in cache.+\b0\b/); + return !!(await getExecShellOutput("ccache -s")).stdout.match(/files in cache.+\b0\b/); } } else { - return !!(await getExecBashOutput("sccache -s")).stdout.match(/Cache size.+\b0 bytes/); + return !!(await getExecShellOutput("sccache -s")).stdout.match(/Cache size.+\b0 bytes/); } } async function getVerbosity(verbositySetting) { @@ -59604,8 +59604,8 @@ async function getVerbosity(verbositySetting) { return ''; } } -function getExecBashOutput(cmd) { - return exec.getExecOutput("bash", ["-xc", cmd], { silent: true }); +function getExecShellOutput(cmd) { + return exec.getExecOutput("sh", ["-xc", cmd], { silent: true }); } async function run(earlyExit) { try { @@ -59616,7 +59616,7 @@ async function run(earlyExit) { return; } // Some versions of ccache do not support --verbose - const ccacheKnowsVerbosityFlag = !!(await getExecBashOutput(`${ccacheVariant} --help`)).stdout.includes("--verbose"); + const ccacheKnowsVerbosityFlag = !!(await getExecShellOutput(`${ccacheVariant} --help`)).stdout.includes("--verbose"); core.startGroup(`${ccacheVariant} stats`); const verbosity = ccacheKnowsVerbosityFlag ? await getVerbosity(core.getInput("verbose")) : ''; await exec.exec(`${ccacheVariant} -s${verbosity}`); diff --git a/src/restore.ts b/src/restore.ts index e196c8b4..bdf45c90 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -50,42 +50,42 @@ async function configure(ccacheVariant : string, platform : string) : Promise { - await execBash("brew install ccache"); + await execShell("brew install ccache"); } async function installCcacheLinux() : Promise { if (await io.which("apt-get")) { - await execBashSudo("apt-get install -y ccache"); + await execShellSudo("apt-get install -y ccache"); return; } else if (await io.which("apk")) { - await execBash("apk add ccache"); + await execShell("apk add ccache"); return; } throw Error("Can't install ccache automatically under this platform, please install it yourself before using this action."); @@ -104,7 +104,7 @@ async function installCcacheWindows() : Promise { } async function installSccacheMac() : Promise { - await execBash("brew install sccache"); + await execShell("brew install sccache"); } async function installSccacheLinux() : Promise { @@ -128,12 +128,12 @@ async function installSccacheWindows() : Promise { ); } -async function execBash(cmd : string) { +async function execShell(cmd : string) { await exec.exec("sh", ["-xc", cmd]); } -async function execBashSudo(cmd : string) { - await execBash("$(which sudo) " + cmd); +async function execShellSudo(cmd : string) { + await execShell("$(which sudo) " + cmd); } async function installCcacheFromGitHub(version : string, artifactName : string, binSha256 : string, binDir : string, binName : string) : Promise { @@ -151,15 +151,15 @@ async function installSccacheFromGitHub(version : string, artifactName : string, await downloadAndExtract(url, `*/${binName}`, binPath); checkSha256Sum(binPath, binSha256); core.addPath(binDir); - await execBash(`chmod +x '${binPath}'`); + await execShell(`chmod +x '${binPath}'`); } async function downloadAndExtract (url : string, srcFile : string, dstFile : string) { if (url.endsWith(".zip")) { const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "")); const zipName = path.join(tmp, "dl.zip"); - await execBash(`curl -L '${url}' -o '${zipName}'`); - await execBash(`unzip '${zipName}' -d '${tmp}'`); + await execShell(`curl -L '${url}' -o '${zipName}'`); + await execShell(`unzip '${zipName}' -d '${tmp}'`); const dstDir = path.dirname(dstFile); if (!fs.existsSync(dstDir)) { fs.mkdirSync(dstDir, { recursive: true }); @@ -167,7 +167,7 @@ async function downloadAndExtract (url : string, srcFile : string, dstFile : str fs.copyFileSync(path.join(tmp, srcFile), dstFile); fs.rmSync(tmp, { recursive: true }); } else { - await execBash(`curl -L '${url}' | tar xzf - -O --wildcards '${srcFile}' > '${dstFile}'`); + await execShell(`curl -L '${url}' | tar xzf - -O --wildcards '${srcFile}' > '${dstFile}'`); } } @@ -211,7 +211,7 @@ async function runInner() : Promise { core.startGroup(`Configure ${ccacheVariant}, ${process.platform}`); await configure(ccacheVariant, process.platform); - await execBash(`${ccacheVariant} -z`); + await execShell(`${ccacheVariant} -z`); core.endGroup(); } diff --git a/src/save.ts b/src/save.ts index 627ac76c..b4ef041c 100644 --- a/src/save.ts +++ b/src/save.ts @@ -6,12 +6,12 @@ import { cacheDir } from "./common"; async function ccacheIsEmpty(ccacheVariant : string, ccacheKnowsVerbosityFlag : boolean) : Promise { if (ccacheVariant === "ccache") { if (ccacheKnowsVerbosityFlag) { - return !!(await getExecBashOutput("ccache -s -v")).stdout.match(/Files:.+\b0\b/); + return !!(await getExecShellOutput("ccache -s -v")).stdout.match(/Files:.+\b0\b/); } else { - return !!(await getExecBashOutput("ccache -s")).stdout.match(/files in cache.+\b0\b/) + return !!(await getExecShellOutput("ccache -s")).stdout.match(/files in cache.+\b0\b/) } } else { - return !!(await getExecBashOutput("sccache -s")).stdout.match(/Cache size.+\b0 bytes/); + return !!(await getExecShellOutput("sccache -s")).stdout.match(/Cache size.+\b0 bytes/); } } @@ -32,8 +32,8 @@ async function getVerbosity(verbositySetting : string) : Promise { } } -function getExecBashOutput(cmd : string) : Promise { - return exec.getExecOutput("bash", ["-xc", cmd], {silent: true}); +function getExecShellOutput(cmd : string) : Promise { + return exec.getExecOutput("sh", ["-xc", cmd], {silent: true}); } async function run(earlyExit : boolean | undefined) : Promise { @@ -46,7 +46,7 @@ async function run(earlyExit : boolean | undefined) : Promise { } // Some versions of ccache do not support --verbose - const ccacheKnowsVerbosityFlag = !!(await getExecBashOutput(`${ccacheVariant} --help`)).stdout.includes("--verbose"); + const ccacheKnowsVerbosityFlag = !!(await getExecShellOutput(`${ccacheVariant} --help`)).stdout.includes("--verbose"); core.startGroup(`${ccacheVariant} stats`); const verbosity = ccacheKnowsVerbosityFlag ? await getVerbosity(core.getInput("verbose")) : '';