pluginhandler: organize in build instead of stage
Metadata
Current evaluation
Merged. Relocates file organization from the stage step to the build step in Snapcraft, resolving double-staging failures and ensuring collision detection accounts for organized files. Approved by reviewer.
Suggested action: —
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)?
- [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh unit`?
-----
Currently, Snapcraft organizes during the stage step. This is terrible for two reasons:
1. The organization actually occurs in the installdir, which belongs to the build step. As a result, a snap that uses the `organize` keyword cannot in some cases be staged twice (i.e. have the stage step cleaned, and then staged again) because the organization cannot always happen twice.
2. Since organization only happens in the stage step, and collision detection runs before any parts are staged, collision detection doesn't take the organization into account. As a result, one cannot use the `organize` keyword to get around file collisions between parts, even though we recommend it for exactly that use.
This PR fixes #2031 and LP: [#1628098](https://bugs.launchpad.net/snapcraft/+bug/1628098) by completing the organization at the tail end of the build step, so the part is already organized when it comes time to check for collisions and stage.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged. Relocates file organization from the stage step to the build step in Snapcraft, resolving double-staging failures and ensuring collision detection accounts for organized files. Approved by reviewer. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged. Relocates organize keyword execution from the stage step to the end of the build step. This resolves re-staging failures and enables collision detection to account for file relocations, fixing issues #2031 and LP: #1628098. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged PR moves file organization from stage to build step, resolving re-staging failures and collision detection conflicts. Fixes #2031 and LP: #1628098. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #2290 pluginhandler: update build should overwrite organize | snapcraft | merged | Merged changes resolve LP: #1794083 by allowing organize to overwrite previously organized files when a part build step updates. Approved by one reviewer, passed CI, and achieved 100% diff coverage. | |
| #3122 pluginhandler: make the build environment available to all steps | snapcraft | merged | Merged. Reviewer feedback refined scoping: build environment is now available across all plugin steps. SNAPCRAFT_STAGE stays global, build-environment stays on the build step. Changes affect 10 files. | |
| #1548 fix: revert organize from build | craft-parts | merged | Merged to revert commit 8e4daf5, resolving a Snapcraft regression caused by the organize-from-build feature. Approved by two reviewers and verified downstream. The feature will be reintroduced once underlying issues are resolved. |