Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitlab/build/bazel/defs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
policy: pull$BAZEL_CACHE_POLICY_SUFFIX
when: on_success
- &bazel_cache
key: bazel-$CI_RUNNER_DESCRIPTION
key:
prefix: bazel-$CI_RUNNER_DESCRIPTION
files: [ .go-version, .python-version ]
paths:
- .cache/bazel/*/cache
- .cache/go-build
- .cache/go/mod
- .cache/pip
policy: pull$BAZEL_CACHE_POLICY_SUFFIX
when: on_success
Expand Down
15 changes: 13 additions & 2 deletions tools/bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ if [ ! -d "${XDG_CACHE_HOME:-}" ]; then
# shellcheck disable=SC2016
>&2 echo ' docker run --env=XDG_CACHE_HOME=/cache --volume="$HOME/.cache:/cache" ...'
fi
elif [ -n "${CI:-}" ]; then
exec "$BAZEL_REAL" ${1:+"$1" --config=ci} "${@:2}"
fi

# Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` as per https://wiki.archlinux.org/title/XDG_Base_Directory
if [ -n "${XDG_CACHE_HOME:-}" ]; then
if [[ "$XDG_CACHE_HOME" != /* ]]; then
>&2 echo "🔴 XDG_CACHE_HOME ($XDG_CACHE_HOME) must denote an absolute path!"
exit 2
fi
unset GOCACHE # https://pkg.go.dev/os#UserCacheDir
export GOMODCACHE="$XDG_CACHE_HOME"/go/mod # https://wiki.archlinux.org/title/XDG_Base_Directory#Partial
unset PIP_CACHE_DIR # https://pip.pypa.io/en/stable/topics/caching/#default-paths

[ -n "${CI:-}" ] && exec "$BAZEL_REAL" ${1:+"$1" --config=ci} "${@:2}"
fi

exec "$BAZEL_REAL" "$@"
13 changes: 12 additions & 1 deletion tools/bazel.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ if not exist "%XDG_CACHE_HOME%" (
)
)

:: Make `bazel` honor $XDG_CACHE_HOME if set as it does on POSIX OSes: https://github.com/bazelbuild/bazel/issues/27808
:: Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` if set: https://github.com/bazelbuild/bazel/issues/27808
if defined XDG_CACHE_HOME (
set "XDG_CACHE_HOME=!XDG_CACHE_HOME:/=\!"
if "!XDG_CACHE_HOME:~1,2!" neq ":\" if "!XDG_CACHE_HOME:~0,2!" neq "\\" (
>&2 echo 🔴 XDG_CACHE_HOME ^(!XDG_CACHE_HOME!^) must denote an absolute path!
exit /b 2
)
:: https://pkg.go.dev/os#UserCacheDir
set "GOCACHE=%XDG_CACHE_HOME%\go-build"
:: https://wiki.archlinux.org/title/XDG_Base_Directory#Partial
set "GOMODCACHE=%XDG_CACHE_HOME%\go\mod"
:: https://pip.pypa.io/en/stable/topics/caching/#default-paths
set "PIP_CACHE_DIR=%XDG_CACHE_HOME%\pip"
set "bazel_home=%XDG_CACHE_HOME%\bazel"
set bazel_home_startup_option="--output_user_root=!bazel_home!"
) else (
Expand Down