[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: Fabian Meumertzheim <fabian@meumertzhe.im>
68 files changed
tree: 59f9c4b33a0dec694ffd8f84010c4ab862f933f7
  1. .bazelci/
  2. .github/
  3. examples/
  4. scripts/
  5. site/
  6. src/
  7. third_party/
  8. tools/
  9. .bazelrc
  10. .bazelversion
  11. .gitattributes
  12. .gitignore
  13. AUTHORS
  14. BUILD
  15. CHANGELOG.md
  16. CODE_OF_CONDUCT.md
  17. CODEOWNERS
  18. combine_distfiles.py
  19. combine_distfiles_to_tar.sh
  20. compile.sh
  21. CONTRIBUTING.md
  22. CONTRIBUTORS
  23. distdir.bzl
  24. distdir_deps.bzl
  25. LICENSE
  26. MODULE.bazel
  27. README.md
  28. SECURITY.md
  29. WORKSPACE
  30. WORKSPACE.bzlmod
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Reporting a Vulnerability

To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.

Contributing to Bazel

See CONTRIBUTING.md

Build status