Please review this pr to add cleanup extension

Two common complaints about snaps are their size and their startup time. These are causally linked: larger snaps start a lot slower because there is more to decompress and there is more to keep the dynamic linker busy.

Adding an easy way for developers to reduce their snap size is really useful, so I started work on a cleanup extension. This extension can be used by snap authors to remove all the libraries from their snap which are already available from the base snap and connected content snaps. Thanks @diddledani for the excellent post-build cleanup part.

With this extension I was able to reduce the mc-installer snap size from 104MB to 39MB and its cold startup time from 5 seconds to 1 second.

What I need help with

  1. The extension needs to run after all other extensions because it needs to know which content snaps will be connected, even if those content snaps are added by other extensions. How can I achieve this?
  2. The extension needs access to the expanded snapcraft.yaml definition so it can see what plugs the other extensions have added. What’s the best way to do this? Do we just give all extension access to the expanded manifest?

I created a rough PoC in the PR to get a discussion started.


I’ve encountered one issue with using this cleanup part:

If your snap uses the gtk2 or gtk3 desktop helper (note, not the gnome-3-28 extension - that’s fine) then the cleanup part will remove the following files which are required to be in $SNAP by the desktop-launch script:

  • usr/lib/$ARCH_TRIPLET/glib-2.0/gio-querymodules
  • usr/lib/$ARCH_TRIPLET/glib-2.0/glib-compile-schemas

This occurs when using at least the core18 base snap because these files exist in there.

Another issue I had was with snapcraft not finding python3 when using core18 and gnome-3-28 extension. I set my command: to path/to/ which has a shebang of #!/usr/bin/env python3. Snapcraft sees that the command is a script and parses the shebang to find python3 and then searches for python3 in the prime directory. Not finding the executable, because it is removed by the cleanup part, it rewrites the command to /usr/bin/python3 $SNAP/path/to/ (note the leading /) and then fails with complaints that the command is illegal. The same occurs if I explicitly set python3 in the command:.