-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Support workspace label prefixes in Starlark config and platform APIs #11128
Comments
Also #10118. |
#11734 is a similar issue in aspects. |
@juliexxia - can you advise on how much of this issue is still relevant? |
With 3.7, our experience with this is mostly the same as what's described in #9177, except Bazel no longer crashes, instead, the flag doesn't seem to take effect when it's prefixed with the workspace id. Interestingly, when I run these two commands (within the example in #9177), it seems like the prefixed and non-prefixed versions are being treated as separate, but still work : > bazel build //:my_drink --//:favorite_flavor=True
DEBUG: .../tmp/bazel-user-settings-example/rules.bzl:5:14: Get the opposite of default (True)
...
INFO: Build completed successfully, 1 total action
> bazel build //:my_drink --@bsws//:favorite_flavor=True
INFO: Build options --//:favorite_flavor and --@bsws//:favorite_flavor have changed, discarding analysis cache.
DEBUG: .../tmp/bazel-user-settings-example/rules.bzl:7:14: Get the default (False)
...
INFO: Build completed successfully, 1 total action Referencing build settings from external WORKSPACEs (#9177 (comment)) seems to work well. |
I am experiencing the same behavior when it comes to using the flags in Bazel transitions. For a WORKSPACE file defined as
Then setting |
@stefanbucur would you mind writing out a full command line/transition for the scenarios you describe here? From my own testing I believe settings --@my_workspace//:my_flag and //:my_flag from inside that workspace successfully resolve to a single flag. |
@juliexxia @stefanbucur I've modified #10499 into the following:
Running Bazel 3.7.0 gives:
|
The general issue here seems to be that starlark options parsing and transitions aren't recognizing //:my_flag and @my_workspace//:my_flag as the same label. This should be easy to fix during starlark options parsing - then in the command line you provided --@my_workspace//:my_flag=bar will simply overwrite --//:my_flag=foo and leave a configuration of //:my_flag=bar Fixing this in transitions will take a little more digging. I'll keep looking. |
@moroten to confirm re: the transition issue. There's nothing that you want to do but can't right? Using the non-workspace-prefixed version of //:my_flag in the transition works fine, just using @my_workspace//:my_flag doesn't do what's expected, is that correct? |
We have worked around by avoiding user flags and settings in the main workspace. Instead, we have |
That sounds reasonable to me. Out of curiosity, why did y'all chose that instead of keeping flags in the main workspace and always referring to them in transitions/bazelrc without the repo name attached? //:my_flag should infer @//:my_flag aka the main workspace. Did y'all try that and it didn't work or did you just avoid it due to the confusion described in this issue? |
In our case, the reason is that the transition and the build configuration flags are part of a library that is meant to be used in other projects: https://github.com/bazelbuild/rules_fuzzing (more precisely, the code is still under review here: bazel-contrib/rules_fuzzing#86) To simplify the specification of these flags on the command line, we encourage users to define their values as Inside the transition implementation, it also wasn't clear to me how Bazel would interpret a |
It turns out that the configuration flag does get interpreted in the context of the top-level workspace, so a rules repository library defining a transition on a configuration flag must reference that flag using the repository name. This means that our own If this is intended behavior, does it mean that a rules library offering configuration flags must always be imported using the name matching the hard-coded repo name used in transitions? |
Somewhat related to this discussion, I discovered another weird behavior. For label-typed flags (the In our case, we use a label flag to control a cc_library dependency in a cc_test rule. Setting that flag with the repo name prefix has no effect - the dependency is left to its default value. Not sure if this is a separate issue or a manifestation of the same underlying issue. |
…and line as --@main_workspace//flag and --//flag will both parse to --//flag. Before this CL, the former maintained its workspace prefix and we would get different entries for these two formats. work towards #11128 PiperOrigin-RevId: 350575360
…dConfigTransition so we can use it here and in FunctionTransitionUtil going forward work towards #11128 PiperOrigin-RevId: 350588700
…ll stack in order to canonicalize. There are 5 locations a user might write the label string of a build setting: (1) on the command line (2) in the transition definition inputs (3) in the transition definition output (4) in the transition impl function while reading the settings dict (5) in the transition impl function return dict We know that, depending on the situation, there are multiple ways to write "a build setting in the main repo of this project" - //myflag, @//myflag, @main_repo//my:flag. In all 5 places listed above, bazel needs to recognize that the three different versions of //myflag above all map back to a single target. We need this for deduping purposes and consistency. 1 is taken care of in a grandparent CL to this CL. This Cl addresses locations 2-5. To do this, whenever we are interpreting a user's input at one of the locations above, we covert that input string to the canonical string form of that build setting for our back end book keeping purposes. The logic to do this was modeled off of the `Label()` function logic. We also keep a map of canonicalized form to the user-given form in order to display messages (or key the dict in 4) to the user using the forms of the flags they used themselves. work towards #11128 PiperOrigin-RevId: 351426279
These should all be fixed as of this most recent commit. |
…and line as --@main_workspace//flag and --//flag will both parse to --//flag. Before this CL, the former maintained its workspace prefix and we would get different entries for these two formats. work towards bazelbuild#11128 PiperOrigin-RevId: 350575360
…and line as --@main_workspace//flag and --//flag will both parse to --//flag. Before this CL, the former maintained its workspace prefix and we would get different entries for these two formats. work towards bazelbuild#11128 PiperOrigin-RevId: 350575360
This is a catch-all to focus the common theme of:
string_flag
settings in external repositories #10152 (fixed)At the narrowest this may require unrelated fixes to
build_setting
and toolchain resolution logic. But the general theme of the problem is clear, however the fixes are made.We're (Bazel configurability) trying to prioritize this for the current quarter.
The text was updated successfully, but these errors were encountered: