Bug 43677

Summary: rpmbuild --root affects %buildroot inconsistently, so that builds fail
Product: Sisyphus Reporter: Ivan Zakharyaschev <imz>
Component: rpm-buildAssignee: placeholder <placeholder>
Status: NEW --- QA Contact: qa-sisyphus
Severity: minor    
Priority: P5 CC: arseny, glebfm, imz, ldv, placeholder, vt
Version: unstable   
Hardware: x86_64   
OS: Linux   

Description Ivan Zakharyaschev 2022-08-31 22:27:01 MSK
rpm-build-4.0.4.184-alt1.x86_64

The problem is that if rpmbuild is used with --root, then this root prefix
is used inconsistently with %buildroot , which leads to the impossibility
to successfully build a package with non-empty %install and %files sections.

Example (with --root /tmp/.private/imz/tmp.0fLun0M6Iq):

warning: created %_tmppath directory /tmp/.private/imz/tmp.0fLun0M6Iq/tmp/.private/imz

0. rootdir prepended to %_tmppath (not really relevant for %buildroot)

+ umask 022
+ /bin/mkdir -p /tmp/.private/imz/tmp.0fLun0M6Iq/usr/src/RPM/BUILD
+ cd /tmp/.private/imz/tmp.0fLun0M6Iq/usr/src/RPM/BUILD
+ /bin/chmod -Rf u+rwX -- /tmp/.private/imz/large-package-buildroot
+ :
+ /bin/rm -rf -- /tmp/.private/imz/large-package-buildroot

1. Cleaned up buildroot, not inside rootdir

+ PATH=/usr/libexec/rpm-build:/home/imz/bin:/bin:/usr/bin:/usr/local/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin
+ mkdir -p /tmp/.private/imz/large-package-buildroot/usr/share/large-package

2. %buildroot (as used in %install) doesn't include rootdir

+ echo a
+ /usr/lib/rpm/brp-alt
egrep: warning: egrep is obsolescent; using grep -E
Hardlinking identical .pyc and .pyo files
Hardlinking identical .pyc and .opt-?.pyc files
error: No such file or directory: /tmp/.private/imz/tmp.0fLun0M6Iq/tmp/.private/imz/large-package-buildroot/usr/share/large-package

3. Processing %files: rootdir is prepended to buildroot, so the files
created in %install can't be found.

First part of a solution to this problem would be not to prepend rootdir
to buildroot when processing %files.

Second--optional and more tricky--part of the solution could be to somehow
prepend rootdir to the value of %buildroot, so that existing spec-files'
%install sections would operate under rootdir without modification.
(If this is really desired. rootdir might be just for reading the db
of installed packages, not for building...) After implementing the first
part of the solution, this wouldn't lead to an inconsistency between
%install and %files.

Currently, %buildroot is usually predefined by rpmbuild as
%{_tmppath}/%{name}-buildroot . There is no macro for the rootdir value,
but if there were one, it could be prepended to this definition.