Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 1686413

Summary: /usr/lib/rpm/redhat/brp-mangle-shebangs fails for non-existing RPM_BUILD_ROOT
Product: Red Hat Enterprise Linux 8 Reporter: Karel Srot <ksrot>
Component: redhat-rpm-configAssignee: Packaging Maintenance Team <packaging-team-maint>
Status: NEW --- QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: medium Docs Contact:
Priority: low    
Version: 8.0CC: dmach, fweimer, pmatilai
Target Milestone: rcKeywords: Triaged
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On: 1681082    
Bug Blocks:    

Description Karel Srot 2019-03-07 12:04:20 UTC
Description of problem:

# head /usr/lib/rpm/redhat/brp-mangle-shebangs
#!/bin/bash -eu

# If using normal root, avoid changing anything.
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
  exit 0

The above doesn't test whether the directory actually exists.
For a spec file which I am able to build on RHEL-7 successfully, I am getting following failure on RHEL-8:

/usr/lib/rpm/redhat/brp-mangle-shebangs: line 72: cd: /tmp/bz-ilrKNb/BUILDROOT/special-1.0-1.x86_64: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.5l4W0o (%install)

RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.5l4W0o (%install)

Changing the condition to the following fixed it for me.

if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" -o ! -d "$RPM_BUILD_ROOT" ]; then
  exit 0

Version-Release number of selected component (if applicable):

Comment 2 Panu Matilainen 2019-03-07 12:20:15 UTC
Actually none of the brp-scripts specifically test for buildroot existence, and eg brp-compress does similar unchecked cd into buildroot:

+ /usr/lib/rpm/check-buildroot
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
+ /usr/lib/rpm/redhat/brp-ldconfig
/sbin/ldconfig: Warning: ignoring configuration file that cannot be opened: /home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64/: No such file or directory
+ /usr/lib/rpm/brp-compress
/usr/lib/rpm/brp-compress: line 10: cd: /home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64: No such file or directory
+ /usr/lib/rpm/brp-strip /usr/bin/strip
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-python-bytecompile '%{__python}' 1 1
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-python-hardlink
find: '/home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64': No such file or directory
+ /usr/lib/rpm/redhat/brp-mangle-shebangs
/usr/lib/rpm/redhat/brp-mangle-shebangs: line 71: cd: /home/pmatilai/rpmbuild/BUILDROOT/special-1.0-1.x86_64: No such file or directory

The catch is that brp-mangle-shebangs runs with -e:
#!/usr/bin/bash -eu

Whatever the fix ends up being, I agree these things should behave consistently.

Comment 3 Karel Srot 2019-03-07 12:43:26 UTC
That is correct. These errors are reported even on RHEL-7, however none of them prevents the package from being built.