pluginhandler: support more complex stage-packages.
Metadata
Current evaluation
Merged PR #1059 in commit 9e00ffc15, adding on/try/else stage-package grammar with architecture selectors, optional packages, and fallbacks; resolved LP #1637282.
Resolution: closed resolved
Reason: PR #1059 was merged as commit 9e00ffc15. It introduced conditional and optional stage-package selection, resolving LP #1637282.
Evaluated by: mr-cal-bot
No scores available.
Issue body
Currently snapcraft only supports a flat list of stage packages to be staged regardless of target architecture. This PR resolves LP: [#1637282](https://bugs.launchpad.net/snapcraft/+bug/1637282) by introducing a more complex grammar that allows one to filter stage packages depending on various selectors (target arch for right now), as well as specify optional packages.
The grammar is made up of two statements: `on` and `try`.
```yaml
- on <selector>[,<selector>...]:
- ...
- else[ fail]:
- ...
```
The body of the `on` clause is taken into account if every (AND, not OR) selector is true for the target build environment. Currently the only selectors supported are target architectures (e.g. amd64).
If the `on` clause doesn't match and it's immediately followed by an `else` clause, the `else` clause must be satisfied. An `on` clause without an `else` clause is considered satisfied even if no selector
matched. The `else fail` form allows erroring out if an `on` clause was not matched.
```yaml
- try:
- ...
- else:
- ...
```
The body of the `try` clause is taken into account only when all packages contained within it are valid. If not, if it's immediately followed by `else` clauses they are tried in order, and one of them must be satisfied. A `try` clause with no `else` clause is considered satisfied even if it contains invalid packages.
This PR is larger than I'd like it to be, I'm sorry about that-- I didn't see a logical place to split. Lots of the line count is tests.
Note also that I tried to test a number of combinations, but the grammar is recursive, allowing for unlimited combinations. This could use some good poking.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #1059 in commit 9e00ffc15, adding on/try/else stage-package grammar with architecture selectors, optional packages, and fallbacks; resolved LP #1637282. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged #1059 in commit 9e00ffc15, adding recursive on/try/else stage-package grammar with architecture selectors and optional-package fallback for LP #1637282. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #1059 as commit 9e00ffc15, adding on/try/else stage-package grammar with architecture selectors and optional packages; resolves LP #1637282. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged. Adds a complex grammar for stage-packages using on and try/else clauses to filter packages by selectors like target architecture, resolving LP #1637282. Approved by reviewer and passed CI. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged changes adding complex stage-packages filtering via on and try/else YAML clauses, enabling architecture-based selection and optional packages. Resolves Launchpad bug 1637282. Includes grammar validation, tests, and addresses review edge cases. |
Update history
No update history recorded yet.
Related work
-
Related To:
canonical/snapcraft#1509
(confidence 98%)
Follow-up PR #1509 moved stage-package grammar processing from pluginhandler into project_loader.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1509 project_loader: process stage package grammar | snapcraft | merged | Merged #1509 in commit 82e27706d, moving stage-package grammar processing from pluginhandler into project_loader while retaining raw YAML for state tracking. | |
| #1637282 Allow for architecture-specific stage packages | snapcraft (launchpad) | closed | Architecture-specific stage packages were implemented through grammar in snapcore/snapcraft#1059, later superseded by broader advanced-grammar support. |