[Hack/Guide/Dev/OBS] Modify a tar_git package without cloning the packaging repo

That’s a small trick I just worked out for the following situation:

Say you have an existing package at OBS and want to change something about its build. But it’s using using a _service file getting the sources via tar_git), so by making a fork or copy you won’t be able to alter the .spec file.
But for some reason you can’t or don’t want to fork the whole original packaging repo just now.


The OBS linking feature to the rescue.

  1. Create a new package example-orig in your project (or branch the original package). Here we just copy it:
osc copypac original:project example home:me example-orig
  1. for that new package, disable building, publishing, … so we don’t clog the OBS workers for stuff we don’t need. This package is just the template we start our work from.
<package name="example-orig" project="home:me">
  <title/>
  <description/>
  <build>
    <disable/>
  </build>
  <publish>
    <disable/>
  </publish>
  <useforbuild>
    <disable/>
  </useforbuild>
</package>
  1. Create a second empty package example-dev. In its empty directory, create file called _link
<link project="home:me" package="example-orig">
<patches>
</patches>
</link>

and commit (osc add _link; osc ci ) it to OBS.

  1. Now here comes the magic: tar_git creates files like _service:tar_git:example.spec that you can’ really manipulate. We want a copy of that file we can edit, and create a diff patch from it. So in the local package dir:
mkdir a
osc cat _service:tar_git:example.spec > a/_service:tar_git:example.spec
cp -r a b
  1. Edit b/_service:tar_git:example.spec to your liking, and when done create a patch from it:
diff -u a b > spec.patch
osc add spec.patch
  1. We use the apply feature of OBS linking to add a patch to the package that is applied before the build process starts. Edit the _link file:
<link project="home:me" package="example-orig">
  <patches>
    <apply name="spec.patch" />
  </patches>
</link>
  1. … and done. Commit your changes:
osc ci _link spec.patch

and watch OBS happily building your changed version.

At this point, continue in a similar manner in case you want to change any other files from the project.
And as you have a _link file in there, you may use the other features of linking, like <topadd> for small changes to .spec files, and <add> to include patches to the sources (as opposed to the OBS package).

See the small guide from OpenSuSE for these.

Hope this (admittedly corner case) hack/trick is useful for someone, feel free to point out a better method if you know of any.

4 Likes

HINT1: Actually you can skip steps 1. and 2. and simply link to an existing package in someone else’s repo:

<link project="home:someone" package="example">

BUT, steps 1. and 2. complete the whole process for the case such a source package does not exist, or you e.g. imported a specific package from a specific release.

You also might want to have an unmodified and the devel version of the package in the same project for quick switching, or other reasons.

HINT2:

Steps 1 to 3 can alternatively be done like this:

osc branch --disable-build original:project example home:me example-dev

HINT3:

It’s probably not feasible to make a patch against the _service:tar_git:foo.tar.gz tarball itself, BUT you can download it, extract to src_a and src_b, create patches and use <apply name="src.patch"> lines to include your local changes.

3 Likes