From cad73c2159567a9857783c56f6b88fc8346a5df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 27 Apr 2021 10:50:50 +0200 Subject: [PATCH] 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. --- python-rpm-macros.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 9094b3e..2a5f6fa 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -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}