Fix #197: auto-expand fineGrainedHashExternalRepos through bzlmod wrappers#343
Open
tinder-maxwellelliott wants to merge 2 commits into
Open
Fix #197: auto-expand fineGrainedHashExternalRepos through bzlmod wrappers#343tinder-maxwellelliott wants to merge 2 commits into
tinder-maxwellelliott wants to merge 2 commits into
Conversation
311be6f to
6b91f03
Compare
…tected The simple case (a main-repo target consuming a file from a single external repo) works on current bazel-diff. The unfixed shape is the one @Ahajha called out: a target inside one external repo is re-wrapped by ANOTHER external repo, and the main repo consumes only the wrapping repo. When the inner repo's source file changes, the main-repo consumer should be reported as impacted -- today it is not, unless the user manually enumerates every wrapping external repo in --fineGrainedHashExternalRepos. The new `wrapped_external_repo` fixture wires this up with bzlmod: inner_repo -> filegroup wrapping data.txt middle_repo -> alias re-exporting @inner_repo//:all_files //:consumer -> genrule consuming @middle_repo//:wrapped Confirmed by hand against the built CLI: --fineGrainedHashExternalRepos=@inner_repo -> impacted: @inner_repo//:all_files, @inner_repo//:data.txt -> //:consumer NOT impacted (bug) --fineGrainedHashExternalRepos=@inner_repo,@middle_repo -> impacted includes //:consumer (workaround proves the chain works when every wrapper is enumerated) The reproducer test asserts that listing only the source-of-truth repo is enough. It is @ignore'd until propagation through alias/wrapper external repos works. Refs #197 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Without this, a main-repo target consuming `@middle_repo//:wrapped` (itself an alias for `@inner_repo//:all_files`) is not reported as impacted when `inner_repo/data.txt` changes, unless the user manually enumerates every wrapping external repo in `--fineGrainedHashExternalRepos`. The dep chain stops at the unhashed `//external:middle_repo` blob because `transformRuleInput` collapses any external label whose repo isn't in the fine-grained set. The fix walks `bazel mod graph --output=json` once at startup, builds the apparent-name dependency graph, and adds every bzlmod module that transitively depends on a user-listed repo to the fine-grained set. For the reproducer fixture, listing only `@inner_repo` now auto-includes `@middle_repo`, so its alias target is queried as a real rule and the chain propagates down to the leaf source file. The expansion is a no-op when the user supplies no repos, when bzlmod is disabled, or when no wrapper depends on a listed repo, so existing fine-grained flows that don't involve wrapping repos are unchanged. Flips the `@Ignore`'d reproducer in #343 to a passing regression test and adds `ModuleGraphParser` unit coverage for the new edge / dependents helpers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6b91f03 to
c826840
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--fineGrainedHashExternalRepos.bazel mod graph --output=jsononce at startup, builds the apparent-name dep graph, and auto-adds every bzlmod module that transitively depends on a user-listed repo to the fine-grained set. Listing only@inner_repois now enough;@middle_repois added automatically so its alias rule is queried for real and itsactualattribute carries the dep chain down to the leaf source file.@Ignore'd regression test under the newwrapped_external_repofixture.Mechanism
expandFineGrainedHashExternalReposWithBzlmodDependentsincli/src/main/kotlin/com/bazel_diff/di/Modules.kt.ModuleGraphParser(parseModuleGraphEdges,findTransitiveDependents) extract the dep edges from the JSON form ofbazel mod graphand run reverse-BFS from the user-listed apparent names, excluding the root module (which is always queried via//...:all-targetsanyway).Manual verification
With the fixture from this PR:
--fineGrainedHashExternalRepos=@inner_repoafter editinginner_repo/data.txt:{@inner_repo//:all_files, @inner_repo//:data.txt}—//:consumeris not impacted (bug).{//:consumer, //:consumer.out, @inner_repo//:all_files, @inner_repo//:data.txt, @middle_repo//:wrapped}—//:consumeris impacted (fixed).--fineGrainedHashExternalRepos=@inner_repo,@middle_repostill works (the manual-enumeration workaround is unaffected).Test plan
bazel test //cli:ModuleGraphParserTest— passes (5 new tests for the edge + dependents helpers).bazel test //cli:E2ETest --test_filter=".*WrappedExternalRepo.*"— the regression test for No impacted targets when a file in an external repository changes #197 now passes without@Ignore.testFineGrainedHashExternalRepo,testBzlmodTransitiveDepsCquery,testUseCqueryWithExternalDependencyChange,testUseCqueryWithAndroidCodeChange— all fail on the unmodified base too due to aFound duplicate artifact versions com.google.guava:guavaissue in the existing maven fixture zips; CI runs on Linux and passes them).🤖 Generated with Claude Code