1

I am attempting to build an RPM using the -bb flag (%prep %build %install %check package). This is the output of the %install step:

Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.2kgeNY
+ umask 022
+ cd /<redacted>/BUILD
+ '[' /<redacted>/BUILDROOT/<redacted>.i386 '!=' / ']'
+ rm -rf /<redacted>/BUILDROOT/<redacted>.i386
++ dirname /<redacted>/BUILDROOT/<redacted>.i386
+ mkdir -p /<redacted>/BUILDROOT
+ mkdir /<redacted>/BUILDROOT/<redacted>.i386
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars

Here are the contents of that tmp file:

  RPM_SOURCE_DIR="/<redacted>/SOURCES"
  RPM_BUILD_DIR="/<redacted>/BUILD"
  RPM_OPT_FLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m32 -march=x86-64 -mtune=generic -mfpmath=sse -fasynchronous-unwind-tables"
  RPM_LD_FLAGS="-Wl,-z,relro "
  RPM_ARCH="i386"
  RPM_OS="linux"
  export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_LD_FLAGS RPM_ARCH RPM_OS
  RPM_DOC_DIR="/usr/share/doc"
  export RPM_DOC_DIR
  RPM_PACKAGE_NAME="<redacted>"
  RPM_PACKAGE_VERSION="<redacted>"
  RPM_PACKAGE_RELEASE="<redacted>"
  export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
  LANG=C
  export LANG
  unset CDPATH DISPLAY ||:
  RPM_BUILD_ROOT="/<redacted>/BUILDROOT/<redacted>.i386"
  export RPM_BUILD_ROOT

  PKG_CONFIG_PATH="%{_PKG_CONFIG_PATH}:/usr/lib/pkgconfig:/usr/share/pkgconfig"
  export PKG_CONFIG_PATH
  set -x
  umask 022
  cd "/<redacted>/BUILD"
    [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"
    mkdir -p `dirname "$RPM_BUILD_ROOT"`
    mkdir "$RPM_BUILD_ROOT"




    /usr/lib/rpm/check-buildroot

    /usr/lib/rpm/redhat/brp-compress

    /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
    /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump

    /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
    /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
    /usr/lib/rpm/redhat/brp-python-hardlink
    /usr/lib/rpm/redhat/brp-java-repack-jars

I have not overwritten the %install behavior in my spec file. My spec file looks like this:

<stuff>
%prep
%build
%install
%files
<more stuff>

Is the default %install behavior defined in the rpm-builder documentation anywhere? How do I know what it's going to execute?

  • Can you still access /var/tmp/rpm-tmp.2kgeNY after rpmbuild completes? That will list everything run by %install. – garethTheRed Sep 11 '14 at 15:13
  • no, it seems to be getting deleted. – smcg Sep 11 '14 at 15:18
  • The docs and the Fedora wiki don't give much away. – garethTheRed Sep 11 '14 at 15:25
  • I added the contents of that file to my question. – smcg Sep 11 '14 at 15:45
  • 1
    they contained product names and versions. – smcg Sep 11 '14 at 16:59
1

The %install phase in an RPM spec file is supposed to create a filesystem hierarchy that is unpacked into a system when you install the resulting rpm. This whole hierarchy is to be created in the %{buildroot} (AKA $RPM_BUILD_ROOT) directory by the commands found in the %install section. Its contents is inserted verbatim (upon RPM macro expansions) into a script that is interpreted by shell - that is the line:

Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.2kgeNY

Now if you leave the %install phase empty, the contents of the script is not - because it initialises various things that a packager will very likely want to use during the installation ($RPM_BUILD_ROOT is one of the important ones).

What exactly the initialisation does is distribution dependent - check the contents of the rpm package (rpm -ql rpm), files like /usr/lib/rpm/macros (might be in somewhere else on your system) are good candidates to contain (RPM) macros that are expanded around what you put in the %install phase of your the spec file.

That said, most often (especially with software that uses autotools) the main part of the %install phase should be

make install DESTDIR=%{buildroot}

The %make_install macro should do exactly that. Some distributions also have a similar RPM macro "shortcut" like e.g. %makeinstall in openSUSE, which may offer some additional features over the generic upstream one.

  • I tried writing my own %install code in my spec file, but it is executing it is still executing its own code right before mine. – smcg Sep 11 '14 at 18:39
  • And it always will - re-read the answer please. – peterph Sep 11 '14 at 19:44
  • ah, I misread your answer, I thought it was initializing iff I "leave the %install phase empty" – smcg Sep 11 '14 at 20:41
  • basically my problem is that the %install is doing an rm -rf of my BUILDROOT directory but later steps depend on having some of those files there. – smcg Sep 11 '14 at 20:42
  • Yes, it removes $RPM_BUILD_ROOT and than it re-creates it - that is to ensure the tree contained therein is not going to be tainted - it's far from being secure (racy) so it won't prevent malicious activities, but it's enough to make sure something doesn't go wrong accidentally. The %install phase should be contained in the place where you have four empty lines in the script (I suppose you have these in the %install section). What follows are various checks and so on (debug symbols stripping, for example). – peterph Sep 12 '14 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.