python: Make Starlark implementation of Python rules build/pass most tests

This makes the Starlark implementation load without errors and pass almost all
of the Java unit tests for the Python rules.

* Expose `--python_path` flag via fragments to Starlark
* Remove load of Google-only toplevel_aliases to get CcInfo symbol
* Implement `imports` attribute completely/correctly; the semantics
  `get_imports()` function is only for processing the `imports` attribute
  itself, not all imports for a target. That is done by (the new) common
  function `collect_imports()`.
* Only return OutputGroupInfo once (the `output_groups` arg of
  `_create_providers()` would cause it to be returned twice.
* Make `PyCcLinkParamsProvider` usable: bind this global name to the actual
  Python rule implementation instead of the C++ no-op implementation.
* Move the Python-specific `PyWrapCcInfo` and `py_wrap_cc_helper_do_not_use`
  symbols out of the C++ rules and into the Python rules. This is necessary do
  avoid a circular dependency between the two rule sets after moving the
  `PyCcLinkParamsProvider` into the Python rules. These two symbols are still
  bound to no-ops in Bazel because they are unused in the Bazel parts of the
  Python rules.
* Fix an undefined variable usage in the Bazel `get_imports` function.
* Various Bazel-specific functions were slightly renamed to better distinguish
  them from their common counterparts.
* Pass missing `inherited_environment` arg in `py_binary`
* Make `py_binary`, `py_test`, and `py_library` macros load and call their
  respective rule implementations.
* Fix `_create_providers` returns doc.
* Implement `legacy_create_init` attribute
* Implement and fixes for `--build_python_zip`, boostrap-template-executables,
  and Windows launcher executables.
  * Fix computing the base executable name: `.basename` attribute, not `.name`
  * Create zip and supporting files next to the executable (use the `sibling`
    arg when declaring the artifacts)
  * Add the zip file to files to build outputs.
  * Fix undefined variable usage (`bootstrap_output`, not `bootstrap_template`)
  * Add stub intended for the zip to the zip action's inputs
* Add missing methods to Bazel binary semantics object. Note that a few
  features are still unimplemented (i.e. coverage).
* Fix `PLATFORMS_LOCATION` prefix (missing leading slash)
* Fix fragment name for getting `--python_path` flag.

Closes #17188. Work towards #15897.

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