no1
no1

Reputation: 727

rpmbuild using .spec file deletes build directory

I am trying rpmbuild(4.11.3) using .spec file , but it deletes the builddirectory, I'd like rpmbuild not to delete any files in my build directory as I need them for other things after the RPM is built. I tried with -bi option but it didnt work, it deletes the build directory.

Here the SPEC file:

 Name: newfile
 Version: 1.0
 Release: 1%{?dist}
 AutoReqProv: no
 Prereq: /bin/chmod
 Prereq: /bin/chown
 Summary: Testing 
 %description
 TBD
 %install

 mkdir -p $RPM_BUILD_ROOT/test/opb

 %files -f testingfiles.files
 %defattr(-,root,root,755)
 %dir /test/opb
 %dir /test/opb
 %dir /test/opb/new
 %dir /test/opb/new1
 %dir /test/opb/new2
 %dir /test/opb/new2

Command :

 /usr/bin/rpmbuild --define '_tmppath /var/tmp/rpmgen24431.d' --define '_topdir pkg/tst' -bi --buildroot /testing/new/dest pkg/tst/newfile.spec

It deletes all the files inside /testing/new/dest. How to create rpm file without deleting build files.

Upvotes: 1

Views: 2317

Answers (1)

msuchy
msuchy

Reputation: 5417

You can add:

%define __spec_install_pre /bin/true

on top of your spec file.

But I feel real shame to provide this answer as your SPEC is already full of hack and this adds just another layer of a dirty hack. Instead of this question, you should rather ask how to do what you want to achieve with regular clean up of buildroot.

EDIT: __spec_install_pre is defined as:

__spec_install_pre %{___build_pre}
    [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"
    mkdir -p `dirname "$RPM_BUILD_ROOT"`
    mkdir "$RPM_BUILD_ROOT"
%{nil}

so if you define it as:

%{___build_pre}
    mkdir -p `dirname "$RPM_BUILD_ROOT"`
    mkdir "$RPM_BUILD_ROOT"
%{nil}

It will behave exactly the same, just not delete the buildroot. The multiline %define can be defined two ways, it depends on the version of your rpm. I will leave it up to you :)

Upvotes: 4

Related Questions