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 'https://raw.githubusercontent.com/diddlesnaps/snapcraft-utils-library/master/lib/cleanup.libsonnet';

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
store.
",

    base: core18,

    # Add the rest of your snapcraft build config here
}
+ cleanup(["core18"])

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

Manually adding to snapcraft.yaml

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
  store.
grade: devel
confinement: devmode

base: core18

parts:
  my-part:
    plugin: nil

  cleanup:
    after: [my-part]  # Make this part run last; list all your other parts here
    plugin: nil
    build-snaps: [core18, gnome-3-28-1804]  # List all content-snaps and base snaps you're using here
    override-prime: |
      set -eux
      for snap in "core18" "gnome-3-28-1804"; do  # List all content-snaps and base snaps you're using here
        cd "/snap/$snap/current" && find . -type f,l -exec rm -f "$SNAPCRAFT_PRIME/{}" \;
      done

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