Skip to content

Commit

Permalink
ci(dist): use Go (S)RPM macros only when available
Browse files Browse the repository at this point in the history
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<something> macros only when available, falling
  back to other macros (such as %autosetup and %meson_test)
- define few %go<something> 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 <[email protected]>
  • Loading branch information
ptoscano authored and subpop committed Nov 13, 2023
1 parent 97694cc commit 857840e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions dist/srpm/yggdrasil.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

%bcond_without check

%global has_go_rpm_macros (0%{?fedora} || 0%{?rhel} >= 9)

# must be before %%gometa
Version: @VERSION@

Expand All @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -104,4 +117,6 @@ export %gomodulesmode
%{_datadir}/doc/%{name}/*
%{_mandir}/man1/*

%if %{has_go_rpm_macros}
%gopkgfiles
%endif

0 comments on commit 857840e

Please sign in to comment.