Skip to content
Snippets Groups Projects
Unverified Commit 2f75f30f authored by Xùdōng Yáng's avatar Xùdōng Yáng Committed by GitHub
Browse files

[6.4.0] Add `--consistent_labels` flag to all query commands (#19567)


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: default avatarFabian Meumertzheim <fabian@meumertzhe.im>
parent ec8c12da
Showing
with 287 additions and 67 deletions
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment