Make Python rules require the new Python toolchain type

This makes py_binary / py_test require the new Python toolchain type (@bazel_tools//tools/python:toolchain_type). It does *not* make the rules actually use Python runtimes obtained via the toolchain; that happens in a follow-up CL.

A default toolchain is defined and registered automatically in order to prevent analysis of Python rules from failing frivolously. This default is simply a stub that fails at execution time, but a follow-up CL will change it to autodetect the Python interpreter at runtime. Registration of the toolchain occurs via a WORKSPACE suffix file, so it happens automatically for every workspace.

Note that workspace suffixes are disabled in BazelAnalysisMock#createRuleClassProvider, so we need to add it to the analysis mock's boilerplate workspace content. Tests that want to register a specific toolchain (and have it take precedence over the boilerplate) should use --extra_toolchains=... in the configuration, rather than manipulate the WORKSPACE file.

tools/python/BUILD is refactored into tools/python/BUILD.tools so that the newly added toolchain definitions can be bootstrapped with Bazel 0.23, which does not have the required PyRuntimeInfo provider type.

As a drive-by cleanup, the ":py_interpreter" attribute is pushed down from PyBaseRule to PyBinaryBaseRule.

Work toward #7375.

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

Bazel is released in ‘Beta’. See the product roadmap to learn about the path toward a stable 1.0 release.