Post-build Cleanup

This utility will clean up any files that have been included in your Snap during build which also exist in the base Snap or any content-Snaps that you are using.

Usage with sc-jsonnet

Applying the utility with sc-jsonnet is the easiest method. To use, simply import the library and add cleanup([]) to your snapcraft tag. Pass-into the function all your content-Snaps and base Snap in between the square brackets separated by commas. The following code shows a trivial example of using it:

local snapcraft = import 'snapcraft.libsonnet';
local cleanup = import '';

snapcraft {
    name: cleanup-example,
    version: "0.1",
    summary: "Example of using the 'cleanup' library",
    description: |||
        This is my-snap's description. You have a paragraph or two to tell the
        most important story about your snap. Keep it under 100 words though,
        we live in tweetspace and your description wants to look good in the snap

    base: core18,

            extensions: [gnome-3-28]

    # Add the rest of your snapcraft build config here
+ cleanup(["gnome-3-28-1804"])

If you are using multiple utilities then put the cleanup utility last in the chain.

Manually adding to snapcraft.yaml

Add the following part into your snapcraft.yaml, and change my-part to a list of all of your snap’s other parts:

    after: [my-part]  # Make this part run last; list all your other parts here
    plugin: nil
    build-snaps: [gnome-3-28-1804]  # List all content-snaps you're using here
    override-prime: |
      set -eux
      for snap in "gnome-3-28-1804"; do  # List all content-snaps you're using here
        cd "/snap/$snap/current" && find . -type f,l -exec rm -f "$SNAPCRAFT_PRIME/{}" "$SNAPCRAFT_PRIME/usr/{}" \;
      for CRUFT in bug lintian man; do
        rm -rf $SNAPCRAFT_PRIME/usr/share/$CRUFT
      find $SNAPCRAFT_PRIME/usr/share/doc/ -type f -not -name 'copyright' -delete
      find $SNAPCRAFT_PRIME/usr/share -type d -empty -delete

Adjust the after definition to ensure that the cleanup part runs after every other part defined in your yaml.