rpm-software-management / mock

Mock is a tool for a reproducible build of RPM packages.
GNU General Public License v2.0
376 stars 220 forks source link

Mock build can produce two SRPM packages in the results directory #1344

Open FrostyX opened 4 months ago

FrostyX commented 4 months ago

Short description of the problem

When using rpmautospec (or probably any other way to dynamically generate version or release number, Mock can generate multiple SRPM packages in the results directory.

We should either fix it or let Mock gracefully fail, refusing to finish such a build.

Output of rpm -q mock

mock-5.5-1.fc39.noarch

Steps to reproduce issue

  1. Make sure the results directory is empty sudo rm -rf /var/lib/mock/fedora-40-x86_64/result/*
  2. Download the spec file and sources tarball attached to this issue
  3. Sorry, GitHub doesn't support spec files mv hello.spec.txt hello.spec
  4. mock -r fedora-40-x86_64 --sources hello-2.12.1.tar.gz --spec hello.spec
  5. ls /var/lib/mock/fedora-40-x86_64/result |grep src.rpm

Example output:

hello-2.12.1-1709662065.fc40.src.rpm
hello-2.12.1-1709662068.fc40.src.rpm

Also, the final RPM filename differs from both of them - hello-2.12.1-1709662074.fc40.x86_64.rpm

Any additional notes

We encountered this issue several times in Copr and it was always confusing and hard to debug. Last reported case was https://github.com/fedora-copr/copr/issues/3110

FrostyX commented 4 months ago

I am pasting the whole specfile here for easier reading in the browser

## START: Set by rpmautospec
## (rpmautospec version 0.6.1)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    -- Packages use something like this:
    -- release_number = 18;
    -- base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    -- print(release_number + base_release_number - 1);

    -- But a more reliable reproducer is the following
    print(os.time())
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

Name:           hello
Version:        2.12.1
Release:        %autorelease
Summary:        Prints a familiar, friendly greeting
# All code is GPLv3+.
# Parts of the documentation are under GFDL
License:        GPL-3.0-or-later AND GFDL-1.3-or-later
URL:            https://www.gnu.org/software/hello/
Source0:        https://ftp.gnu.org/gnu/hello/hello-%{version}.tar.gz

BuildRequires:  gcc
BuildRequires:  gnupg2
BuildRequires:  make
Recommends:     info
Provides:       bundled(gnulib)

%description
The GNU Hello program produces a familiar, friendly greeting.
Yes, this is another implementation of the classic program that
prints “Hello, world!” when you run it.

However, unlike the minimal version often seen, GNU Hello processes
its argument list to modify its behavior, supports greetings in many
languages, and so on. The primary purpose of GNU Hello is to
demonstrate how to write other programs that do these things; it
serves as a model for GNU coding standards and GNU maintainer
practices.

%prep
%setup -q

%build
%configure
%make_build

%install
%make_install
rm -f %{buildroot}%{_infodir}/dir
%find_lang hello

%files -f hello.lang
%license COPYING
%{_mandir}/man1/hello.1*
%{_bindir}/hello
%{_infodir}/hello.info*

%changelog
%autochangelog
FrostyX commented 4 months ago

It is also worth mentioning that this issue happens only when calling mock with --spec and --sources. If you specify a SRPM on the input, there will be only one SRPM in the results directory. Even though with a different release number than the original (I think this is fine).

xsuchy commented 4 months ago

Note for myself: maybe this can be reproduced by %generatebuildrequires that makes more src.rpm.