diff --git a/.gitignore b/.gitignore index 0caaba2..0fc0323 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ /go-rpm-macros-3.0.15.tar.gz /go-rpm-macros-3.1.0.tar.gz /go-rpm-macros-3.2.0.tar.gz +/golist-0.10.3.tar.gz +/golist-0.10.3-vendor.tar.xz diff --git a/go-rpm-macros.spec b/go-rpm-macros.spec index 272f38c..538ee84 100644 --- a/go-rpm-macros.spec +++ b/go-rpm-macros.spec @@ -18,6 +18,27 @@ Version: 3.2.0 # make Go devel packages archful %global gopath %{_datadir}/gocode +# whether to bundle golist or require it as a dependency +%if 0%{?rhel} +%ifarch %{golang_arches} %{gccgo_arches} +%global bundle_golist 1 +%endif +%endif + +%global golist_version 0.10.3 +%if 0%{?bundle_golist} +# do not create debuginfo packages when we add a build section +%global debug_package %{nil} +%global golist_builddir %{_builddir}/golist-%{golist_version} +%global golist_goipath pagure.io/golist +# where to bundle the golist executable +%global golist_execdir %{_libexecdir}/go-rpm-macros +# define gobuild to avoid this package requiring itself to build +%define gobuild(o:) GO111MODULE=on go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "-B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '${LDFLAGS:-} '" -a -v %{?**}; +%else +%global debug_package %{nil} +%endif + Name: go-rpm-macros Release: %autorelease Summary: Build-stage rpm automation for Go packages @@ -25,10 +46,22 @@ Summary: Build-stage rpm automation for Go packages License: GPL-3.0-or-later URL: %{forgeurl} Source: %{forgesource} +Source1: https://pagure.io/golist/archive/v%{golist_version}/golist-%{golist_version}.tar.gz +# vendored dependency tarball, to create: +# tar xf golist-%%{golist_version}.tar.gz ; pushd golist-%%{golist_version} ; \ +# go mod init %%{golist_goipath} && go mod tidy && go mod vendor && \ +# tar Jcf ../golist-%%{golist_version}-vendor.tar.xz go.mod go.sum vendor/ ; popd +Source2: golist-%{golist_version}-vendor.tar.xz Requires: go-srpm-macros = %{version}-%{release} Requires: go-filesystem = %{version}-%{release} + +%if 0%{?bundle_golist} +BuildRequires: golang +Provides: bundled(golist) = %{golist_version} +%else Requires: golist +%endif %ifarch %{golang_arches} Requires: golang @@ -94,6 +127,27 @@ for template in templates/rpm/*\.spec ; do touch -r "${template}" "${target}" done +# unpack golist and vendor deps +%if 0%{?bundle_golist} +pushd %{_builddir} +tar -xf %{SOURCE1} +cd golist-%{golist_version} +tar -xf %{SOURCE2} +cp %{_builddir}/golist-%{golist_version}/LICENSE %{_builddir}/go-rpm-macros-%{version}/LICENSE-golist +cp %{_builddir}/golist-%{golist_version}/vendor/modules.txt %{_builddir}/go-rpm-macros-%{version}/modules.txt +popd +%endif + +%build +# build golist +%if 0%{?bundle_golist} +pushd %{golist_builddir} +for cmd in cmd/* ; do + %gobuild -o %{golist_builddir}/bin/$(basename $cmd) ./$cmd +done +popd +%endif + %install install -m 0755 -vd %{buildroot}%{rpmmacrodir} @@ -141,9 +195,19 @@ install -m 0644 -vp rpm/macros.d/macros.go-compilers-gcc \ %{buildroot}%{_rpmconfigdir}/macros.d/ %endif +# install golist +%if 0%{?bundle_golist} +install -m 0755 -vd %{buildroot}%{golist_execdir} +install -m 0755 -vp %{golist_builddir}/bin/* %{buildroot}%{golist_execdir}/ +sed -i "s,golist ,%{golist_execdir}/golist ,g" \ + %{buildroot}%{_bindir}/go-rpm-integration \ + %{buildroot}%{_rpmconfigdir}/gosymlink.deps \ + %{buildroot}%{_rpmmacrodir}/macros.go-rpm +%endif + %ifarch %{golang_arches} %{gccgo_arches} %files -%license LICENSE.txt +%license LICENSE.txt %{?bundle_golist:LICENSE-golist modules.txt} %doc README.md %{_bindir}/* %{_rpmconfigdir}/fileattrs/*.attr @@ -152,6 +216,11 @@ install -m 0644 -vp rpm/macros.d/macros.go-compilers-gcc \ %{_rpmmacrodir}/macros.go-rpm* %{_rpmmacrodir}/macros.go-compiler* %{_rpmluadir}/fedora/rpm/*.lua +# package golist +%if 0%{?bundle_golist} +%{golist_execdir}/golist +%endif + %files -n go-rpm-templates %license LICENSE-templates.txt diff --git a/sources b/sources index ce81344..ea0f3be 100644 --- a/sources +++ b/sources @@ -1 +1,3 @@ SHA512 (go-rpm-macros-3.2.0.tar.gz) = 5d1a7773c0044b3046d6c0006b8aae441b17a52a79b65b3a704619433b1ed27cd59972703ba4cba17ec3f15755d7d81ae99401a7daac2217c3e58adb360a91c7 +SHA512 (golist-0.10.3.tar.gz) = 1b1e04eca2283d96976bbe3b2dec91d483f74e354fbe33292796c62db2a52865dd9d8c7e58e2ad7a5c875ace1347b1a253adad90eb6e8e5e0375e63e4b68fd90 +SHA512 (golist-0.10.3-vendor.tar.xz) = 39cf0784ad30bc854794f00d473dec8efc03e584de29d1d03bf160508fda2e53242ea844aae509ca03b08847dd2b144a85e48d4f58972b3752a5a41d8c22030a