From 12af9309a1c7b2b929291cf7f6e9dcc78e9bfd39 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Sep 15 2022 16:10:58 +0000 Subject: Sources: Add section about conditionalization A common mistake when writing multi-distro/multi-release spec files is to conditionalize the source tarball or patch entries. While this may generally work in Fedora because of how we always rebuild the SRPM for the target build, it's bad practice and prevents the reuse of SRPMs on other releases. This new section requires that all sources be shipped in the SRPM and then their use (rather than presence) is conditionalized. Signed-off-by: Stephen Gallagher --- diff --git a/guidelines/modules/ROOT/pages/SourceURL.adoc b/guidelines/modules/ROOT/pages/SourceURL.adoc index c3e8179..a33bc26 100644 --- a/guidelines/modules/ROOT/pages/SourceURL.adoc +++ b/guidelines/modules/ROOT/pages/SourceURL.adoc @@ -231,3 +231,39 @@ Sometimes this does not work because the upstream cgi tries to parse the fragmen # https://dev.mysql.com/downloads/mysql/5.1.html Source: mysql-5.1.31.tar.gz .... + +== Do not conditionalize Sources + +When building an SRPM, it is critical that all of the sources are present, irrespective of the platform on which the SRPM is generated. For example, the following code *does not work* (the way you might expect): + +.... +%if 0%{?fedora} < 35 +Source1: mysource-old.tar.bz2 +Patch1: oldpatch.patch +%else +Source1: mysource-ng.tar.bz2 +Patch1: ngpatch.patch +%endif +.... + +If you were to build this SRPM from a Fedora 34 host (`rpmbuild -bs mysource.spec`), the resulting SRPM would carry `mysource-old.tar.bz2` and `oldpatch.patch`. However, if you then try to use this SRPM to build for Fedora 35, the operation would fail because `mysource-ng.tar.bz2` is not available. + +The correct behavior is to always carry all of the sources that might be used in the build and then conditionalize the *usage* of them instead. For example: + +``` +Source1: mysource-old.tar.bz2 +Source2: mysource-ng.tar.bz2 + +Patch1: oldpatch.patch +Patch2: ngpatch.patch +... +%prep +... +%if 0%{?fedora} < 35 +tar xf %{SOURCE1} +%patch1 -p1 +%else +tar xf %{SOURCE2} +%patch2 -p1 +%endif +``` \ No newline at end of file