Convert BuildType.SelectorList back to SelectorList in native.existing_rules

(Attempt two.)

This allows a round-trip like:

```
some_rule(
   ...
   deps = native.existing_rule(...)["deps"],
   ...
)
```

(native.existing_rule / native.existing_rules is disfavored, it's brittle and order-dependent. Prefer using a Starlark macro that creates the original target and related targets at the same time.)

When traversing the struct recursively, starlarkifyValue converts List into Tuple (though maybe StarlarkList would be more idiomatic) and Label into the corresponding str. So the select may not be exactly as input, but the meaning is preserved.

The logic for StarlarkValue is moved down because SelectorList is a StarlarkValue, so the more specific case needs to be handled first.

This change is not strictly backward-compatible because it changes the type and `repr` of these values, e.g. you can have something like:

```
if type(native.existing_rule(...)[...]) == "SelectorList":
  # Something broken that wasn't previously executed
```

Logic like this can be updated to use "select" instead of "SelectorList". (Or, if it was specifically working around the issue that SelectorList values can't be used as rule inputs, the workaround can be removed.)

RELNOTES[INC]: native.existing_rule now returns select values in a form that is accepted by rule instantiation. This is a breaking API change because there is some code that relies on the precise type returned, including brittle workarounds for this bug specifically and insufficiently flexible workarounds for other issues with the intersection of select and native.existing_rule.

PiperOrigin-RevId: 350180297
3 files changed
tree: 26ff1a4c7a91888842b31389ab8ca746544e8ae7
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEBASE.md
  15. CODEOWNERS
  16. combine_distfiles.py
  17. combine_distfiles_to_tar.sh
  18. compile.sh
  19. CONTRIBUTING.md
  20. CONTRIBUTORS
  21. distdir.bzl
  22. distdir_deps.bzl
  23. ISSUE_TEMPLATE.md
  24. LICENSE
  25. README.md
  26. WORKSPACE
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

Contributing to Bazel

See CONTRIBUTING.md

Build status