Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel doesn't respect XDG_CACHE_HOME #16937

Closed
ebyrne242 opened this issue Dec 6, 2022 · 6 comments
Closed

Bazel doesn't respect XDG_CACHE_HOME #16937

ebyrne242 opened this issue Dec 6, 2022 · 6 comments
Assignees
Labels
area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug

Comments

@ebyrne242
Copy link

ebyrne242 commented Dec 6, 2022

Description of the bug:

Bazel writes caches, often many megabytes in size to $USER/.cache/bazel on Linux. It's common for users on NFS home dirs to set the XDG_CACHE_HOME environment variable to put their caches on a local disk instead. However, bazel ignores this variable and continues to write to ~/.cache/bazel.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

export XDG_CACHE_HOME=/tmp/$USER/bazel

build anything with bazel

bazel still writes output to ~/.cache/bazel

Which operating system are you running Bazel on?

CentOS 7.9

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

$ bazel info release

WARNING: Output base '/data/homes/nfs/home/user/.cache/bazel/_bazel_user/33181acb49c359f0b2bfbb3335eecb1f' is on NFS. This may lead to surprising failures and undetermined behavior.

release 5.3.2

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

Suggestions that TEST_TMPDIR is the only way to influence the output dir, along with suggestions it should not be used.

Any other information, logs, or outputs that you want to share?

No response

@ebyrne242 ebyrne242 changed the title Bazel doesn't respect XDG_CACHE_DIR Bazel doesn't respect XDG_CACHE_HOME Dec 6, 2022
@sgowroji
Copy link
Member

sgowroji commented Dec 7, 2022

Hello @sketch242, Could you please provide an example code to reproduce the above issue. Thanks !

@ebyrne242
Copy link
Author

ebyrne242 commented Dec 7, 2022

It's not code specific, you can use anything.

$ git clone https://github.com/bazelbuild/examples
Cloning into 'examples'...
remote: Enumerating objects: 1995, done.
remote: Counting objects: 100% (600/600), done.
remote: Compressing objects: 100% (410/410), done.
remote: Total 1995 (delta 219), reused 441 (delta 147), pack-reused 1395
Receiving objects: 100% (1995/1995), 542.98 KiB | 7.87 MiB/s, done.
Resolving deltas: 100% (763/763), done.
$ cd examples/cpp-tutorial/stage1/
$ export $XDG_CACHE_HOME=/data/cache/user
$ readlink -m $HOME
/data/homes/nfs/home/user
$ rm -rf ~/.cache/bazel /data/cache/user/bazel
$ bazel build //main:hello-world
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Analyzed target //main:hello-world (37 packages loaded, 163 targets configured).
INFO: Found 1 target...
Target //main:hello-world up-to-date:
  bazel-bin/main/hello-world
INFO: Elapsed time: 6.790s, Critical Path: 0.35s
INFO: 6 processes: 4 internal, 2 processwrapper-sandbox.
INFO: Build completed successfully, 6 total actions
$ ls -ld/data/cache/user/bazel/
ls: cannot access /data/cache/user/bazel/: No such file or directory
$ ls -ld /data/homes/nfs/home/user/.cache/bazel/_bazel_user/8fb73c6900510c4b2c71adc08d4544df
drwxr-xr-x. 6 user users 4096 Dec  7 13:10 /data/homes/nfs/home/user/.cache/bazel/_bazel_user/8fb73c6900510c4b2c71adc08d4544df

@sgowroji sgowroji added type: bug team-Configurability platforms, toolchains, cquery, select(), config transitions untriaged and removed more data needed labels Dec 8, 2022
@aiuto aiuto added area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling and removed team-Configurability platforms, toolchains, cquery, select(), config transitions labels Jan 11, 2023
@tetromino tetromino self-assigned this Mar 11, 2024
@tetromino
Copy link
Contributor

We should fix this.

@tetromino
Copy link
Contributor

... and until this is fixed, as a workaround, you can do bazel --output_user_root=/tmp/$USER/bazel build ... - see https://bazel.build/remote/output-directories#layout

@Wyverald
Copy link
Member

@bazel-io fork 7.2.0

@Wyverald Wyverald added P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website and removed untriaged labels Mar 11, 2024
tetromino added a commit to tetromino/bazel that referenced this issue Mar 26, 2024
… and BSD

It may well be that $HOME is on a read-only mount. In this case, it is the
convention in the Linux and BSD world that $XDG_CACHE_HOME points to an
appropriate writable location.

Fixes bazelbuild#16937

RELNOTES: Bazel on Linux and BSD now respects the XDG_CACHE_HOME environment
variable instead of assuming that ~/.cache/bazel is writable.
PiperOrigin-RevId: 614772057
Change-Id: I6377d7a90fb929843d18e82f5ed3d0adc55ac5c6
iancha1992 pushed a commit that referenced this issue Mar 26, 2024
…on Linux and BSD (#21817)

It may well be that $HOME is on a read-only mount. In this case, it is
the
convention in the Linux and BSD world that $XDG_CACHE_HOME points to an
appropriate writable location.

Fixes #16937

RELNOTES: Bazel on Linux and BSD now respects the XDG_CACHE_HOME
environment
variable instead of assuming that ~/.cache/bazel is writable.
PiperOrigin-RevId: 614772057
Change-Id: I6377d7a90fb929843d18e82f5ed3d0adc55ac5c6

Commit 05ae91f
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.2.0 RC1. Please test out the release candidate and report any issues as soon as possible.
If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.2.0rc1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug
Projects
None yet
Development

No branches or pull requests

6 participants