Open tomtseng opened 4 years ago
I think this is a duplicate of another request for mapping short flag names to starlark defined settings, but I can not find it, so I won't close it today.
@juliexxia Do you know what this is a duplicate of?
There's an admittedly non-obvious nuance that makes it impossible to directly support --config
.
config_setting
by its definition can only affect flags that are part of the build's configuration. But not every Bazel flag is a part of the configuration. For example, --verbose_explanations
or --spawn_strategy
.
--config
is an expansion flag that can expand to arbitrary other flags of any type. We could conceivably have config_setting
capture the filtered set of --config
values that are part of the configuration. But I don't think that's particularly sound.
Yes, it sounds like I'm overloading a bunch of terms that all sound the same. Apologies for that. :/
The best followup is to document the status quo. I agree your workaround is the best solution.
👍 sounds good, thanks!
This would be good to have in https://docs.bazel.build/versions/master/configurable-attributes.html#faq, and maybe also https://docs.bazel.build/versions/master/be/general.html#config_setting.
(Context: I'm moving on from Bazel on friday and spending some time triaging all bugs assigned to me before unassigning myself)
Was originally assigned to me because it might be related to starlark shorthand aliases but I don't think it actually is. I agree, doc updates are what's needed.
config_setting
by its definition can only affect flags that are part of the build's configuration. But not every Bazel flag is a part of the configuration. For example,--verbose_explanations
or--spawn_strategy
.
this part is the part I find most confusing since it's hard to distinguish what falls to the build options category.
I agree. At the very least this part of the docs needs some kind of redesign to express this.
You could play with bazel config
to surface this information. But that's an advanced developer tool so I don't recommend it for anyone casually browsing through the issue.
Description of the problem / feature request:
The documentation on configuration attributes suggests that
config_setting()
should be able to match on any Bazel flag, e.g.,--copt
or--cpu
. However, it fails to match on--config
.My use case: I am contributing to a project with several existing
--config
options, and I want to set build rules based on what--config
options are set.Example
Put the following in a
BUILD
file:Then run
bazel build :my_binary
(orbazel build :my_binary --config=foo
). The following error results:Workaround
This is a minor issue because there's a workaround with an additional step of indirection. Add something like this to the
.bazelrc
:and change the
config_setting
in the BUILD toI wasted some time mucking around in documentation for defining custom flags, however, before a colleague suggested this workaround. Hence it may be appropriate to either add support for matching on
--config
or to explicitly mention in the documentation thatconfig_setting()
will not match on--config
.What operating system are you running Bazel on?
Ubuntu 18.04
What's the output of
bazel info release
?release 3.2.0
Have you found anything relevant by searching the web?
Didn't see anything related on StackOverflow, GitHub issues, or on bazel-discuss.