Skip to content

Fix #365: attribute .bzl seed per-package instead of workspace-wide#367

Merged
tinder-maxwellelliott merged 1 commit into
masterfrom
fix/365-per-package-bzl-seed
Jun 8, 2026
Merged

Fix #365: attribute .bzl seed per-package instead of workspace-wide#367
tinder-maxwellelliott merged 1 commit into
masterfrom
fix/365-per-package-bzl-seed

Conversation

@tinder-maxwellelliott

Copy link
Copy Markdown
Collaborator

Summary

Fixes #365 — after the #259/#227 fix, adding (or editing) any .bzl macro and load()ing it, even in an otherwise-empty BUILD that nothing else loads, marked every target in the repository as impacted rather than just the targets that load the macro.

Root cause: BuildGraphHasher.createSeedForBzlFiles rolled the union of every main-repo .bzl digest into a single workspace-wide seed that was then mixed into every target's hash. Its own doc comment acknowledged the tradeoff — "a single .bzl edit re-hashes every target". So introducing a brand-new, unrelated .bzl flipped the seed and changed the hash of completely unrelated targets.

Fix: Replace the single seed with createPackageBzlSeeds, which attributes each BUILD file's loaded .bzl digests to the package that loads them — keyed off the subinclude proto field carried on each package's BUILD SourceFile target. Each rule and source file then mixes in only its own package's seed (looked up via labelToPackage(name)). Because every target always looks up its own package and never the caller's, this stays consistent under RuleHasher's memoized, depth-first recursion.

Behaviour

Tests

  • Flips the @Ignore'd post-fix invariant testAddingUnrelatedMacroDoesNotImpactExistingTargets_reproducerForIssue365 on — it now passes.
  • Removes the companion testAddingUnrelatedMacroImpactsExistingTargets_currentBehaviourBuggy_issue365 that pinned the now-fixed over-triggering behaviour.

Test plan

  • BuildGraphHasherTest / TargetHashTest / SourceFileHasherTest pass (golden hashes byte-identical)
  • testAddingUnrelatedMacroDoesNotImpactExistingTargets_reproducerForIssue365 passes
  • testMacroBzlChangeImpactsCallers_regressionForIssue259And227 still passes
  • CI green on ubuntu+macos × bazel 7/8/9

Refs #365. Builds on the reproducer from #366.

🤖 Generated with Claude Code

The #259/#227 fix (createSeedForBzlFiles) rolled the union of every
main-repo `.bzl` digest into a single workspace-wide seed that was mixed
into every target's hash. As its own doc comment acknowledged ("a single
`.bzl` edit re-hashes every target"), adding or editing any `.bzl` -- even
in an otherwise-empty BUILD that nothing else loads -- flipped the seed and
marked every target in the repo impacted, not just the targets that load it.

Replace the single seed with `createPackageBzlSeeds`, which groups each
BUILD file's loaded `.bzl` digests by the package that loads them (via the
`subinclude` proto field on each package's BUILD SourceFile target). Each
rule and source file then mixes in only its own package's seed, looked up
by `labelToPackage(name)`. Because every target looks up its own package
(never the caller's), this stays consistent under RuleHasher's memoized,
depth-first recursion.

Effects:
- A macro added/edited in package X re-hashes only targets in packages
  that `load()` it, fixing the #365 over-triggering.
- #259/#227 stays fixed: a `.bzl` edit still re-hashes every target in the
  packages that load it (e.g. macro_invalidation's `//:logo_miniature`).
- Workspaces that load no tracked `.bzl` are byte-for-byte stable: the
  per-package map is empty, so nothing is mixed in (golden-hash unit tests
  unchanged).

Flips the @ignore'd post-fix invariant test on and removes the companion
test that pinned the buggy behaviour.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tinder-maxwellelliott tinder-maxwellelliott merged commit 5c08b8e into master Jun 8, 2026
15 checks passed
@tinder-maxwellelliott tinder-maxwellelliott deleted the fix/365-per-package-bzl-seed branch June 8, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bazel-diff macro issue

1 participant