bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.27k stars 4.08k forks source link

Allow empty configurations in .bazelrc #12844

Open aherrmann opened 3 years ago

aherrmann commented 3 years ago

Description of the feature request:

Allow users to define empty configurations for the --config flag in .bazelrc. E.g. the following should work without error:

.bazelrc:

common:foo
$ bazel build --config=foo //...

Currently, this will fail with the following error message:

ERROR: Config value 'foo' is not defined in any .rc file

Feature requests: what underlying problem are you trying to solve with this feature?

For some projects it is useful to expose a set of --config options as a stable interface. E.g. rules_haskell exposes a set of configuration options to define the platform and build configuration (linux-bindist, linux-nixpkgs, macos-bindist, macos-nixpkgs, windows-bindist).

However, there is no way to declare such a stable set of configuration options independent of the corresponding configuration options. Meaning, if a configuration happens to be empty, even just for some commands, then it cannot be defined or enabled.

For example, I would like to be able to declare the following in the rules_haskell:

common:linux-nixpkgs
common:linux-bindist
common:macos-nixpkgs
common:macos-bindist
common:windows-bindist

To ensure that the corresponding --config options work for every command.

What operating system are you running Bazel on?

Ubuntu 20.10

What's the output of bazel info release?

release 3.7.2

gregestren commented 3 years ago

This sounds reasonable.

I believe the solution requires:

  1. Update https://github.com/bazelbuild/bazel/blob/8346ea4cfdd9fbd170d51a528fee26f912dad2d5/src/main/cpp/rc_file.h (the parser for bazelrc files) to include entries for empty keys. This may require some special null value representation.
  2. This is used in https://github.com/bazelbuild/bazel/blob/8346ea4cfdd9fbd170d51a528fee26f912dad2d5/src/main/cpp/option_processor.cc#L686 to auto-set the --default_override build flag.
  3. Bazel consumes that at https://github.com/bazelbuild/bazel/blob/8346ea4cfdd9fbd170d51a528fee26f912dad2d5/src/main/java/com/google/devtools/build/lib/runtime/ClientOptions.java#L126.
  4. This is used at https://github.com/bazelbuild/bazel/blob/a16183933c59e00446da748f1af294eb93f37737/src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java#L236 and https://github.com/bazelbuild/bazel/blob/a16183933c59e00446da748f1af294eb93f37737/src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java#L255 to ultimately expand each --config.

So basically have the C++ bazelrc parser include entries for zero-valued --configs. Then have the Java consumer recognize that and skip https://github.com/bazelbuild/bazel/blob/199e70c11716cccf098f06b50c98d4f44df08b53/src/main/java/com/google/devtools/build/lib/runtime/ConfigExpander.java#L265-L267 for those cases.

I'd be happy to review anyone who wants to put up a PR.

dfreese commented 2 years ago

Ran into this as well. Surprisingly, this, at a minimum, ran:

build:foo --

I can only imagine that causing any number of problems, though, lol.

pauldraper commented 2 years ago

The workaround is to add a noop flag.

The one that I use:

common:myconfig --announcerc=false
github-actions[bot] commented 1 year ago

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 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

aherrmann commented 1 year ago

@bazelbuild/triage not stale

github-actions[bot] commented 3 months ago

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.

fishy commented 1 month ago

--announcerc=false is no longer available on bazel 7.3.2. Looking at the current output of bazel help build and bazel help run I picked --show_progress as the noop flag (that's already the default and unlikely to change any time soon).

But would love to just be allowed to define empty config instead.