Thursday, October 11, 2012

Problems with new version of rpmbuild

The Problem

With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the following:

error: File not found: <path>/BUILDROOT/<product>-6.7.x86_64/<filename>

Previously rpmbuild would install and look for files under the rpm_top/BUILD directory, while now it looks under the new BUILDROOT directory.

The Solution

This is what I ended up doing to solve the problem. When I call rpmbuild I now define a new variable, for example:

$ centos_release=$(lsb_release -rs | sed 's/\.//')
$ rpmbuild --define "centos_release $centos_release" ... -bb specfile 



then I changed my spec file to contain something like the following:

%if %{centos_release} >= 60

%setup -q -c -n %{buildroot}/usr/local/ 
cp -a -r %{buildroot}/usr/local/ /usr/
 
%else
 
%setup -q -c -n usr/local/
%install
cp -a -r $PWD /usr/
 
%endif

Another related problem

Suppose you have a single tar ball and you want to create two or more RPMs using different spec files. The new version of rpmbuild automatically cleans the BUILDROOT directory after completing the targets for a given spec file. If you want to save time and have the second spec file just look for the BUILDROOT created by the first spec it won't find it because of the automatic clean. So it seems like you are forced to untar and install under the BUILDROOT your file over and over again.
A simple solution to this problem is to add a %clean directive to your spec file and do nothing to disable to automatic cleaning done by rpmbuild. Add the following line at the bottom of your spec file:

%clean

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.