12

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.

devios1
  • 36,899
  • 45
  • 162
  • 260

2 Answers2

11

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.

artless noise
  • 21,212
  • 6
  • 68
  • 105
devios1
  • 36,899
  • 45
  • 162
  • 260
  • Alas, this doesn't work with RPM version 4.11.1 : if noclean is undefined, %{noclean} gets expanded to % { n o c l e a n } (without the spaces) rather than an empty string. – Bulletmagnet Oct 03 '14 at 09:15
3

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.

ulidtko
  • 14,740
  • 10
  • 56
  • 88