Do .bzl load cycle detection by key instead of label

The inlining code path for StarlarkImportLookupFunction does its own cycle detection since it doesn't use Skyframe. This CL changes it to look for cycles over the graph of bzl key dependencies, instead of their projection onto their labels. This allows two distinct keys that happen to have the same label to not spuriously trigger cycle detection when inlining.

This is likely not a current problem in practice, because there doesn't seem to be a way to construct a non-cyclic path of load()s where any labels are repeated. Package bzl keys can't produce workspace keys and vice versa, even though the same .bzl file may be used for both. Likewise, I do not believe it's possible for the same label to be loaded in a cycle with distinct workspace chunking info, though I'm not 100% sure. When the new @builtins pseudo-repository is added, it may conflict with a proper external repo that happens to be named "@builtins", but even then the two shouldn't be able to load each other.

All the same, let's cycle check the proper object in case any of these assumptions change in the future. It also brings the inlining case's cycle check in-line (ha-ha) with ordinary Skyframe evaluation's cycle check.

This is refactoring work toward adding a new kind of .bzl loading context, for Bazel-internal .bzl files.

Work toward #11437.

RELNOTES: None
PiperOrigin-RevId: 312842293
1 file changed
tree: bbfe4c616db9686151eba50b74c2449911e1495b
  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. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. 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