Skip to content

Commit

Permalink
Change Bash to Shell everywhere (#223)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
hansfn authored Sep 5, 2024
1 parent eb34167 commit eecbcad
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 26 additions & 26 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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");
Expand All @@ -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}`;
Expand All @@ -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 });
Expand All @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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}`);
Expand Down
52 changes: 26 additions & 26 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,42 @@ async function configure(ccacheVariant : string, platform : string) : Promise<vo
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() : Promise<void> {
await execBash("brew install ccache");
await execShell("brew install ccache");
}

async function installCcacheLinux() : Promise<void> {
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.");
Expand All @@ -104,7 +104,7 @@ async function installCcacheWindows() : Promise<void> {
}

async function installSccacheMac() : Promise<void> {
await execBash("brew install sccache");
await execShell("brew install sccache");
}

async function installSccacheLinux() : Promise<void> {
Expand All @@ -128,12 +128,12 @@ async function installSccacheWindows() : Promise<void> {
);
}

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<void> {
Expand All @@ -151,23 +151,23 @@ 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 });
}
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}'`);
}
}

Expand Down Expand Up @@ -211,7 +211,7 @@ async function runInner() : Promise<void> {

core.startGroup(`Configure ${ccacheVariant}, ${process.platform}`);
await configure(ccacheVariant, process.platform);
await execBash(`${ccacheVariant} -z`);
await execShell(`${ccacheVariant} -z`);
core.endGroup();
}

Expand Down
12 changes: 6 additions & 6 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { cacheDir } from "./common";
async function ccacheIsEmpty(ccacheVariant : string, ccacheKnowsVerbosityFlag : boolean) : Promise<boolean> {
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/);
}
}

Expand All @@ -32,8 +32,8 @@ async function getVerbosity(verbositySetting : string) : Promise<string> {
}
}

function getExecBashOutput(cmd : string) : Promise<exec.ExecOutput> {
return exec.getExecOutput("bash", ["-xc", cmd], {silent: true});
function getExecShellOutput(cmd : string) : Promise<exec.ExecOutput> {
return exec.getExecOutput("sh", ["-xc", cmd], {silent: true});
}

async function run(earlyExit : boolean | undefined) : Promise<void> {
Expand All @@ -46,7 +46,7 @@ async function run(earlyExit : boolean | undefined) : Promise<void> {
}

// 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")) : '';
Expand Down

0 comments on commit eecbcad

Please sign in to comment.