bazelbuild / bazelbuild/bazel

Relative path for --output_base in .bazelrc resolves to %cwd% instead of %workspace_root%

Open
#15,137 7 comments 4 reactions 0 assignees View on GitHub
not stale P3 team-Core type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the problem:

I'd like to set the --output_base relative to the workspace directory. If I add "startup --output_base=../build" to the .bazelrc file in the root workspace directory I would expect one of the following behaviors:
1. Bazel would resolve the output_base path relative to the workspace directory ('%workspace_root%/../build) (behavior similar to how --experimental_downloader_config resolves the path).
2. Bazel would complain that relative paths are not supported in .bazelrc files.

But it seems that Bazel instead resolves the path relative to current working directory (%cwd%/../build).

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

Steps to reproduce:
1. Add: startup --output_base=../build to .bazelrc in root of workspace
2. bazel build //src:all
3. cd src;bazel build :all
4. Notice that two output folders are created (one in %workspace_root%/../build and one in %workspace_root%/build)

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

Fedora 34

### What's the output of `bazel info release`?

release 4.1.0

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

This discussion about the same issue: https://groups.google.com/g/bazel-discuss/c/aTcB9vmhYyQ

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

Probably this bug affects other startup options. A general strategy for handling relative paths in command line options should probably be considered. Some possible strategies:

1. Paths are always handled as relative to workspace root (this is how --experimental_downloader_config resolves the path).
2. Paths are handled relative to workspace root if specified in .bazelrc and relative to cwd if specified on command line.
3. Relative paths are not allowed in .bazelrc, but a %workspace% keyword can be used to specify paths relative to the workspace root.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the behavior using the .bazelrc startup --output_base=../build setting and the two build commands from the issue, first at the workspace root and then from src. Inspect how relative startup-option paths are resolved, including the comparison with --experimental_downloader_config. Done means the handling is consistent with an agreed strategy and the duplicate output directories no longer occur.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
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.