pro tip: use scriptlets instead of custom plugins

Kyle Fazzari kyle.fazzari at canonical.com
Mon Feb 20 16:55:51 UTC 2017


On Feb 20, 2017 6:23 AM, "Olivier Tilloy" <olivier.tilloy at canonical.com>
wrote:

On Fri, Feb 17, 2017 at 12:11 AM, Leo Arias <leo.arias at canonical.com> wrote:
> Hello!
>
> This week I've been cleaning a few of my old snaps, using some of the
> new features in more recent versions of snapcraft. At first I wasn't
> convinced about scriptlets, but now I think they are great. Take a
> look at this diff:
>
> 5 additions and 144 deletions
>
> https://github.com/elopio/ipfs-snap/commit/06f32696c1b461b1068e803e71e22b
ad50fe52eb
>
> Here is more info:
> https://insights.ubuntu.com/2017/02/02/run-scripts-during-
snapcraft-builds-with-scriptlets/

Very useful, thanks for highlighting it Leo!
I've been able to replace the custom plugin for the 0AD snap with
scriptlets, and that simplifies the packaging quite a bit.

One thing that bit me is that I was expecting the 'install' scriptlet
to replace the `make install` step when using the make plugin, but it
doesn't. It runs `make`, `make install`, and then the install
scriptlet. Note that the documentation is reasonably clear about it,
but it looks a bit counterintuitive to me.


Note that the lifecycle doesn't have an 'install' step. The install
actually happens in the 'build' step, which you can replace via the 'build'
scriptlet. The three scriptlet surround the 'build' step:

- 'prepare' runs before build
- 'build' replaces plugin build (including install)
- 'install' runs after build. This is useful e.g. for a Makefile with no
installation targets, or copying over some config files after the plugin
does its thing.


One thing I haven't been able to figure out: is the
parallel_build_count property exposed to scriptlets as a variable?
That would be useful for custom build scripts that call make.


I don't believe so, but I agree it would be useful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/snapcraft/attachments/20170220/cca5edf7/attachment.html>


More information about the Snapcraft mailing list