#89 rpmdev-bumpspec: errors with load buitlin macro: failed to load macro file
Opened by jaruga. Modified

When running the rpmdev-bumpspec for a RPM spec file that has load buildin macro on Fedora 34, the command shows errors (1st issue), and also the exit status is 0 (2nd issue), and as a result, NVR version number is not written on the spec file (3rd issue).

I prepared the reproducer https://github.com/junaruga/report-rpmlint-load that was used to report a rpmlitn issue with the buitin load macro in the past.

$ rpmdev-bumpspec --version
rpmdev-bumpspec version 1.0.13
Copyright (c) 2005-2014 Fedora Project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
$ rpm -qf /bin/rpmdev-bumpspec
rpmdevtools-9.5-1.fc34.noarch

Here are the steps to reproduce.

$ git clone https://github.com/junaruga/report-rpmlint-load.git
$ cd report-rpmlint-load
$ rpmdev-bumpspec test.spec 
error: test.spec: line 9: failed to load macro file /home/jaruga/rpmbuild/SOURCES/macros.test
error: query of specfile test.spec failed, can't parse
$ echo $?
0
$ git diff
diff --git a/test.spec b/test.spec
index f17830a..764c88e 100644
--- a/test.spec
+++ b/test.spec
@@ -1,6 +1,6 @@
 Name: test
 Version: 1
-Release: 1%{?dist}
+Release: 2%{?dist}
 Summary: Test
 License: Public Domain
 URL: https://github.com/junaruga/report-rpmlint-load
@@ -29,5 +29,8 @@ install -m 0755 test %{buildroot}/%{_bindir}/test
 %{_bindir}/test
 %changelog
+* Thu Aug 19 2021 Jun Aruga <jaruga@redhat.com>
+- rebuilt
+
 * Fri Mar 26 2021 Jun Aruga <jaruga@redhat.com> - 1-1
 - Init.

As a note, I can do mock build the spec file.

$ fedpkg --release rawhide srpm
$ mock test-1-1.fc36.src.rpm

A Mock build with a full src.rpm as input is not the same than loading an isolated spec file. As one can see, the RPM backend is configured to look for source files in $HOME/rpmbuild/SOURCES/ which may be an entirely different folder than where the spec file is stored when running rpmdev-bumpspec on it.

The workaround probably will require something like this:

--- /usr/bin/rpmdev-bumpspec    2021-07-17 18:36:08.000000000 +0200
+++ rpmdev-bumpspec 2021-08-19 17:48:29.171004230 +0200
@@ -398,6 +398,7 @@
         # Get EVR for changelog entry.
         cmd = ("rpm", "-q", "--specfile", "--define", "dist %{nil}",
+               "--define", "_sourcedir "+os.getcwd(),
                "--qf=%|epoch?{%{epoch}:}:{}|%{version}-%{release}\n", aspec)
         popen = subprocess.Popen(cmd, stdout=subprocess.PIPE)
         evr = popen.communicate()[0].split(b"\n")[0]

A Mock build with a full src.rpm as input is not the same than loading an isolated spec file. As one can see, the RPM backend is configured to look for source files in $HOME/rpmbuild/SOURCES/ which may be an entirely different folder than where the spec file is stored when running rpmdev-bumpspec on it.

OK. Thanks for the workaround. By the way, here is a PR merged in rpmlint to fix errors in the spec file including load builtin macro as a reference.
https://github.com/rpm-software-management/rpmlint/pull/633

The workaround probably will require something like this:

Thanks I confirmed your workaround with the patch works.

For the 2nd issue that the rpmdev-bumpspec finishes with exist status 0 even when an error happens in the command. I expect the command finishes with an exist status non zero when an error happens. I assume we need to modify an error handling logic.

For the 3rd issue that a RPM spec file is modified in incomplete status. I expect the spec file is not modified when an error happens in the process of running rpmdev-bumpspec. For the solution, I think there might be a way to delay a timing of modifying the RPM spec file, verifying a RPM spec file and input files in advance.

Still an issue

Metadata