You are not logged in.

#1 2009-08-27 01:01:44

alexk
Member
From: Sydney, Australia
Registered: 2009-08-27
Posts: 32
Website

[solved] Patching - is it possible to...

... apply a patch each time the package is upgraded?

Let me elaborate: a package has a bug which doesn't affect most users but does affect me. The bug is well known, there's a working patch, but it won't be committed upstream in the foreseeable future.

What I want is to patch the package each time it's upgraded.

I followed instructions on the wiki, copied PKGBUILD from /var/abs, edited it to patch the package, made the package with makepkg, and finally installed with pacman -U. But I cannot figure out how to automate this process.

Do I have to repeat these steps each time a new version is released? What if I have a few such packages, this can become quite tedious...

Sorry if I'm missing something obvious, I just started using Arch yesterday.

Cheers,
Alex

Last edited by alexk (2009-08-28 01:26:32)

Offline

#2 2009-08-27 01:29:26

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,422
Website

Re: [solved] Patching - is it possible to...

There is a program called srcpac which is a wrapper around pacman that should allow you to do this.  I think you should probably look at the git version as I think there are issues with the current one...

Offline

#3 2009-08-27 01:36:53

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [solved] Patching - is it possible to...

Do you use yaourt? You can find it in AUR. I recommend using yaourt-git. There's another package, customizepkg, also in AUR. What that does is let you store little snippets in /etc/customizepkg.d/package_name. Yaourt checks for this automatically, if you later try to upgrade package_name, it will download the PKGBUILD, applies the patches to the PKGBUILD described in your snippet file (in the case you describe, you'd be adding instructions to the PKGBUILD to get it to find the patch and apply it to the new source), and then builds the package from source.

It's all a bit fragile---a while ago, the community PKGBUILDs weren't available (see here) where yaourt looks for them; I'm not sure whether that's now fixed. Also, the format that customizepkg expects requires a lot of escaping---for example any time you want to include a literal '/' you have to use '\\/'. And there's almost no (or literally no) documentation. But it works.

Frankly, if it's only a package or two it's easier to just patch it and build it yourself by hand. Once you get to five or ten such packages, though, then yes, automating looks attractive. It's just laborious to set the automation up, and a bit fragile.

Last edited by Profjim (2009-08-27 01:37:50)

Offline

#4 2009-08-27 01:51:41

alexk
Member
From: Sydney, Australia
Registered: 2009-08-27
Posts: 32
Website

Re: [solved] Patching - is it possible to...

Allan wrote:

There is a program called srcpac which is a wrapper around pacman that should allow you to do this.  I think you should probably look at the git version as I think there are issues with the current one...

Thanks Allan, srcpac looks like what I need. I just need to learn sed big_smile

Offline

#5 2009-08-27 01:52:41

alexk
Member
From: Sydney, Australia
Registered: 2009-08-27
Posts: 32
Website

Re: [solved] Patching - is it possible to...

Profjim wrote:

Do you use yaourt? You can find it in AUR. I recommend using yaourt-git. There's another package, customizepkg, also in AUR. What that does is let you store little snippets in /etc/customizepkg.d/package_name. Yaourt checks for this automatically, if you later try to upgrade package_name, it will download the PKGBUILD, applies the patches to the PKGBUILD described in your snippet file (in the case you describe, you'd be adding instructions to the PKGBUILD to get it to find the patch and apply it to the new source), and then builds the package from source.

It's all a bit fragile---a while ago, the community PKGBUILDs weren't available (see here) where yaourt looks for them; I'm not sure whether that's now fixed. Also, the format that customizepkg expects requires a lot of escaping---for example any time you want to include a literal '/' you have to use '\\/'. And there's almost no (or literally no) documentation. But it works.

Frankly, if it's only a package or two it's easier to just patch it and build it yourself by hand. Once you get to five or ten such packages, though, then yes, automating looks attractive. It's just laborious to set the automation up, and a bit fragile.

Thanks Profijm, customizepkg looks interesting, I'll check it out.

Offline

#6 2009-08-28 04:42:31

alexk
Member
From: Sydney, Australia
Registered: 2009-08-27
Posts: 32
Website

Re: [solved] Patching - is it possible to...

Just a quick follow-up for anyone interested.

I ended up using yaourt+customizepkg as suggested by Profijm. What you need to do is add a file to /etc/customizepkg.d/ which describes the changes to be done to the PKGBUILD file before building.

When the new version of the package is available, yaourt will know that you want to build it from source by finding the file in /etc/customizepkg.d/, get the PKGBUILD, patch it, build and install.

This all looks very nifty, so far I'm really liking Arch! big_smile

Offline

#7 2009-09-06 12:05:47

alexk
Member
From: Sydney, Australia
Registered: 2009-08-27
Posts: 32
Website

Re: [solved] Patching - is it possible to...

I blogged about using customizepkg here, hope it will be useful to someone.

Offline

#8 2009-09-06 22:43:44

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [solved] Patching - is it possible to...

Actually, I ended up hacking the customizepkg source, because I was fed up with so many damn escapes and the like. Here's my updated version:
http://pastebin.ca/1556530.

Differences:
1. a patch file has to include "version=2" to be interpreted in the new way, else it defaults to the original customizepkg format.
2. one change is a tweak to keep customizepkg from collapsing whitespace
3. uses extended grep patterns (as in egrep) and uses ! instead of / for its internal sed separators. So '/'s no longer need to be escaped. But now '!'s do; I think that's a reasonably uncommon character.
4. when escaping is necessary, it still needs to be done with double backslashing
5. no longer blindly quotes items added to PKGBUILD arrays. Single quotes are added only if the item doesn't already have (single or double) quotes. This lets one add items like "file/path/$pkgname".
6. source items are added to the end of the source array rather than to the start. I thought this looked better; also, it enabled one to retain the md5sums on the already existing items and just ignore/warn about the newly added items which may lack an md5sum entry. With the most recent version of makepkg, however, md5sum-checking can't be ignored; and with the next version, the arch devs have made md5sum-checking all-or-nothing. So you can't just check the md5sums on some of the source items. Oh well. Adding source items to the end of the source array still looks better. All other array items are added to the start of their array (customizepkg's default behavior, and easier to implement). I don't think order matters for any other arrays.

Offline

#9 2009-09-07 01:27:17

alexk
Member
From: Sydney, Australia
Registered: 2009-08-27
Posts: 32
Website

Re: [solved] Patching - is it possible to...

Thanks Profjim, looks good!

Offline

Board footer

Powered by FluxBB