[8.9.0] Match automatic exec groups for aliased toolchain types (#32235) (#32471)

Automatic exec groups are named after the label that a rule used to
request a toolchain type. The `toolchain` parameter of `ctx.actions.run`
and `ctx.actions.run_shell`, its compatibility check with an explicit
`exec_group`, and the exec group selection of native C++ and Java
actions compared that name with the label they were given. For a
toolchain type requested through an alias, the label of the actual type
therefore didn't match, even though `ctx.toolchains` accepts both
labels.

All of these now find the automatic exec group in the same way as
`ctx.toolchains`, which accepts either the requested label or the label
of the actual type. To avoid parsing the label of the Java toolchain
type, `JavaSemantics.getJavaToolchainType()` now returns a `Label`.

Exec groups other than the default one can no longer have toolchain
types that are ignored if invalid. Only genrule's `toolchains` attribute
requests such types, and only for its default exec group, as genrule
doesn't use automatic exec groups. This ensures that the resolved
toolchain context of every other exec group lists all of its toolchain
types.

With `--incompatible_auto_exec_groups`, a rule that requests
`@rules_cc//cc:toolchain_type`, which is an alias of
`@bazel_tools//tools/cpp:toolchain_type`, and calls `cc_common.compile`
had its compile actions silently run in the default exec group instead
of the one of the C++ toolchain. Starlark actions that pass the label of
the actual type as `toolchain`, as rules_cc's link actions do, failed
with "Action declared for non-existent toolchain".

This is also needed to move toolchain types such as the C++ one out of
`@bazel_tools` with the old label becoming an alias: code that looks up
a toolchain by the label of the actual type then keeps working
regardless of the label the rule requested.

No

RELNOTES: None

Closes #32235


COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/bazel/pull/32235
from fmeum:auto-exec-group-toolchain-aliases
8b8c5e9d50cfe1d819ac763df5e56effc936a82c PiperOrigin-RevId: 1015003118
Change-Id: I44cb1c03c841f969c7eeeffea44ec1e6e8b9c92f

<!--
Thank you for contributing to Bazel!
Please read the contribution guidelines: https://bazel.build/contribute
and guidelines for AI-assisted contributions:
https://bazel.build/contribute/ai-assisted-contributions
-->

### Description
<!--
Please provide a brief summary of the changes in this PR.
-->

### Motivation
<!--
Why is this change important? Does it fix a specific bug or add a new
feature?
If this PR fixes an existing issue, please link it here (e.g. "Fixes
#1234").
-->

### Build API Changes
<!--
Does this PR affect the Build API? (e.g. Starlark API, providers,
command-line flags, native rules)
If yes, please answer the following:
1. Has this been discussed in a design doc or issue? (Please link it)
2. Is the change backward compatible?
3. If it's a breaking change, what is the migration plan?
-->

No

### Checklist

- [ ] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

<!--
If this is a new feature, please add 'RELNOTES[NEW]: <description>'
here.
If this is a breaking change, please add 'RELNOTES[INC]: <reason>' here.
If this change should be mentioned in release notes, please add
'RELNOTES: <reason>' here.
-->

RELNOTES: None

Commit
https://github.com/bazelbuild/bazel/commit/f698dfa8f609b661e781ceab0bf3dc296a17006e

---------

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
11 files changed
tree: 63b2d37894d8843e8b8c84c1cd8b60f290a16ab3
  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. bazel_downloader.cfg
  15. BUILD
  16. CHANGELOG.md
  17. CODE_OF_CONDUCT.md
  18. CODEOWNERS
  19. combine_distfiles.py
  20. combine_distfiles_to_tar.sh
  21. compile.sh
  22. CONTRIBUTING.md
  23. CONTRIBUTORS
  24. distdir.bzl
  25. extensions.bzl
  26. LICENSE
  27. maven_install.json
  28. MODULE.bazel
  29. MODULE.bazel.lock
  30. README.md
  31. repositories.bzl
  32. requirements.txt
  33. SECURITY.md
  34. workspace_deps.bzl
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