Bug 2229971

Summary: rpm variable $RPM_BUILD_DIR stopped expanding in %files %doc
Product: [Fedora] Fedora Reporter: Jaroslav Škarvada <jskarvad>
Component: rpmAssignee: Packaging Maintenance Team <packaging-team-maint>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: igor.raits, mdomonko, packaging-team-maint, pmatilai
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-08-08 13:06:00 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jaroslav Škarvada 2023-08-08 10:47:45 UTC
rpm-4.18.92-1.fc39


Reproducible: Always

Steps to Reproduce:
1. use $RPM_BUILD_DIR in %files %doc
2.
3.

Actual Results:  
It is not expanded

Expected Results:  
It is expanded

It was working for a long time, e.g. here:
https://kojipkgs.fedoraproject.org//packages/espeak/1.48.04/24.fc38/data/logs/x86_64/build.log

Where:
cp -pr /builddir/build/BUILD/espeak-1.48.04-source/ReadMe /builddir/build/BUILDROOT/espeak-1.48.04-24.fc38.x86_64/usr/share/doc/espeak

Was originally in the espeak spec:
%doc $RPM_BUILD_DIR/espeak-%{version}-source/ReadMe

Now it doesn't expand, e.g.:
https://kojipkgs.fedoraproject.org//work/tasks/1116/104531116/build.log

+ cp -pr '/builddir/build/BUILD/espeak-1.48.04-source/$RPM_BUILD_DIR/espeak-1.48.04-source/ReadMe' /builddir/build/BUILDROOT/espeak-1.48.04-25.fc39.x86_64/usr/share/doc/espeak
cp: cannot stat '/builddir/build/BUILD/espeak-1.48.04-source/$RPM_BUILD_DIR/espeak-1.48.04-source/ReadMe': No such file or directory

It breaks several builds.

Comment 1 Fedora Update System 2023-08-08 13:05:27 UTC
FEDORA-2023-e4d5549651 has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-e4d5549651

Comment 2 Fedora Update System 2023-08-08 13:06:00 UTC
FEDORA-2023-e4d5549651 has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 3 Michal Domonkos 2023-08-08 15:31:44 UTC
(In reply to Jaroslav Škarvada from comment #0)
> Was originally in the espeak spec:
> %doc $RPM_BUILD_DIR/espeak-%{version}-source/ReadMe

Environment variables were never supported in the %files section.  The reason it worked previously was just a side effect of RPM passing the filenames verbatim to the "cp" command in a shell script that it internally creates in order to copy %doc entries to the build root.

There is a bug fix in the 4.19 codebase which makes those filenames single-quoted, to prevent any shell meta characters to interfere, including the dollar sign, which is why you're seeing this behavior now.  This is the patch:
https://github.com/rpm-software-management/rpm/commit/a06374be2f85e457cb526edb8ead40f57c82bfd6

Hence, the fix here would be to use the %{_builddir} macro which gets expanded at SPEC parse time, i.e. before "cp" is invoked.

That said, you don't need to specify an absolute path here.  The %doc directive, if given a relative path, looks for the filename relative to the build directory [1].  I can see you've already fixed this in your SPEC so that relative paths are used instead, which is correct.

[1] http://ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html

Comment 4 Michal Domonkos 2023-08-08 15:40:18 UTC
Not sure why the needinfo flag was activated, fixing.

Comment 5 Michal Domonkos 2023-08-08 15:49:31 UTC
Minor correction for:

(In reply to Michal Domonkos from comment #3)
> Hence, the fix here would be to use the %{_builddir} macro which gets
> expanded at SPEC parse time, i.e. before "cp" is invoked.

This actually wouldn't work since the macro would expand to an absolute path at parse time, triggering the code path in RPM that treats the %doc entry as a path relative to the build root, not build dir.  So you would need to install the file to the appropriate location in %install and refer to it normally as any other %files entry here, or specify a relative path to make it do that automatically (as you now do).

Comment 6 Panu Matilainen 2023-08-09 09:02:18 UTC
Changing resolution to NOTABUG which this is. Linking this to an errata gives an impression of something being fixed in rpm for this which is not the case.