-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Description of the feature request:
When a project supports multiple Bazel versions, or is straddling two bazel versions during an upgrade, it can be tough to set flags that only exist in particular Bazel versions. This is because Bazel will (quite reasonably) fail with an error when given an unrecognized flag.
To address this, it would be much easier if the bazelrc syntax supported a way to only use lines for particular bazel versions. A couple proposals for addressing this:
(1) try-import-version $version_string $config_file Only import the named config file if the version string matches. e.g. try-import-version 7.4 %workspace%/bazel7.4.bazelrc
The nice thing about this is it could, if desired, later be expanded to have simple operators. e.g. try-import-version >=7 ...
(2a) if-supported <FLAGS> Similar to the common psuedo-command, a flag is only used if bazel recognizes it. e.g. if-supported --some-bazel-flag
The nice thing about this is it works by feature detection.
(2b) --undefok <flag> Similar to how --undefok works in absl: if the flag is recognized, parse it; if not, ignore it. e.g. common --undefok --someflag. This is often used so that flags can be set for programs before a flag is supported, which allows easier rollforward/rollback of binaries.
(3) --enable_bazel_version_specific_config When enabled, bazel automatically adds e.g. --config=bazel7.4 (but doesn't fail if no such config exists). This is similar to the --enable_platform_specific_config flag.
The nice thing about this is it fits neatly into the existing way rcs can include each other.
Which category does this issue belong to?
CLI
What underlying problem are you trying to solve with this feature?
Trying to manage bazelrc file while supporting multiple bazel versions.
Which operating system are you running Bazel on?
Multiple
What is the output of bazel info release?
7.3.2
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
n/a
What's the output of git remote get-url origin; git rev-parse HEAD ?
n/a
Have you found anything relevant by searching the web?
Some related prior art:
- common allowing unrecognized options: Fix
common.bazelrcbehavior for flag expansions #20720 - automatic host platform-specific flags: Allow platform-specific startup options #22763
- env vars in bazelrc: Use environment variables in .bazelrc via string interpolation #10904
Any other information, logs, or outputs that you want to share?
No response