[2.x] fix: extraProjects with auto-root aggregate breaks key aggregation#8690
Conversation
…gation When a plugin adds extraProjects, sbt creates an auto root that aggregates all projects but has no plugin tasks (e.g. scripted). The aggregated key parser filtered choices by data.contains(key), so (root, scripted) was rejected and 'scripted' failed with 'No such setting/task'. - Add optional structure param to scopedKeySelected and select - Use isValidForAggregate when structure is present: accept key if it exists in data or aggregates to keys that all exist in data - Pass structure from scopedKeyAggregated/scopedKeyAggregatedFilter so root-scoped keys that exist only on aggregated projects are valid
|
@eed3si9n Ready for review! |
- scopedKeySelected: structure is required; callers pass None or Some(structure) - select: add two-arg overload for callers without structure; three-arg version has no default so aggregate path is explicit
|
Please review again. |
eed3si9n
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I can't tell from the diff it if fixes the bug or not. As per usual, please include repro test(s), like a scripted test, into the pull request, and declare AI usages if any - https://github.com/sbt/sbt/blob/develop/CONTRIBUTING.md.
…tion) - project/extra-projects-key-aggregate: repro for sbt#4947 Run 'check' at root; without fix: No such setting/task; with fix: runs p/check
2500d40 to
eb89e0e
Compare
Done, thanks for the review. |
Key aggregation at root with extraProjects+auto-root aggregate was requiring all aggregated projects to define a task (forall). Change to exists so a task is valid if any aggregated project defines it.
The test for sbt#4947 needs an explicit root that aggregates all projects including z from extraProjects. This validates that check works from root when only defined in subproject p.
sbt-app/src/sbt-test/project/extra-projects-key-aggregate/build.sbt
Outdated
Show resolved
Hide resolved
When extraProjects adds projects via plugins, the auto-root is created before other projects (defined in build.sbt) are discovered. This caused the auto-root to only aggregate the extraProjects, not all projects. The fix updates processAutoAggregate to add missing projects to the auto-root's aggregation after all projects have been discovered. The fix only applies to auto-generated roots (when hasRoot=false), not to user-defined root projects. Fixes sbt#4947
Closes #4947
What was wrong
When a plugin adds projects via
extraProjects, sbt creates an auto root that aggregates all projects. That root doesn't get plugin tasks (e.g.scriptedfrom SbtPlugin). So if you ranscriptedfrom the shell, you'd get "Not a valid command: scripted" / "No such setting/task" even though a subproject had the task.What we changed
When using the aggregated key parser, a key is now valid if it exists in
datafor that scope or it's an aggregate key and every key it aggregates to exists indata. So(root, scripted)is accepted when the root aggregates a project that definesscripted, and runningscriptedat root runs it on that project as before.Repro test
project/extra-projects-key-aggregateaandp; plugin adds extra projectz→ sbt creates auto root.pdefines the taskcheck.> checkat root; without the fix this fails with "No such setting/task"; with the fix it runsp/checkand passes.AI disclosure
AI usage: I used AI tools (ChatGPT) to assist with this PR: implementation design, code changes, and test setup. The changes were verified locally (compile, lint, unit tests). I have reviewed and understand the code.
mainProj/test).scripted project/extra-projects-key-aggregate(afterpublishLocalBinor in CI).