Feature request: let a part modify files ater staging

This issue came up in the thread about speeding up start up of desktop app snaps, but seems to have gotten lost in the noise. I would like the ability to have a part modify the contents of the stage/ directory after all parts have staged their content.

A concrete use case for this is compiling GSettings schemas. Schemas are XML files that are generally installed to $datadir/glib-2.0/schemas, and the compilation process produces a gschemas.compiled file that covers all the schemas in that directory.

If we have multiple parts that install schemas to the same directory, we’d need to generate a gschemas.compiled file that covers all of them. This means no part can produce the file without knowing what all the other parts are going to stage.

From a brief look it isn’t currently possible to do this, even with a custom part plugin. So would it be possible to enable a feature like this?

could you not create a part that runs after: [all, the, other, parts] to do the compilation as a hacky workaround? You’d reference $SNAPCRAFT_STAGE in that case.

This should work in the short term, longer term, you will be able to pre and post for -stage and prime

That’s essentially what I’m doing for the libreoffice snap: https://git.launchpad.net/~libreoffice/+git/libreoffice-snap/tree/snap/snapcraft.yaml#n292.
Not the most readable/maintainable piece of declarative code, but it does the trick.

@sergiusens, where can we track the implementation of those pre and post hooks?

1 Like

Ideally I’d like to be able to encode this into a cloud part (i.e. desktop-gtk3, desktop-qt5, etc). In this case we don’t know the names of all the other parts so can’t ask to run after them.

Take desktop-gtk3 for instance: it pulls in the .deb packages for libgtk-3-common, which installs schemas to $SNAP/usr/share/glib-2.0/schemas. I’d like to compile these schemas so that we don’t need to handle it on first run, but if any of the subsequent parts add schemas to that directory, the gschemas.compiled file will be incomplete and the application will break.