From ccad978d3617ae11cbc0b6b184e70e19563df13b Mon Sep 17 00:00:00 2001 From: UNIDY Date: Tue, 19 Dec 2023 10:23:00 +0800 Subject: [PATCH] Add a new flag `create-symlink` --- .github/workflows/tests.yml | 20 ++++++++++++++++++++ README.md | 10 ++++++++++ action.yml | 4 ++++ dist/restore/index.js | 9 +++++++++ src/restore.ts | 9 +++++++++ 5 files changed, 52 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4a36921e..28c57b5b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/README.md b/README.md index a2e3ac5d..4a7bce12 100644 --- a/README.md +++ b/README.md @@ -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/ccache-action@v1.2 + with: + create-symlink: true +``` + + Ccache/sccache gets installed by this action if it is not installed yet. ### Example workflow diff --git a/action.yml b/action.yml index 6de75b6b..db965ba6 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/dist/restore/index.js b/dist/restore/index.js index bf61870a..ea1573b7 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -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"); } diff --git a/src/restore.ts b/src/restore.ts index 024d4f9f..9aaee727 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -56,6 +56,15 @@ async function configure(ccacheVariant : string, platform : string) : Promise