|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -# In some scenarios (like CodeSpaces), apparently not all (or even any?) |
5 | | -# bind mounts to the host are done and /var/cache/bazel does not exist. |
6 | | -# See devcontainer-feature.json, where this mount is defined. |
7 | | -# Hence, if /var/cache/bazel exists, it was mounted from the host, |
8 | | -# and we configure Bazel to use /var/cache/bazel as cache. |
9 | | -# This way, Bazel re-uses a bind-mounted cache from the host machine, while |
10 | | -# still using the default cache (${HOME}/.cache/bazel) if no such cache exists. |
| 4 | +# Enable persistent Bazel cache |
| 5 | +# |
| 6 | +# Usually, a volume is mounted to /var/cache/bazel (see |
| 7 | +# devcontainer-feature.json). This shall be used as Bazel cache, which is then |
| 8 | +# preserved across container re-starts. Since the volume has a fixed |
| 9 | +# name ("eclipse-s-core-bazel-cache"), it is even used across all Eclipse |
| 10 | +# S-CORE DevContainer instances. |
11 | 11 | if [ -d /var/cache/bazel ]; then |
12 | | - echo "Configuring Bazel to use /var/cache/bazel as cache..." |
| 12 | + echo "Bazel Cache: /var/cache/bazel exists. Checking ownership and configuring Bazel to use it as cache..." |
| 13 | + current_owner_group=$(stat -c "%U:%G" /var/cache/bazel) |
| 14 | + current_user_group="$(id -un):$(id -gn)" |
| 15 | + if [ "${current_owner_group}" = "${current_user_group}" ]; then |
| 16 | + echo "Bazel Cache: /var/cache/bazel is already owned by ${current_user_group}. " |
| 17 | + else |
| 18 | + echo "Bazel Cache: /var/cache/bazel is not owned by ${current_owner_group}. Setting ownership (this may take a few seconds) ..." |
| 19 | + sudo chown -R "${current_user_group}" /var/cache/bazel |
| 20 | + fi |
| 21 | + echo "Bazel Cache: Configuring Bazel to use /var/cache/bazel as cache..." |
13 | 22 | echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc |
14 | 23 | fi |
15 | 24 |
|
|
0 commit comments