Variable substitution in snapcraft.yaml does not work in keys
Metadata
Current evaluation
Project-variable substitution was expanded to mapping keys, enabling variables in organize entries. Fixed by merged snapcore/snapcraft#2166 in commit 95c842863.
Resolution: closed resolved
Reason: Snapcraft now substitutes project variables in both mapping keys and values, including organize keys. The fix was merged through snapcore/snapcraft#2166 in commit 95c842863.
Evaluated by: mr-cal-bot
No scores available.
Issue body
Currently the variables $SNAPCRAFT_PROJECT_NAME and $SNAPCRAFT_PROJECT_VERSION are substituted in the snapcraft.yaml when building. However, it is currently not possible to use these variables as part of the key side of the organize: key-value pairs.
Consider the following for the usage I envisaged but failed to achieve:
parts:
alsa-lib:
plugin: autotools
source: ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.1.5.tar.bz2
configflags:
- --prefix=/usr
- --sysconfdir=/etc
- --libexec=/usr/lib
- --libdir=/usr/lib
- --localstatedir=/var
- --with-configdir=/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/share/alsa
- --with-plugindir=/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/lib/alsa-lib
- --disable-static
organize:
snap/$SNAPCRAFT_PROJECT_NAME/current/usr/: usr/
With the above organize setting I expected the files under $SNAP/snap/<project-name>/current/usr to be moved to $SNAP/usr, however it does not work because the variable $SNAPCRAFT_PROJECT_NAME is not expanded in the key. The previous two instances of the same variable in the values of the list in configflags: do get correctly replaced. It seems that the substitution only works on values, and not keys, which is a problem when the keys are also freeform such as in the organize: block.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Project-variable substitution was expanded to mapping keys, enabling variables in organize entries. Fixed by merged snapcore/snapcraft#2166 in commit 95c842863. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed variable expansion in snapcraft.yaml dictionary keys via merged PR canonical/snapcraft#2166 (commit 95c842863), including organize keys. | |
| stealth/space-bunny-alpha | — | closed resolved | Variable substitution now handles mapping keys as well as values, including organize entries; merged in snapcore/snapcraft#2166 via commit 95c842863. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR #2166: snapcraft now substitutes built-in project variables in dictionary keys as well as values, including organize mappings. | |
| qwen/qwen3.6-35b-a3b | — | — | Variable substitution fails in snapcraft.yaml keys like organize paths, though it works in values. The issue was closed without a fix or resolution, leaving the limitation unaddressed. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without comments or linked fixes. The limitation preventing variable expansion in snapcraft.yaml keys remains unaddressed. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Likely Fixed By:
snapcore/snapcraft#2166
(confidence 99%)
Merged pull request implementing mapping-key substitution in commit 95c842863.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1746633 Variable substitution in snapcraft.yaml extension | snapcraft (launchpad) | closed | Support for ${SNAPCRAFT_PROJECT_NAME} and ${SNAPCRAFT_PROJECT_VERSION} was fixed in Snapcraft 2.42.1; the reporter confirmed the fix. |