I used to build Debian packages (quilt), it supports applying patches while build process. Patches are stored in debian/patches
folder and they are usually used to add fixes not committed yet to the upstream source or add specific platform tunning.
My case is a package that needs custom build command:
make build; make install_api; make install_desktop
instead of standard way:
make; make install
Current proposed solution is to:
- modify
Makefile
and adddefault:
&install:
entries.
The error got when running snapcraft --no-parallel-build
without modifying source:
make install DESTDIR=/home/username/Desktop/sandbox/alfanous-snap/parts/alfanous-git/install
make: *** No rule to make target 'install'. Stop.
Command '['/bin/sh', '/tmp/tmp_f_u1ktl', 'make', 'install',
'DESTDIR=/home/username/Desktop/sandbox/alfanous-snap/parts/alfanous-git/install']'
returned non-zero exit status 2
So, is there any way to add a patch to snapcraft build? I'm open to any other solution/workaround.
This sounds like a good case for snapcraft "scriptlets". The
build:
stanza will let you replace the build step with your own shell commands (make build; make install_api; make install_desktop
).In the ideal case, the snap is maintained upstream so it's on their best interest to accept the patches upstream, maybe adjusting them to be more general.
If upstream doesn't want to maintain the snap and you are doing it as a community contributor, I would suggest to make a fork of the original project and apply your patches there. To me, a fork seems clearer than keeping a set of patches around. That's the github way, and I prefer it to the debian way.
But of course, that's a subjective opinion, and snapcraft should be flexible enough to let you follow whatever process you think is best for your project. So, with the bitcoin snap we explored a little with patching. You can find the snap metadata here: https://github.com/elopio/blockchain-snaps/tree/master/bitcoin/snap
In the snapcraft.yaml you will find a part for patches. That one just copies the patches directory into the stage directory, and makes sure that those files don't end up in the snap. If you check that dir, you'll find one .patch file generated with git diff.
Then, also in the snapcraft.yaml you will find that the bitcoin part applies the patch in the prepare script.
Important parts of
snapcraft.yaml
:Snap folder structure:
That works nicely in the bitcoin case. But it's just an experiment, not yet a documented best practices. So comments and ideas to make it nicer are welcome.