Below I'm going to go through my example of patching a source RPM, something that I've had to do for the first time this week. The information below is more a collation of documents that I've read on the internet in order to get this to work, hopefully in this version I've removed any assumtopn that has been made to ensure its very clear.
NOTE: I'm going to use a source RPM that I've patched as the example, but I'm still working through it. So I make no guarantees that it will work if anyone else is trying the same thing, the details are only show below so you are clear on how this works. The Linux version was RHEL6, on zlinux (s390x).
First you need to ensure that all the required packages are installed, for this you will need 'rpmbuild'. As you can see I also need a few other rpms installed to get this to work.
sudo yum install java-1.7.1-ibm-devel rpm-build rpmbuild tar wget
This build needs a copy of Maven on s390 (which also installs 'ant') - this guide covers it - https://github.com/linux-on-ibm-z/docs/wiki/Building-Maven
First we download the source RPM and setup the environment for our build, this of course will change depending on your own requirements:
$ wget http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5.4.5/SRPMS/hive-1.1.0+cdh5.4.5+199-1.cdh5.4.5.p0.8.src.rpm
$ sudo ln -s /home/test/work/maven/bin/mvn /usr/bin/mvn
$ export WORK_DIR=`pwd`
$ export PATH=$WORK_DIR/apache-ant-1.9.4/bin:$PATH
$ export JAVA_HOME=/usr/lib/jvm/java
$ export M2_HOME=$WORK_DIR/maven
$ export PATH=$JAVA_HOME/bin:$PATH:$M2_HOME/bin
$ export HADOOP_JAAS_DEBUG=true
$ rpmbuild --rebuild hive-1.1.0+cdh5.4.5+199-1.cdh5.4.5.p0.8.src.rpm
As you can see, first I try a '--rebuild' but it throws this error:
[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /home/test/rpmbuild/BUILD/hive-1.1.0-cdh5.4.5/ql/src/java/org/apache/hadoop/hive/ql/debug/Utils.java:[29,26] package com.sun.management does not exist [ERROR] /home/test/rpmbuild/BUILD/hive-1.1.0-cdh5.4.5/ql/src/java/org/apache/hadoop/hive/ql/debug/Utils.java:[36,27] cannot find symbol symbol: class HotSpotDiagnosticMXBean location: class org.apache.hadoop.hive.ql.debug.Utils
Its something that I've seen before and I need to apply this patch: https://issues.apache.org/jira/secure/attachment/12696113/HIVE-9545.1.patch.txt
As this is a change to the rpm, each time I run rebuild its going overwrite the files, so need to extract and put it all back together:
$ rpm -i hive-1.1.0+cdh5.4.5+199-1.cdh5.4.5.p0.8.src.rpm
Attempt a SRPM Build
$ cd rpmbuild/SPECS/
$ rpmbuild -ba hive.spec
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.1hYiNa (%build)
At this point make changes to the code until you get it to build successfully, taking note of them as you do. Then its just a matter of uncompromising the source and duplicating them in patch folder:
$ tar xzf hive-1.1.0-cdh5.4.5.tar.gz
cp -R hive-1.1.0-cdh5.4.5 hive-1.1.0-cdh5.4.5.p1
Copy all the changed files from the BUILD directory and then generate the patch file with the following command:
$ diff -Naur hive-1.1.0-cdh5.4.5 hive-1.1.0-$ cdh5.4.5.p01 > ../SOURCES/hive-1.1.0-$ cdh5.4.5.patch01
In our example the only file that has changed is the 'hive/ql/src/java/org/apache/hadoop/hive/ql/debug/Utils.java', as this makes a number of fixes so that I can use the IBM JDK, details are in the HIVE-9545.1.patch.txt above.
Then we need to edit the spec file to include this new patch
$ cp ../SPECS/hive.spec ../SPECS/hive.spec.org
$ vi ../SPECS/hive.spec
Add in patch and patch0 parameters, first after the name and source0 section add -
Then after %prep and %setup, add this:
You can then test this new patch with the rpmbuild command:
$ rpmbuild -ba SPECS/hive.spec
Finally generating a new source RPM with the included patch:
$ rpmbuild -bs SPECS/hive.spec
If your looking for another guide on how to do this, then please take a look at this link on how to patch and rebuild an RPM package, as it was the main guide I used to get my patching to work.