Be more careful when loading the macros from sources

The %{?load:%{SOURCE102}} construct no longer works in RPM 4.17+

Currently, we:

1. Load %{SOURCE102} if it exists.
   This should always be the case when actually building the RPM or SRPM package.

2. Else, load macros.python-srpm if it exists.
   This is the case when something parses the spec from dist-git without setting
   %_sourcedir to the current working directory. E.g. rpmdev-bumpspec does this.

3. Else, don't load anything, get %{__default_python3_version} from the environment.
   This is the case when something parses the spec in isolation.
   Getting the version from sources is impossible, because the sources are missing.
   So we get the installed version instead. Note that this will blow up on Fedora < 33,
   but it already did before.
This commit is contained in:
Miro Hrončok 2021-04-27 10:50:50 +02:00
parent 187e049d6c
commit cad73c2159
1 changed files with 8 additions and 1 deletions

View File

@ -20,7 +20,14 @@ License: MIT and Python
# The package version MUST be always the same as %%{__default_python3_version}.
# To have only one source of truth, we load the macro and use it.
# The macro is defined in python-srpm-macros.
%{?load:%{SOURCE102}}
%{lua:
if posix.stat(rpm.expand('%{SOURCE102}')) then
rpm.load(rpm.expand('%{SOURCE102}'))
elseif posix.stat('macros.python-srpm') then
-- something is parsing the spec without _sourcedir macro properly set
rpm.load('macros.python-srpm')
end
}
Version: %{__default_python3_version}
Release: 37%{?dist}