Support repeated flags in platform mappings and platform-based flags
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
This was discovered while implementing platform-based flags, #19409. Since this uses the same [`BuildOptions.applyParsingResult`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/config/BuildOptions.java?q=symbol%3A%5Cbcom.google.devtools.build.lib.analysis.config.BuildOptions.applyParsingResult%5Cb%20case%3Ayes) method as platform mappings, the same issue applies to both.
A quick definition: a repeatable flag is a flag where repeated uses accumulate, instead of overwriting. This corresponds to using [`@Option.allowMultiple`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/common/options/Option.java?q=symbol%3A%5Cbcom.google.devtools.common.options.Option.allowMultiple%5Cb%20case%3Ayes) in a native flag or defining a Starlark flag using [`config.string_list(repeatable = True)`](https://bazel.build/rules/lib/toplevel/config#string_list.repeatable). Commonly used flags that use this are `--features` and `--copt`.
Currently, any repeatable flags used in platform mapping or platform based flags will overwrite any previous values. If any platforms set the `--features` flag, for example, this will remove any values set on the command line.
Ideally we would either intelligently merge these, or at least warn users that it happens.
There are example tests that show the error: https://github.com/bazelbuild/bazel/pull/22386 (see errors: https://buildkite.com/bazel/bazel-bazel-github-presubmit/builds/21626).
This is a tracking issue for dealing with this.
Contributor guide
Research direction
Start with BuildOptions.applyParsingResult in src/main/java/com/google/devtools/build/lib/analysis/config/BuildOptions.java and review the repeatable-flag behavior described in the example tests from PR #22386. Compare handling for platform mappings and platform-based flags, then use those tests to verify that repeated values no longer overwrite command-line values or that users receive an appropriate warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100