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

--config in .bazelrc doesn't appear to follow build to test inheritance #15845

Open
srdo-humio opened this issue Jul 8, 2022 · 3 comments
Open
Labels
awaiting-user-response Awaiting a response from the author stale Issues or PRs that are stale (no activity for 30 days) team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug

Comments

@srdo-humio
Copy link

Description of the bug:

We are using a config flag (--config=ci) to override some defaults from the workspace-level .bazelrc on CI. We set this on CI in the home ~/.bazelrc as build --config=ci.

We are seeing Bazel pick defaults instead of overrides when the command being run is bazel test. It works as expected with bazel build. Switching the command in ~/.bazelrc to test also works as expected.

We have a minimal reproducer described below.

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

WORKSPACE:

Empty

BUILD.bazel:

genrule(
    name = "demo",
    outs = ["hello.txt"],
    cmd_bash = "echo 'hello' > $@"
)

.bazelrc (workspace level):

test --color=no
test:ci --color=yes

~/.bazelrc (home directory):

build --config=ci

Run bazel test demo. Colors are disabled. We expected colors to be on, since test inherits from build, and --config=ci is set for build, and the workspace level RC file enables colors for test when --config=ci is enabled.

Workarounds

  • Changing build to test in the home .bazelrc, or just setting the config for both build and test.
  • Setting --config=ci explicitly when invoking Bazel.
  • Changing test to build in the workspace .bazelrc and running build instead also causes colors to be enabled.

Which operating system are you running Bazel on?

MacOS Monterey

What is the output of bazel info release?

6.0.0-pre.20220608.2

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 master; git rev-parse HEAD ?

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

@aranguyen
Copy link
Contributor

With inheritance, precedence depends on specificity. Commands such as test and release inherit flags from build. The inheriting command is said to be more specific and thus the associated flags take precedence https://docs.bazel.build/versions/main/guide.html#bazelrc-syntax-and-semantics. So in this case because you have test --color=no and test is more specific than build, test --color=no always take precedence over your build --config=ci.

What were you trying to achieve with defining a test config test:ci and use it for build? Why not defining a build config and let inheritence takes place when testing? This is your workaround 3.

@aranguyen aranguyen added awaiting-user-response Awaiting a response from the author and removed untriaged labels Jul 29, 2022
@srdo-humio
Copy link
Author

@aranguyen The above is simplified to show the slightly odd behavior. Our actual use case for this was this:

When doing local development, we wanted --test_output=errors configured for our devs. When running on CI, we wanted --test_output=all instead. We attempted to do this by having the following lines in .bazelrc in the project root:

test --test_output=errors
test:ci --test_output=all

On CI, rather than adding --config=ci to every command, we thought we'd just write a home-dir .bazelrc before starting the build, containing

build --config=ci

This turned out to not work. Running bazel test someTarget on CI would use the errors-only output. In order to fix it, we needed to change the CI .bazelrc to say

build --config=ci
test --config=ci

Since the docs say the home .bazelrc is interpreted before the project-level .bazelrc, I expected something like this order:

# home bazelrc
build --config=ci # 1: CI config is enabled for test immediately due to inheritance

# project-level bazelrc
test --test_output=errors # 2: This line is applied
test:ci --test_output=all # 3: Since CI config is enabled, this line is applied, overriding step # 2.

If I understand you correctly, Bazel instead does something like this:

# home bazelrc
build --config=ci # 1: Not immediately applied, since we are running "test" and not "build"

# project-level bazelrc
test --test_output=errors # 2: Output is set to error since we are running "test"
test:ci --test_output=all # 3: Since CI config is not enabled, this line is skipped

# home bazelrc
build --config=ci # 4: Applied due to inheritance

@gregestren gregestren added team-Core Skyframe, bazel query, BEP, options parsing, bazelrc and removed team-Configurability Issues for Configurability team labels Feb 15, 2023
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-user-response Awaiting a response from the author stale Issues or PRs that are stale (no activity for 30 days) team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug
Projects
None yet
Development

No branches or pull requests

4 participants