Skip to content

Commit

Permalink
Respect the XDG_CACHE_HOME environment variable
Browse files Browse the repository at this point in the history
Fixes: #16
  • Loading branch information
EdSchouten committed Jul 12, 2024
1 parent 2fc0903 commit ab3b694
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ bb\_clientd:

```sh
umount ~/bb_clientd; fusermount -u ~/bb_clientd
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-~/.cache}
mkdir -p \
~/.cache/bb_clientd/ac/persistent_state \
~/.cache/bb_clientd/cas/persistent_state \
~/.cache/bb_clientd/outputs \
${XDG_CACHE_HOME}/bb_clientd/ac/persistent_state \
${XDG_CACHE_HOME}/bb_clientd/cas/persistent_state \
${XDG_CACHE_HOME}/bb_clientd/outputs \
~/bb_clientd
OS=$(uname) bazel run //cmd/bb_clientd $(bazel info workspace)/configs/bb_clientd.jsonnet
```
Expand Down Expand Up @@ -118,7 +119,7 @@ bazel build --remote_executor mycluster-prod.example.com --remote_instance_name
You can let it use bb\_clientd by running it like this instead:

```
bazel build --remote_executor unix:${HOME}/.cache/bb_clientd/grpc --remote_instance_name mycluster-prod.example.com/hello [more options]
bazel build --remote_executor unix:${XDG_CACHE_HOME:-~/.cache}/bb_clientd/grpc --remote_instance_name mycluster-prod.example.com/hello [more options]
```

Notice how the hostname of the cluster has become a prefix of
Expand All @@ -130,9 +131,9 @@ traffic needs to be routed.
You may wish to add `--remote_bytestream_uri_prefix` to the `bazel build`
command with the URI of the _real_ remote executor. This will cause Bazel's
build event stream to emit URIs with this prefix rather than
`${HOME}/.cache/bb_clientd/grpc`. Some build event consumers offer features
that require access to the remote cache; this is necssary for those features
to access the canonical remote.
`${XDG_CACHE_HOME:-~/.cache}/bb_clientd/grpc`. Some build event
consumers offer features that require access to the remote cache; this
is necssary for those features to access the canonical remote.

### ... as a system local cache

Expand All @@ -142,7 +143,7 @@ name acts as its own namespace. This means that if you want to cache the
results of a build performed locally, you may run Bazel as follows:

```
bazel build --remote_cache unix:${HOME}/.cache/bb_clientd/grpc --remote_instance_name local/some/project --remote_upload_local_results=true [more options]
bazel build --remote_cache unix:${XDG_CACHE_HOME:-~/.cache}/bb_clientd/grpc --remote_instance_name local/some/project --remote_upload_local_results=true [more options]
```

The advantage of this option over Bazel's own `--disk_cache` flag is
Expand Down Expand Up @@ -256,5 +257,5 @@ Bazel can be configured to use this feature by providing the following
additional command line arguments:

```
--experimental_remote_output_service unix:${HOME}/.cache/bb_clientd/grpc --experimental_remote_output_service_output_path_prefix ${HOME}/bb_clientd/outputs
--experimental_remote_output_service unix:${XDG_CACHE_HOME:-~/.cache}/bb_clientd/grpc --experimental_remote_output_service_output_path_prefix ${HOME}/bb_clientd/outputs
```
9 changes: 4 additions & 5 deletions configs/bb_clientd.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ local blobstoreConfig(authorizationHeader, proxyURL) = {
};

local os = std.extVar('OS');
local homeDirectory = std.extVar('HOME');
local cacheDirectory = homeDirectory + '/.cache/bb_clientd';
local cacheDirectory = std.extVar('XDG_CACHE_HOME') + '/bb_clientd';

{
// Options that users can override.
Expand Down Expand Up @@ -184,8 +183,9 @@ local cacheDirectory = homeDirectory + '/.cache/bb_clientd';
// The FUSE or NFSv4 file system through which data stored in the
// Content Addressable Storage can be loaded lazily. This file system
// relies on credentials captured through gRPC.
mount: if $.useNFSv4 then {
mountPath: homeDirectory + '/bb_clientd',
mount: {
mountPath: std.extVar('HOME') + '/bb_clientd',
} + if $.useNFSv4 then {
nfsv4: {
enforcedLeaseTime: '120s',
announcedLeaseTime: '60s',
Expand All @@ -195,7 +195,6 @@ local cacheDirectory = homeDirectory + '/.cache/bb_clientd';
Linux: { linux: { mountOptions: ['vers=4.1'] } },
}[os],
} else {
mountPath: homeDirectory + '/bb_clientd',
fuse: {
directoryEntryValidity: '300s',
inodeAttributeValidity: '300s',
Expand Down
11 changes: 6 additions & 5 deletions configs/linux/launch_bb_clientd_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ set -eu
fusermount -u ~/bb_clientd || true

# Remove UNIX socket, so that builds will not attept to send gRPC traffic.
rm -f ~/.cache/bb_clientd/grpc
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-~/.cache}
rm -f ${XDG_CACHE_HOME}/bb_clientd/grpc

if [ "$1" = "start" ]; then
# Create directories that are used by bb_clientd.
mkdir -p \
~/.cache/bb_clientd/ac/persistent_state \
~/.cache/bb_clientd/cas/persistent_state \
~/.cache/bb_clientd/outputs \
${XDG_CACHE_HOME}/bb_clientd/ac/persistent_state \
${XDG_CACHE_HOME}/bb_clientd/cas/persistent_state \
${XDG_CACHE_HOME}/bb_clientd/outputs \
~/bb_clientd

# Discard logs of the previous invocation.
rm -f ~/.cache/bb_clientd/log
rm -f ${XDG_CACHE_HOME}/bb_clientd/log

# Use either the user provided or system-wide configuration file, based
# on whether the former is present.
Expand Down

0 comments on commit ab3b694

Please sign in to comment.