From 857840ebb5b60c231bd4b42be493a61b4e7697ab Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 6 Nov 2023 08:31:51 +0100 Subject: [PATCH] ci(dist): use Go (S)RPM macros only when available The Go (S)RPM macros are available in recent Fedora versions (i.e. all of them, assuming the non-EOL ones), and in EL starting from 9; this means that, in order to build on older distros (i.e. EL 8) we need to avoid them. Hence: - introduce an helper variable to easily track their availability - limit the usage of %go macros only when available, falling back to other macros (such as %autosetup and %meson_test) - define few %go variables that would be set by %gometa, so there are less differences around - limit the "-f" (i.e. "future archs") %gometa flag only on Fedora for now; the latest RHEL 9 release (9.2) has a bug [1] that prevents it to work - explicitly use the "-k" (i.e. "do not remove the "vendor" subdir) %goprep flag only on EL, since on this distro family bundling is used for the Go dependencies [1] https://bugzilla.redhat.com/show_bug.cgi?id=2227224 Signed-off-by: Pino Toscano --- dist/srpm/yggdrasil.spec.in | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/dist/srpm/yggdrasil.spec.in b/dist/srpm/yggdrasil.spec.in index 1dbf0d65..10596fcb 100644 --- a/dist/srpm/yggdrasil.spec.in +++ b/dist/srpm/yggdrasil.spec.in @@ -8,6 +8,8 @@ %bcond_without check +%global has_go_rpm_macros (0%{?fedora} || 0%{?rhel} >= 9) + # must be before %%gometa Version: @VERSION@ @@ -17,10 +19,13 @@ Version: @VERSION@ %global shortcommit %(c=%{commit}; echo ${c:0:7}) %global archivename yggdrasil-%{version} -%if 0%{?fedora} -%gometa -f +%if %{has_go_rpm_macros} +%gometa %{?fedora:-f} %else -%gometa +%global gourl https://github.com/RedHatInsights/%{name} +%global gomodulesmode GO111MODULES=off +%global gosource %{gourl}/releases/download/%{version}/yggdrasil-%{version}.tar.gz +%global gocompilerflags "-buildmode pie -compiler gc" %endif # Manually redefine %%dist to work around an issue in COPR where the build root @@ -60,13 +65,15 @@ BuildRequires: pkgconfig(bash-completion) %description %{common_description} +%if %{has_go_rpm_macros} %gopkg +%endif %prep -%if 0%{?fedora} -%goprep +%if %{has_go_rpm_macros} +%goprep %{?rhel:-k} %else -%goprep -k +%autosetup %endif %if 0%{?fedora} @@ -84,11 +91,17 @@ export %gomodulesmode %global gosupfiles ./ipc/com.redhat.Yggdrasil1.Dispatcher1.xml ./ipc/com.redhat.Yggdrasil1.Worker1.xml %install %meson_install +%if %{has_go_rpm_macros} %gopkginstall +%endif %if %{with check} %check +%if %{has_go_rpm_macros} %gocheck +%else +%meson_test +%endif %endif %files @@ -104,4 +117,6 @@ export %gomodulesmode %{_datadir}/doc/%{name}/* %{_mandir}/man1/* +%if %{has_go_rpm_macros} %gopkgfiles +%endif