Add --consistent_labels flag to all query commands#19508
Add --consistent_labels flag to all query commands#19508fmeum wants to merge 1 commit intobazelbuild:masterfrom
--consistent_labels flag to all query commands#19508Conversation
33d8b60 to
72b8dc9
Compare
|
@gregestren @Wyverald This doesn't have tests yet. I would first like to confirm the approach taken by this PR as well as testing strategies. |
77b7817 to
d8787fc
Compare
c14ecd5 to
57e5f14
Compare
|
To fix #18543, I was thinking that I'd change |
|
I chatted with @Wyverald for some basic context. I'm still not sure I understand the argument for *query-based Starlark output looking different than other Starlark output? And the ultimate relationship between Starlark-formatted *query output and non-Starlark *query output? |
But doesn't that run into the problem that It would affect this PR in that it would allow us to get rid of the |
I think it's fine as the |
There is no argument for that, that's simply a bug. See my other PR in which I wire up the correct StarlarkSemantics with
With this commit and the flag enabled, they would become identical, which is very useful for any kind of tooling. But that requires e.g. regular query output to be of the form |
I would be a huge fan of that change, but I so far didn't consider it possible: It is probably very breaking towards any kind of tooling, so to roll it out in Bazel 7 we would probably need a flag. Since If you think that this can work, I am all for it. Even with this PR cleaning up all query variants, there are many other places in Bazel that will still emit unusable label if we don't change |
|
Yes I somehow forgot that Google exists :P. Make that "use |
Wyverald
left a comment
There was a problem hiding this comment.
overall LGTM. we should have (not a lot of) time to get this in for 6.4.0
| * com.google.devtools.build.lib.query2.common.CommonQueryOptions#getLabelPrinter(StarlarkSemantics, | ||
| * RepositoryMapping)} instead. | ||
| */ | ||
| static LabelPrinter canonical(StarlarkSemantics starlarkSemantics) { |
There was a problem hiding this comment.
I think I'd prefer to call this starlark or something (and in the same vein, call the other displayForm). canonical could sometimes output "apparent" labels (ie. with bzlmod off) and apparent, canonical labels (ie. when not visible to main repo).
|
|
||
| @Override | ||
| public String toString(PackageIdentifier packageIdentifier) { | ||
| // This is adapted from the implementation of Label#str. |
There was a problem hiding this comment.
WDYT about just doing toString(Label.create(packageIdentifier, "DUMMY")).substring(0, -6)? (imaginary support for "-6" aside)
It avoids the code duplication and makes this much more easily maintainable, at the cost of a not-very-palatable runtime trick (which is presumably not a big deal since how often do we stringify PackageIdentifiers?)
57e5f14 to
e8ff2b0
Compare
--canonical_labels flag to all query commands--consistent_labels flag to all query commands
e8ff2b0 to
947791c
Compare
If enabled, labels are emitted as if by the Starlark `str` function applied to a `Label` instance. This is useful for tools that need to match the output of different query commands and/or labels emitted by rules. If not enabled, output formatters are free to emit apparent repository names (relative to the main repository) instead to make the output more readable.
947791c to
56bd5f4
Compare
Wyverald
left a comment
There was a problem hiding this comment.
the changes look good. I'm iffy about the flag name --consistent_labels but I don't have a better idea, so unless @gregestren suggests otherwise, I say we merge this.
|
@bazel-io fork 6.4.0 |
|
@gregestren @Wyverald @fmeum looks like one of the tests is failing. I've tried a couple times. Can you please take a look? |
|
The failure is: This does look like an infrastructure problem to me, but it's surprising that it is persistent. |
|
yeah I retried it yesterday and it was persistent too. I've asked Ian to try importing it anyway and see if the test fails there too. |
If enabled, labels are emitted as if by the Starlark `str` function applied to a `Label` instance. This is useful for tools that need to match the output of different query commands and/or labels emitted by rules. If not enabled, output formatters are free to emit apparent repository names (relative to the main repository) instead to make the output more readable. This is implemented by replacing all `Label#toString()` calls in query code with an indirection through a `LabelPrinter` object constructed in a central place. There are currently three types of instances: * `canonical` behaves just like `str(Label(...))`; * `apparent` matches the current behavior, which renders main repo labels in repo-relative form and attempts to use the apparent names for external repos if possible; * `legacy` is used in all non-query callsites and uses `Label#toString()`. Fixes #17864 RELNOTES: The new `--consistent_labels` option on `query`, `cquery`, and `aquery` can be used to force consistent label formatting across all output modes that is also compatible with `str(Label(...))` in Starlark. Closes #19508. PiperOrigin-RevId: 566723654 Change-Id: Ifa08a82e281f423faa971c46bf7277cb307698b5
If enabled, labels are emitted as if by the Starlark `str` function applied to a `Label` instance. This is useful for tools that need to match the output of different query commands and/or labels emitted by rules. If not enabled, output formatters are free to emit apparent repository names (relative to the main repository) instead to make the output more readable. This is implemented by replacing all `Label#toString()` calls in query code with an indirection through a `LabelPrinter` object constructed in a central place. There are currently three types of instances: * `canonical` behaves just like `str(Label(...))`; * `apparent` matches the current behavior, which renders main repo labels in repo-relative form and attempts to use the apparent names for external repos if possible; * `legacy` is used in all non-query callsites and uses `Label#toString()`. Fixes #17864 RELNOTES: The new `--consistent_labels` option on `query`, `cquery`, and `aquery` can be used to force consistent label formatting across all output modes that is also compatible with `str(Label(...))` in Starlark. Closes #19508. PiperOrigin-RevId: 566723654 Change-Id: Ifa08a82e281f423faa971c46bf7277cb307698b5 --------- Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
If enabled, labels are emitted as if by the Starlark
strfunction applied to aLabelinstance. This is useful for tools that need to match the output of different query commands and/or labels emitted by rules. If not enabled, output formatters are free to emit apparent repository names (relative to the main repository) instead to make the output more readable.This is implemented by replacing all
Label#toString()calls in query code with an indirection through aLabelPrinterobject constructed in a central place. There are currently three types of instances:canonicalbehaves just likestr(Label(...));apparentmatches the current behavior, which renders main repo labels in repo-relative form and attempts to use the apparent names for external repos if possible;legacyis used in all non-query callsites and usesLabel#toString().Fixes #17864
RELNOTES: The new
--consistent_labelsoption onquery,cquery, andaquerycan be used to force consistent label formatting across all output modes that is also compatible withstr(Label(...))in Starlark.