Skip to content

Commit

Permalink
Add a new flag create-symlink (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
UNIDY2002 authored Dec 22, 2023
1 parent 9ec9ca3 commit 2a51777
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,23 @@ jobs:
uses: ./
with:
append-timestamp: ${{ matrix.append-timestamp }}

test_option_create_symlink:
# Test that the 'create-symlink' option is available.
runs-on: ubuntu-latest
strategy:
matrix:
create-symlink: [true, false]
steps:
- uses: actions/checkout@v2
- name: Run ccache-action
uses: ./
with:
create-symlink: ${{ matrix.create-symlink }}
- name: Test symlink
run: |
if [ ${{ matrix.create-symlink }} = true ]; then
ls -l $(which gcc) | grep $(which ccache)
else
ls -l $(which gcc) | grep -v $(which ccache)
fi
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ or by manipulating `PATH` (ccache only):

(works for both `ubuntu` and `macos`)

or by setting create-symlink to `true`:

```yaml
- name: ccache
uses: hendrikmuhs/[email protected]
with:
create-symlink: true
```


Ccache/sccache gets installed by this action if it is not installed yet.

### Example workflow
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
description: "Append a timestamp to the cache key (default: true)"
default: true
required: false
create-symlink:
description: "If set to 'true', create symlinks for ccache in /usr/local/bin to override default toolchains"
default: false
required: false
runs:
using: "node16"
main: "dist/restore/index.js"
Expand Down
9 changes: 9 additions & 0 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59626,6 +59626,15 @@ async function configure(ccacheVariant, platform) {
if (platform === "darwin") {
await execBash(`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++`);
}
core.info("Cccache config:");
await execBash("ccache -p");
}
Expand Down
9 changes: 9 additions & 0 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ async function configure(ccacheVariant : string, platform : string) : Promise<vo
if (platform === "darwin") {
await execBash(`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++`);
}
core.info("Cccache config:");
await execBash("ccache -p");
} else {
Expand Down

0 comments on commit 2a51777

Please sign in to comment.