Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rpmbuild %clean phase without removing files

Tags:

rpm

rpmbuild

I am getting the following in my build log:

Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.CgE2Qn
+ umask 022
+ cd /export/home/svn_checkouts/*snip*/Output/release/bin/packaging/BUILD
+ /bin/rm -rf /export/home/svn_checkouts/*snip*/Output/release/bin
+ exit 0

I'd like to avoid rpmbuild deleting all the files in my build directory as I need them for other things after the RPM is built. Can I override this behavior?

I read that some versions of RPM support a --noclean argument, but ours doesn't unfortunately.

like image 609
devios1 Avatar asked Dec 11 '12 23:12

devios1


People also ask

What is Buildroot in RPM spec file?

By using Buildroot: in your spec file you are indicating that your package can be built (installed into and packaged from) a user-definable directory. This helps package building by normal users. RPM will use the buildroot listed in the spec file as the default buildroot.

What is Rpmbuild?

rpmbuild is used to build both binary and source software packages. A package consists of an archive of files and meta- data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package.


2 Answers

Turns out I just needed to provide my own %clean directive in the spec file and leave it blank to override the default. For some reason I didn't expect that to work. ;)

A define can conditionalize the %Clean% phase so that the same effect as --noclean can be achieved.

%Clean
%if "%{noclean}" == ""
   rm -rf $RPM_BUILD_ROOT
%endif

Called with rpmbuild --define 'noclean 1' to disable cleaning.

like image 141
devios1 Avatar answered Oct 06 '22 08:10

devios1


For building from spec-file, rpmbuild has the -bi option. It leaves the $RPM_BUILD_ROOT as is; it does no %clean.

  -bi     build through %install (%prep, %build, then install) from <specfile>

(rpmbuild --help)


For building from SRPM (a source RPM package; yumdownloader will get you those), there is also --recompile option:

 --rebuild    build binary package from <source package>
 --recompile  build through %install (%prep, %build, then install) from <source package>

Finally, there is --noclean option for rpmbuild — but in my case (RPM version 4.11.3) it didn't work.

like image 3
ulidtko Avatar answered Oct 06 '22 08:10

ulidtko