diff --git a/README.md b/README.md index fc5ea48..5f00e4b 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 @@ -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 @@ -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 @@ -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 ``` diff --git a/configs/bb_clientd.jsonnet b/configs/bb_clientd.jsonnet index bd4e79c..301da71 100644 --- a/configs/bb_clientd.jsonnet +++ b/configs/bb_clientd.jsonnet @@ -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. @@ -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', @@ -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', diff --git a/configs/linux/launch_bb_clientd_linux.sh b/configs/linux/launch_bb_clientd_linux.sh index 37a8b2e..5117953 100644 --- a/configs/linux/launch_bb_clientd_linux.sh +++ b/configs/linux/launch_bb_clientd_linux.sh @@ -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.