bazelbuild / bazelbuild/bazel

Issues setting --output_user_root to a relative path

Open
#25,210 1 comment 0 reactions 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

I would like to have Bazel create its output_user_root ("build directory") under the source tree so that the build directories are clearly separated by project, so I created a `~/.bazelrc` file that looks like this:
```
startup --output_user_root=out
```
However, if I do this I encounter the following issues:
1. `bazel build //...` attempts to descend into the build directory, and it seems to start considering the contents of the various modules checked out in the build directory to be part of the main project. This leads to errors such as:
```
ERROR: Skipping '//...': error loading package under directory '': error loading package 'out/75b790c096b4cf839d824389bb5a7120/install/rules_java/toolchains': at /mnt/disk2/pcc/bazel/out/75b790c096b4cf839d824389bb5a7120/install/rules_java/toolchains/default_java_toolchain.bzl:17:6: Label '//java:defs.bzl' is invalid because 'java' is not a package; perhaps you meant to put the colon here: '//:java/defs.bzl'?
ERROR: error loading package under directory '': error loading package 'out/75b790c096b4cf839d824389bb5a7120/install/rules_java/toolchains': at /mnt/disk2/pcc/bazel/out/75b790c096b4cf839d824389bb5a7120/install/rules_java/toolchains/default_java_toolchain.bzl:17:6: Label '//java:defs.bzl' is invalid because 'java' is not a package; perhaps you meant to put the colon here: '//:java/defs.bzl'?
```
2. If I build from a subdirectory, another `out` directory is created in the current directory instead of reusing the one in the project root.

It seems that the following fixes are needed:
1. Do not descend into the `--output_user_root` when evaluating a build target.
2. If a relative path is specified to `--output_user_root` it should be interpreted relative to the project root.

### Which category does this issue belong to?

CLI

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

1. Check out any project that uses Bazel (e.g. Bazel itself).
2. `bazel --output_user_root=out build //...`
3. `cd src` (or any project subdirectory)
4. `bazel --output_user_root=out build //...`

### Which operating system are you running Bazel on?

Linux

### What is the output of `bazel info release`?

release 8.0.1

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

_No response_

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

```text
https://github.com/bazelbuild/bazel
07dfb112c27d7ac5f0b190b17864ce8f0b6f996e
```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

_No response_

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

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the behavior with `bazel --output_user_root=out build //...`, then repeat from `src` and compare the workspace roots used. Read the `--output_user_root` startup option and the `bazel build //...` workspace evaluation entry points mentioned in the report. Done means the output directory is excluded from target discovery and a relative path is resolved from the project root.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.