Skip to content

Commit 2a51777

Browse files
authored
Add a new flag create-symlink (#172)
1 parent 9ec9ca3 commit 2a51777

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

.github/workflows/tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,23 @@ jobs:
210210
uses: ./
211211
with:
212212
append-timestamp: ${{ matrix.append-timestamp }}
213+
214+
test_option_create_symlink:
215+
# Test that the 'create-symlink' option is available.
216+
runs-on: ubuntu-latest
217+
strategy:
218+
matrix:
219+
create-symlink: [true, false]
220+
steps:
221+
- uses: actions/checkout@v2
222+
- name: Run ccache-action
223+
uses: ./
224+
with:
225+
create-symlink: ${{ matrix.create-symlink }}
226+
- name: Test symlink
227+
run: |
228+
if [ ${{ matrix.create-symlink }} = true ]; then
229+
ls -l $(which gcc) | grep $(which ccache)
230+
else
231+
ls -l $(which gcc) | grep -v $(which ccache)
232+
fi

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ or by manipulating `PATH` (ccache only):
3535

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

38+
or by setting create-symlink to `true`:
39+
40+
```yaml
41+
- name: ccache
42+
uses: hendrikmuhs/[email protected]
43+
with:
44+
create-symlink: true
45+
```
46+
47+
3848
Ccache/sccache gets installed by this action if it is not installed yet.
3949

4050
### Example workflow

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ inputs:
2828
description: "Append a timestamp to the cache key (default: true)"
2929
default: true
3030
required: false
31+
create-symlink:
32+
description: "If set to 'true', create symlinks for ccache in /usr/local/bin to override default toolchains"
33+
default: false
34+
required: false
3135
runs:
3236
using: "node16"
3337
main: "dist/restore/index.js"

dist/restore/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59626,6 +59626,15 @@ async function configure(ccacheVariant, platform) {
5962659626
if (platform === "darwin") {
5962759627
await execBash(`ccache --set-config=compiler_check=content`);
5962859628
}
59629+
if (core.getBooleanInput("create-symlink")) {
59630+
const ccache = await io.which("ccache");
59631+
await execBash(`ln -s ${ccache} /usr/local/bin/gcc`);
59632+
await execBash(`ln -s ${ccache} /usr/local/bin/g++`);
59633+
await execBash(`ln -s ${ccache} /usr/local/bin/cc`);
59634+
await execBash(`ln -s ${ccache} /usr/local/bin/c++`);
59635+
await execBash(`ln -s ${ccache} /usr/local/bin/clang`);
59636+
await execBash(`ln -s ${ccache} /usr/local/bin/clang++`);
59637+
}
5962959638
core.info("Cccache config:");
5963059639
await execBash("ccache -p");
5963159640
}

src/restore.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ async function configure(ccacheVariant : string, platform : string) : Promise<vo
5656
if (platform === "darwin") {
5757
await execBash(`ccache --set-config=compiler_check=content`);
5858
}
59+
if (core.getBooleanInput("create-symlink")) {
60+
const ccache = await io.which("ccache");
61+
await execBash(`ln -s ${ccache} /usr/local/bin/gcc`);
62+
await execBash(`ln -s ${ccache} /usr/local/bin/g++`);
63+
await execBash(`ln -s ${ccache} /usr/local/bin/cc`);
64+
await execBash(`ln -s ${ccache} /usr/local/bin/c++`);
65+
await execBash(`ln -s ${ccache} /usr/local/bin/clang`);
66+
await execBash(`ln -s ${ccache} /usr/local/bin/clang++`);
67+
}
5968
core.info("Cccache config:");
6069
await execBash("ccache -p");
6170
} else {

0 commit comments

Comments
 (0)