How To (safely) Modify Gentoo Packages Without Breaking Portage

Bild von hadez

A few minutes ago someone was very bitchy about ATI and how their linux driver uses mesa-gl.
Not necessarily a problem, unless you have a dual-head setup and want to use beryl.

The problem lies withing mesa’s config.h that has a certain, quite limiting, define:
#define MAX_TEXTURE_RECT_SIZE 2048 which limits you to textures 2048×2048 pixels big.
His dual 19” setup had a resolution of 2560×1024, buhhh…

Now, what do you do?
Change it? That’s quite simple.
But how do you install a new mesa version without breaking portage?

Here is how it’s done:

  • Make sure portage is up to date (to what you want to do, atleast)
  • Let emerge fetch the package you want to modify (for the sake of simplicity let’s call the package media-libs/somepack-1.0.0 )

emerge -f somepack
  • Move /usr/portage/disfiles/somepack-1.0.0.tar.bz2 (or similar) to some temporary folder
  • Unpack it, modify the contents, and re-pack it
  • Move the archive back to /usr/portage/distfiles
  • Fix the fingerprints, after all the archive was modified

cd /usr/portage/media-libs/somepack/
ebuild somepack-1.0.0.ebuild digest
  • Now you should mask out all other versions of the modified package so you’ll get a warning/reminder/block in case portage wants to update (downgrade) the package, possibly breaking your system by reverting your changes by doing so.

echo "# package manually modified, changed define FOO in config.h to ASDF" >> /etc/portage/package.mask
echo ">media-libs/somepack-1.0.0" >> /etc/portage/package.mask
echo "<media-libs/somepack-1.0.0" >> /etc/portage/package.mask
  • Emerge the package (or whatever was pulling in the dependency)
  • If the package was a library you might want to play it safe and re-emerge all dependencies

revdev-rebuild --library libsomepack-*

One last bit of info:
The second to last step does not block re-emerges of the same version.
Unless you delete the fetched files in /etc/portage/distfiles (including your modified package) you’re safe, but if (for whatever reason) the packages gets downloaded again, you’ll end up with a broken system.
The fingerprints/digests might prevent this, but on the other hand, emerge --sync might also revert the digest file to the original version.
Just be very cautious if you see a ‘digest failed’ error message.
Check twice it could be both, new archive or changed digest file!

Ok, this should work, as usual, no guarantees on anything. You might break something.
But at the end of the day this is the safest method of modifying the source of a certain package without (necessarily) breaking portage (AFAIK). If you happen to know a better way, please let me know.