From 53dc537ebf7c8389cb1f8e0bdcc6e6e04430327c Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Dec 02 2018 16:01:58 +0000 Subject: Split BuildRequires automation in a separate genbr macro Prepare for the infrastructure changes described in – https://github.com/rpm-software-management/rpm/issues/104 and – https://github.com/rpm-software-management/rpm/pull/593 --- diff --git a/rpm/macros.d/macros.go-rpm b/rpm/macros.d/macros.go-rpm index e62cad0..487d2a7 100644 --- a/rpm/macros.d/macros.go-rpm +++ b/rpm/macros.d/macros.go-rpm @@ -151,11 +151,6 @@ cd "%{mybuilddir}/src/%{mygoipath}" # Computes BuildRequires for a given import path. Optional argument: # -i use the specified import path value -%gobuildrequires(i:) %{expand: ( -golist --imported --package-path %{?-i*}%{!-i:%{currentgoipath}} --skip-self -golist --imported --package-path %{?-i*}%{!-i:%{currentgoipath}} --skip-self --tests) | sort -u | xargs -I{} echo "golang({})" -} - # Perform usual Go source preparation steps. Optional arguments: # -z read the zth block of definitions, for example # %{goipath}, %{commit}… @@ -172,7 +167,6 @@ golist --imported --package-path %{?-i*}%{!-i:%{currentgoipath}} --skip-self --t # -k keep the vendor directory, do not delete it # -e use extracted archives, do not perform %setup-like # operations -# -r resolve BuildRequires, but do not install them # -v be verbose %goprep(z:ai:b:s:kerv) %{lua: local fedora = require "fedora.common" @@ -191,7 +185,6 @@ local function process(suffix) print(rpm.expand("%setup " .. setupflags .. " %{?forgesetupargs" .. suffix .. "}\\n")) end print( rpm.expand("%gomkdir " .. zsuffix .. gomkdirflags .. "\\n")) - print('GOBUILDREQUIRES=$((sort -u |grep -v "^$" || :) <<< "$(' .. rpm.expand("%gobuildrequires") .. ')\\n${GOBUILDREQUIRES}")\\n') end -- Main loop if processall then @@ -201,10 +194,46 @@ if processall then else process(rpm.expand("%{?-z*}")) end +} + +# https://github.com/rpm-software-management/rpm/issues/104 +# Computes BuildRequires for a given import path. Arguments: +# -z read the zth block of definitions, for example +# %{goipath}, %{commit}… +# derived from the import path value if not specified +# -a process all sources in one go, instead of using separate +# -z calls +# -i use the specified import path value instead of the one +# found in %{goipath} +# -i use the specified import path value +# -r resolve BuildRequires, but do not install them +%gogenbr(z:ai:r) %{lua: +local fedora = require "fedora.common" +local installdeps = (rpm.expand("%{-r}") == "") +local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") +local goipath = rpm.expand("%{?-i*}") +-- https://github.com/gofed/symbols-extractor/issues/159 +local function process(suffix, goipath) + local goipath = (goipath ~= "") and goipath or rpm.expand("%{goipath" .. suffix .. "}") + print("golist --imported --package-path " .. goipath .. " --skip-self\\n") + print("golist --imported --package-path " .. goipath .. " --skip-self --tests\\n") +end +-- Main loop if installdeps then - print('[[ -n "${GOBUILDREQUIRES}" ]] && mock-install ${GOBUILDREQUIRES}\\n') - print('unset GOBUILDREQUIRES\\n') + print('mock-install ') +else + print('GOBUILDREQUIRES=') +end +-- https://github.com/gofed/symbols-extractor/issues/155 +print('$((sort -u | xargs -I{} echo "golang({})") <<< "$(\\n') +if processall then + for _, s in pairs(fedora.getsuffixes("goipath")) do + process(s, "") + end +else + process(rpm.expand("%{?-z*}"), rpm.expand(goipath)) end +print(')")\\n') } # Try to install Go package files in sensible locations, with strict directory diff --git a/templates/rpm/spectemplate-go-0-source-minimal.spec b/templates/rpm/spectemplate-go-0-source-minimal.spec index 1066e9c..f09efee 100644 --- a/templates/rpm/spectemplate-go-0-source-minimal.spec +++ b/templates/rpm/spectemplate-go-0-source-minimal.spec @@ -98,14 +98,13 @@ Source0: %{gosource} # template. # # https://github.com/rpm-software-management/rpm/issues/104 -# The following will eventually be split from ”goprep”. -# “gobuildrequires” computes the build dependencies of the packaged Go code and -# installs them in the build root. Assuming you fixed source problems after -# “goprep”, it should just work. -# Right now, “gobuildrequires” only manages version-less Go dependencies. If your +# “gogenbr” computes the build dependencies of the packaged Go code and +# will install them in the build root once infra has improved. Assuming you +# fixed source problems after “goprep”, it should just work. +# Right now, “gogenbr” only manages version-less Go dependencies. If your # project requires a specific dependency version, or something which is not Go # code, you need to declare the corresponding BuildRequires manually as usual. -#gobuildrequires +%gogenbr %install # Perform installation steps for all known kinds of Go subpackages diff --git a/templates/rpm/spectemplate-go-1-source-full.spec b/templates/rpm/spectemplate-go-1-source-full.spec index 7d322a7..bb8a0f2 100644 --- a/templates/rpm/spectemplate-go-1-source-full.spec +++ b/templates/rpm/spectemplate-go-1-source-full.spec @@ -88,7 +88,7 @@ Source0: %{gosource} %prep %goprep -#gobuildrequires +%gogenbr %install %gopkginstall diff --git a/templates/rpm/spectemplate-go-2-alternative-import-path-minimal.spec b/templates/rpm/spectemplate-go-2-alternative-import-path-minimal.spec index c3aaa7d..860fae0 100644 --- a/templates/rpm/spectemplate-go-2-alternative-import-path-minimal.spec +++ b/templates/rpm/spectemplate-go-2-alternative-import-path-minimal.spec @@ -49,7 +49,7 @@ Source0: %{gosource} %prep %goprep -#gobuildrequires +%gogenbr %install # Perform installation steps for all known kinds of Go subpackages. You can diff --git a/templates/rpm/spectemplate-go-3-alternative-import-path-full.spec b/templates/rpm/spectemplate-go-3-alternative-import-path-full.spec index bb68115..4a51aeb 100644 --- a/templates/rpm/spectemplate-go-3-alternative-import-path-full.spec +++ b/templates/rpm/spectemplate-go-3-alternative-import-path-full.spec @@ -73,7 +73,7 @@ Source0: %{gosource} %prep %goprep -#gobuildrequires +%gogenbr %install %gopkginstall diff --git a/templates/rpm/spectemplate-go-4-binary-minimal.spec b/templates/rpm/spectemplate-go-4-binary-minimal.spec index b4a2e05..1ec0159 100644 --- a/templates/rpm/spectemplate-go-4-binary-minimal.spec +++ b/templates/rpm/spectemplate-go-4-binary-minimal.spec @@ -46,7 +46,7 @@ Source0: %{gosource} %prep %goprep -#gobuildrequires +%gogenbr %build # You need to identify manually the project parts that can be built, and how to diff --git a/templates/rpm/spectemplate-go-5-binary-full.spec b/templates/rpm/spectemplate-go-5-binary-full.spec index d264cc1..4ef98db 100644 --- a/templates/rpm/spectemplate-go-5-binary-full.spec +++ b/templates/rpm/spectemplate-go-5-binary-full.spec @@ -63,7 +63,7 @@ Source0: %{gosource} %prep %goprep -#gobuildrequires +%gogenbr %build for cmd in cmd/* ; do diff --git a/templates/rpm/spectemplate-go-6-multi.spec b/templates/rpm/spectemplate-go-6-multi.spec index 2857a01..ea07bac 100644 --- a/templates/rpm/spectemplate-go-6-multi.spec +++ b/templates/rpm/spectemplate-go-6-multi.spec @@ -143,12 +143,12 @@ Source1: %{gosource1} %gopkg %prep -# “%goprep” and “gobuildrequires” accept the usual selection arguments: +# “%goprep” and “gogenbr” accept the usual selection arguments: # – “-a” process everything # – “-z ” process a specific declaration block # If no flag is specified they only process the zero/nosuffix block. %goprep -a -#gobuildrequires -a +%gogenbr -a %build # When your spec processes multiple Go source archives, you need to call diff --git a/templates/rpm/spectemplate-go-7-manual.spec b/templates/rpm/spectemplate-go-7-manual.spec index 7e07289..b0e43a8 100644 --- a/templates/rpm/spectemplate-go-7-manual.spec +++ b/templates/rpm/spectemplate-go-7-manual.spec @@ -63,7 +63,7 @@ your Go code depends on this package, you should patch it to import directly %prep %goprep -#gobuildrequires +%gogenbr %install # goinstall is our Go source installation workhorse. It accepts a huge and