As you know, RPM (and DEB and …) package building is a repetitive process and you would want to automate it as much as possible. In the context of the Open Build Service(OBS), source services can help you with exactly that. Over the time, the OBS community has implemented a whole range of source services. For instance, you can use them to fetch from git, mercurial or any other SCM repositories. You can auto-update the spec file or generate changes entries and what not. Here’s what’s currently hosted on Github:
Without much ado, we’ve got another one today, obs-service-refresh_patches. Whenever you automatically update your package with source services, there is a chance that patches applied to the package break. This could be because your local fix was merged upstream and became obsolete, or the upstream code changed and you have to rebase your patch. In the packaging context, most people just use quilt to help with that and that’s what this service is about. So let’s assume a package with the following _service file:
<services> <service name="tar_scm" mode="disabled"> <param name="url">git://github.com/crowbar/barclamp-swift.git</param> <param name="scm">git</param> <param name="exclude">.git</param> <param name="versionformat">1.7+git.%ct.%h</param> <param name="revision">release/roxy/master</param> </service> <service name="recompress" mode="disabled"> <param name="file">crowbar-barclamp-swift-*git*.tar</param> <param name="compression">bz2</param> </service> <service name="set_version" mode="disabled">; <param name="basename">crowbar-barclamp-swift</param> </service>; </services>
So if you invoke the services locally with osc, it would fetch from a specific git repository, tar the whole thing up and adjust the Version: tag in the spec file:
saschpe@duff:% osc service dr Found git://github.com/crowbar/barclamp-swift.git in /root/.obs/cache/tar_scm/repo/16116456bfcb1e0bf47d540a1e517c9450cd5569d5e423d29b18ca045c555939; updating ... HEAD is now at 7860d00 Merge pull request #149 from MirantisDellCrowbar/bug/smoke/roxy/master Created crowbar-barclamp-swift-1.7+git.1383238227.7860d00.tar Compressed crowbar-barclamp-swift-1.7+git.1383238227.7860d00.tar to crowbar-barclamp-swift-1.7+git.1383238227.7860d00.tar.bz2 Detected version as 1.7+git.1383238227.7860d00 Updated first occurrence (if any) of Version in crowbar-barclamp-swift.spec to 1.7+git.1383238227.7860d00
Now let’s invoke refresh_patches by hand:
saschpe@duff:% /usr/lib/obs/service/refresh_patches Patch pull-request-124.patch ok Patch pull-request-148.patch refreshed Patch fix-swift-defaults.patch ok Patch suse-branding.patch ok Applying patch hide-unneeded-options.patch patching file crowbar_framework/app/views/barclamp/swift/_edit_attributes.html.haml Hunk #1 succeeded at 11 (offset -5 lines). Hunk #2 succeeded at 34 (offset -5 lines). Hunk #3 FAILED at 47. Hunk #4 succeeded at 65 (offset -14 lines). 1 out of 4 hunks FAILED -- rejects in file crowbar_framework/app/views/barclamp/swift/_edit_attributes.html.haml Patch hide-unneeded-options.patch does not apply (enforce with -f)
So it told us all patches except the last are ok. Let’s fix that.
saschpe@duff:% vi hide-unneeded-options.patch ... "hide-unneeded-options.patch" 43L, 3681C written
Now we can run it again:
saschpe@duff:% /usr/lib/obs/service/refresh_patches Patch pull-request-124.patch ok Patch pull-request-148.patch ok Patch fix-swift-defaults.patch ok Patch suse-branding.patch ok Patch hide-unneeded-options.patch ok Patch proposal-keystone-dep.patch refreshed Finished refreshing patches for crowbar-barclamp-swift.spec saschpe@duff:% osc st ? crowbar-barclamp-swift-1.7+git.1383238227.7860d00.tar.bz2 M crowbar-barclamp-swift.spec M hide-unneeded-options.patch
Everything refreshed, nice and tidy.As you can see, the first patch was refreshed during the first run, then things broke and we fixed it. After running again, everything was ok. So this is what you would end up with your local osc checkout:
saschpe@duff:% osc st ? crowbar-barclamp-swift-1.7+git.1383238227.7860d00.tar.bz2 M crowbar-barclamp-swift.spec M hide-unneeded-options.patch M pull-request-148.patch
Now we only have to issue osc addremove and osc build and commit everything afterwards. We didn’t had to touch the spec file, we didn’t had to untar anything and we didn’t had to invoke quilt. Ah and did I tell you that it autogenerates changes entries for you too:
Index: crowbar-barclamp-swift.changes =================================================================== --- crowbar-barclamp-swift.changes (revision caef0f9f0d1cb92298ad184a4f2a1efe) +++ crowbar-barclamp-swift.changes (working copy) @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Nov 08 14:19:31 UTC 2013 - speilicke@suse.com + +- Rebased patches: + + fix-swift-defaults.patch (manually) + + pull-request-148.patch (only offset) + ------------------------------------------------------------------- Fri Nov 8 10:24:11 UTC 2013 - speilicke@suse.com
So if you want to give it a try, you can install the package obs-service-refresh_patches from the openSUSE:Tools OBS repository. Then you have to put the following at the end of your _service file (after the other services that modify sources):
<service name="refresh_patches" mode="disabled"> <param name="changesgenerate">enable</param> </service>;
Now you are only one osc service disabledrun away from one issue less to care for. It is probably best to run this service only locally, i.e. with either mode=”disabled” or mode=”localonly”. This way you can still check that the refreshed patches won’t break anything.
Happy packaging!
Great stuff 🙂
I am not sure how this helps. I don’t get only offset numbers, just the following:
/usr/lib/obs/service/refresh_patches
Applying patch patches/scintilla-shared.patch
patching file gtk/makefile
Hunk #1 FAILED at 42.
Hunk #2 FAILED at 71.
Hunk #3 FAILED at 104.
Hunk #4 FAILED at 113.
4 out of 4 hunks FAILED — rejects in file gtk/makefile
Patch patches/scintilla-shared.patch does not apply (enforce with -f)