diff --git a/rpm/fileattrs/go.attr b/rpm/fileattrs/go.attr index d4d5761..a9000a7 100644 --- a/rpm/fileattrs/go.attr +++ b/rpm/fileattrs/go.attr @@ -2,5 +2,3 @@ %__go_path ^%{gopath}/src/.+/.goipath$ %__go_flags path -%__go_provides go-rpm-integration provides --prefix "%{buildroot}" --go-path "%{gopath}" %{?goprovflags} -%__go_requires go-rpm-integration requires --prefix "%{buildroot}" --go-path "%{gopath}" %{?goreqflags} diff --git a/rpm/lua/rpm/go.lua b/rpm/lua/rpm/go.lua index cb5f958..fb42cb7 100644 --- a/rpm/lua/rpm/go.lua +++ b/rpm/lua/rpm/go.lua @@ -72,63 +72,6 @@ local function env(suffix, goipath, verbose, usermetadata) fedora.explicitset( "currentgoldflags", ldflags, verbose) end --- Create a single set of %install tasks for a known kind of Go subpackage -local function singleinstall(kind, suffix, verbose) - local go = require "fedora.srpm.go" - if (kind == "devel") then - go.develenv(suffix, verbose) - for goipath in string.gmatch(rpm.expand("%{currentgoipaths}"), "[^%s]+") do - env('', goipath, verbose, {}) - local vflag = verbose and " -v" or "" - print(rpm.expand("%__godevelinstall -i " .. goipath .. vflag .. "\n")) - end - print(rpm.expand("%__godevelinstalldoc\n")) - elseif (kind == "alt") then - local fedora = require "fedora.common" - local ismain = (suffix == "") or (suffix == "0") - if ismain then - fedora.zalias({"goaltipaths","gocid","goaltcid"}, verbose) - end - fedora.safeset("goaltcid" .. suffix, "%{?gocid" .. suffix .. "}", verbose) - if ismain then - fedora.zalias({"goaltcid"}, verbose) - end - for rpmname, goaltipaths in pairs(go.indexedgoipaths("%{goaltipaths" .. suffix .. "}", - "%{goaltcid" .. suffix .. "}")) do - go.altenv(suffix, rpmname, goaltipaths, verbose) - gocanonipath = rpm.expand("%{currentgocanonipath}") - for _, goaltipath in ipairs(goaltipaths) do - fedora.explicitset("currentgoaltipath", goaltipath) - print(rpm.expand("%__goaltinstall\n")) - goaltipath = string.gsub(goaltipath, "/?[^/]+/?$", "") - while (not string.match(gocanonipath, "^" .. goaltipath)) do - print(rpm.expand('echo \'%dir "%{gopath}/src/' .. goaltipath .. '"\' >> "%{goworkdir}/%{currentgoaltfilelist}"\n')) - goaltipath = string.gsub(goaltipath, "/?[^/]+/?$", "") - end - end - end - else - rpm.expand("%{error:Unknown kind of Go subpackage: " .. kind .. "}") - end -end - --- Create one or all %install tasks for a known kind of go subpackage -local function install(kind, suffix, processall, verbose) - local fedora = require "fedora.common" - local go = require "fedora.srpm.go" - if (kind == "devel") then - go.develenvinit() - end - if processall then - for _, suffix in pairs(fedora.getsuffixes(go.pivot[kind])) do - singleinstall(kind, suffix, verbose) - end - else - singleinstall(kind, suffix, verbose) - end -end - return { - env = env, - install = install, + env = env, } diff --git a/rpm/lua/srpm/go.lua b/rpm/lua/srpm/go.lua index 457b8f1..d650b26 100644 --- a/rpm/lua/srpm/go.lua +++ b/rpm/lua/srpm/go.lua @@ -232,104 +232,6 @@ local function altenv(suffix, rpmname, goaltipaths, verbose) end end --- Create a single %package section for a known kind of Go subpackage -local function singlepkg(kind, suffix, verbose) - local fedora = require "fedora.common" - if (kind == "devel") then - develenv(suffix, verbose) - print( - rpm.expand( - "%package -n %{currentgodevelname}\n" .. - "Summary: %{currentgodevelsummary}\n" .. - "BuildRequires: go-rpm-macros\n" .. - "BuildArch: noarch\n" .. - "%{?currentgodevelheader}\n" .. - "%description -n %{currentgodevelname}\n") .. - fedora.wordwrap("%{?currentgodeveldescription}") .. - "\n") - elseif (kind == "alt") then - local ismain = (suffix == "") or (suffix == "0") - if ismain then - fedora.zalias({"goaltipaths","gocid","goaltcid"}, verbose) - end - fedora.safeset("goaltcid" .. suffix, "%{?gocid" .. suffix .. "}", verbose) - if ismain then - fedora.zalias({"goaltcid"}, verbose) - end - for rpmname, goaltipaths in pairs(indexedgoipaths("%{goaltipaths" .. suffix .. "}", - "%{goaltcid" .. suffix .. "}")) do - altenv(suffix, rpmname, goaltipaths, verbose) - print( - rpm.expand( - "%package -n %{currentgoaltname}\n" .. - "Summary: %{currentgoaltsummary}\n" .. - "BuildRequires: go-rpm-macros\n" .. - "BuildArch: noarch\n" .. - "%{?currentgoaltheader}\n" .. - "%description -n %{currentgoaltname}\n") .. - fedora.wordwrap("%{?currentgoaltdescription}") .. - "\n") - end - else - rpm.expand("%{error:Unknown kind of Go subpackage: " .. kind .. "}") - end -end - --- Create one or all %package sections for a known kind of go subpackage -local function pkg(kind, suffix, processall, verbose) - local fedora = require "fedora.common" - if (kind == "devel") then - develenvinit() - end - if processall then - for _, suffix in pairs(fedora.getsuffixes(pivot[kind])) do - singlepkg(kind, suffix, verbose) - end - else - singlepkg(kind, suffix, verbose) - end -end - --- Create a single %files section for a known kind of Go subpackage -local function singlefiles(kind, suffix, verbose) - if (kind == "devel") then - develenv(suffix, verbose) - print(rpm.expand('%files -n %{currentgodevelname} -f "%{goworkdir}/%{currentgodevelfilelist}"\n')) - elseif (kind == "alt") then - local fedora = require "fedora.common" - local ismain = (suffix == "") or (suffix == "0") - if ismain then - fedora.zalias({"goaltipaths","gocid","goaltcid"}, verbose) - end - fedora.safeset("goaltcid" .. suffix, "%{?gocid" .. suffix .. "}", verbose) - if ismain then - fedora.zalias({"goaltcid"}, verbose) - end - for rpmname, goaltipaths in pairs(indexedgoipaths("%{goaltipaths" .. suffix .. "}", - "%{goaltcid" .. suffix .. "}")) do - altenv(suffix, rpmname, goaltipaths, verbose) - print(rpm.expand('%files -n %{currentgoaltname} -f "%{goworkdir}/%{currentgoaltfilelist}"\n')) - end - else - rpm.expand("%{error:Unknown kind of Go subpackage: " .. kind .. "}") - end -end - --- Create one or all %files sections for a known kind of go subpackage -local function files(kind, suffix, processall, verbose) - local fedora = require "fedora.common" - if (kind == "devel") then - develenvinit() - end - if processall then - for _, suffix in pairs(fedora.getsuffixes(pivot[kind])) do - singlefiles(kind, suffix, verbose) - end - else - singlefiles(kind, suffix, verbose) - end -end - return { rpmname = rpmname, meta = meta, @@ -338,6 +240,5 @@ return { develenvinit = develenvinit, develenv = develenv, altenv = altenv, - pkg = pkg, - files = files, } + diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index b0ab4c4..942549f 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -20,6 +20,8 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +%gocompilerflags -buildmode pie -compiler gc + # This *must* be all on one line, as it will be used in shell # assignments. eg # @@ -29,22 +31,33 @@ # # %make GOBUILDFLAGS="%gobuildflags" # -%gobuildflags() %{expand:%{gocompilerflags} -tags=\\"rpm_crashtraceback \\" -ldflags \\"${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'\\" -a -v -x} +%gobuildflags() %{expand:%{gocompilerflags} -tags=\\"rpm_crashtraceback ${BUILDTAGS:-} libtrust_openssl\\" -ldflags \\"-linkmode=external -compressdwarf=false ${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'\\" -a -v -x} +%_gobuildflags_internal() %{expand:%{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-} libtrust_openssl" -ldflags "-linkmode=external -compressdwarf=false ${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x} # Turn off Go modules %gomodulesmode GO111MODULE=off # Define commands for building # BUILD_ID can be generated for golang build no matter of debuginfo + +%_gobuild_cmd CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-all" go build %{_gobuildflags_internal} +%gobuild_compat_el8(o:) %{expand:%{_gobuild_cmd} %{?**};} %gobuild(o:) %{expand: # https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12 %global _dwz_low_mem_die_limit 0 %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} %{?gomodulesmode} \\ - go build %{?gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; + %{_gobuild_cmd} %{?**}; } ${workroot}${GOPATH:+:${GOPATH}} # Define commands for testing %gotestflags %{gocompilerflags} %gotestextldflags %__global_ldflags %{?__golang_extldflags} -%gotest() %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-}%{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; + +%_gotest_cmd %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-}%{?currentgoldflags} -extldflags '%{gotestextldflags}'" +%gotest_compat_el8(o:) %{expand:%{_gotest_cmd} %{?**};} +%gotest(o:) %{expand: + %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} %{?gomodulesmode} \\ + %{_gotest_cmd} %{?**}; +} + diff --git a/rpm/macros.d/macros.go-rpm b/rpm/macros.d/macros.go-rpm index f773f34..b82581b 100644 --- a/rpm/macros.d/macros.go-rpm +++ b/rpm/macros.d/macros.go-rpm @@ -22,42 +22,6 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -# Default filtering policy -# Complete or replace the following variables in your spec file if this policy -# does not apply to your project -# -# Specific example matching rule. -# The average Go project example code is incomplete and obsolete. It will -# fail to compile as-is, or even panic. It will poison the dependency -# generator with bogus or legacy import path requirements. Even when it it -# clean and up to date, it will require many third party components not needed -# in production. Therefore: -# – never install Go project example code in %{gopath}. Publish is as %doc. -# — ask politely projects that publish example code in some other directory -# than _examples to rename it. -# – never rely on third party examples being available or working in another -# project. This is *not* production code. Ask upstreams politely to remove -# tests or code that import other project examples. -%goignoreflags_examples -r '.*example.*' - -# Default flags to apply in all stages -%godefaultflags %{goignoreflags_examples} - -# Default flags to apply in Go install (%goinstall) -%goinstallflags %{godefaultflags} - -# Default flags to apply in Go checks (%gochecks) -%gocheckflags %{godefaultflags} - -# Default flags to apply in Go autoprovides -%goprovflags %{godefaultflags} - -# Default flags to apply in Go autorequires -%goreqflags %{godefaultflags} - -# The default filelist name generated by %goinstall -%gofilelist devel.file-list - # Sets environment variables suitable for a Go source archive. Optional arguments: # -z read the zth block of definitions, for example # %{goipath}, %{commit}… @@ -116,6 +80,7 @@ fi cd "%{mybuilddir}/src/%{mygoipath}" } + # Perform usual Go source preparation steps. Optional arguments: # -z read the zth block of definitions, for example # %{goipath}, %{commit}… @@ -160,207 +125,3 @@ else process(rpm.expand("%{?-z*}")) end } - -# 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} -%go_generate_buildrequires(z:ai:) %{lua: -local fedora = require "fedora.common" -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local forcedgoipath = rpm.expand("%{?-i}") -local golistargs = "" -if processall then - for _, s in pairs(fedora.getsuffixes("goipath")) do - golistargs = golistargs .. " --package-path %{goipath" .. s .. "}" - end - golistargs = string.gsub(golistargs, "^ ", "") -elseif forcedgoipath ~= "" then - golistargs = "--package-path " .. forcedgoipath -else - golistargs = "--package-path %{goipath" .. rpm.expand("%{?-z*}") .. "}" -end -print(rpm.expand('GOPATH="%{?gobuilddir:%{gobuilddir}:}${GOPATH:+${GOPATH}:}%{?gopath}" ' .. - 'GO111MODULE=off ' .. - "golist --imported " .. golistargs .. - " --template 'golang({{.}})\\\\n'" .. - " --with-tests --skip-self\\n")) -} - -# Try to install Go package files in sensible locations, with strict directory -# ownership and lockfile creation as required by Go autodeps. -# -# Simple arguments, that can not be repeated: -# -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 -# default: %{goipath} -# -b read binaries already produced in -# default: %{gobuilddir}/bin -# -s read expanded and prepared Go sources in /src -# should be populated in %prep -# default: %{gobuilddir} -# -o output installed file list in -# default: %{gofilelist} -# -O output in -# -l add those flags to LDFLAGS when building unit tests -# -v be verbose -# -# Inclusion arguments, that can be repeated: -# -e include files with the provided extension -# -# Exclusion arguments, that can be repeated, relative to the go import path root: -# -d exclude the files contained in -# not recursive (subdirectories are not excluded) -# -t exclude the files contained in -# recursive (subdirectories are excluded) -# -r exclude files matching , -# -# Optional versionning metadata, that can not be repeated: -# -V Should only be specified when creating subpackages with -# distinct versions -# default: %{version}.%{release} -# -T default: %{tag} -# -C default: %{commit} -# -B default: %{branch} -# -# When invoked several times with the same import path goinstall will append to -# the existing file list if versionning and exclusion arguments are identical to -# previous calls, and error out otherwise. -# When invoked several times with different file list names, it will attribute -# directories to the first file list that makes use of them. -%goinstall(z:ai:b:s:o:O:ve:d:t:rV:T:C:B:p:g:) %{lua: -local fedora = require "fedora.common" -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local myenvflags = rpm.expand('%{?-i} %{?-v} %{?-V} %{?-T} %{?-C} %{?-B}') -local myinstallflags = rpm.expand('%{!-i:-i "%%{currentgoipath}" }' .. - '%{!-b:-b "%%{gobuilddir}/bin" }' .. - '%{!-s:-s "%%{gobuilddir}" }' .. - '%{!-o:-o "%%{thisgofilelist}" }' .. - '%{!-O:-O "%%{goworkdir}" }' .. - '%{!-V:-V "%{version}-%{release}" }' .. - '%{!-T:%%{?currenttag: -T "%%{?currenttag}" }}' .. - '%{!-C:%%{?currentcommit: -C "%%{?currentcommit}" }}' .. - '%{!-B:%%{?currentbranch: -B "%%{?currentbranch}" }}' .. - '%{!-p:-p "%{buildroot}" }' .. - '%{!-g:-g "%{gopath}" }' .. - '%{?goinstallflags} %{?**}') --- Main function -local function process(suffix) - local zsuffix = "" - if (suffix ~= "") and (suffix ~= nil) then - zsuffix = "-z " .. suffix .. " " - end - print(rpm.expand('%goenv ' .. zsuffix .. myenvflags .. '\\n' .. - 'go-rpm-integration install ' .. myinstallflags .. '\\n')) -end --- Main loop -if processall then - for _,s in pairs(fedora.getsuffixes("goipath")) do - process(s) - end -else - process(rpm.expand("%{-z*}")) -end -} - -# Perform the %install tasks of every known kind of Go subpackage. Arguments: -# -v be verbose -%gopkginstall(av) %{expand: -%godevelinstall -a %{-v} -%goaltinstall -a %{-v} -} - -# Perform the %install tasks of a golang-*-devel subpackage. Arguments: -# -z read the zth block of definitions, for example -# %{goipaths} -# -a process all blocks in one go, instead of using separate -# -z calls -# -v be verbose -%godevelinstall(z:av) %{lua: -local go = require "fedora.rpm.go" -local suffix = rpm.expand("%{-z*}") -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local verbose = (rpm.expand("%{-v}") ~= "") -go.install("devel", suffix, processall, verbose) -} - -# Perform the %install tasks of a compat-golang-*-devel subpackage. Arguments: -# -z read the zth block of definitions, for example -# %{goaltipaths} -# -a process all blocks in one go, instead of using separate -# -z calls -# -v be verbose -%goaltinstall(z:av) %{lua: -local go = require "fedora.rpm.go" -local suffix = rpm.expand("%{-z*}") -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local verbose = (rpm.expand("%{-v}") ~= "") -go.install("alt", suffix, processall, verbose) -} - -# Run go test with Fedora flags on all subdirectories except for those filtered out -# THIS MACRO IS OPT-OUT. -# -# Simple arguments, that can not be repeated: -# -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 -# default: %{goipath} -# -b read binaries already produced in -# default: %{gobuilddir}/bin -# -s read expanded and prepared Go sources in /src -# should be populated in %prep -# default: %{gobuilddir} -# -v be verbose -# Exclusion arguments, that can be repeated, relative to the go import path root: -# -d exclude the files contained in -# not recursive (subdirectories are not excluded) -# -t exclude the files contained in -# recursive (subdirectories are excluded) -# -r exclude files matching , -%gocheck(z:ai:b:s:vd:t:rV:T:C:B:p:g:w) %{lua: -local fedora = require "fedora.common" -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local myenvflags = rpm.expand('%{?-i} %{?-v} %{?-V} %{?-T} %{?-C} %{?-B}') -local mycheckflags = rpm.expand('%{!-i:-i "%%{currentgoipath}" }' .. - '%{!-b:-b "%%{gobuilddir}/bin" }' .. - '%{!-s:-s "%%{gobuilddir}" }' .. - '%{!-V:-V "%{version}-%{release}" }' .. - '%{!-T:%%{?currenttag: -T "%%{?currenttag}" }}' .. - '%{!-C:%%{?currentcommit: -C "%%{?currentcommit}" }}' .. - '%{!-B:%%{?currentbranch: -B "%%{?currentbranch}" }}' .. - '%{!-p:-p "%{buildroot}" }' .. - '%{!-g:-g "%{gopath}" }' .. - '%{?gocheckflags} %{?**}') --- Main function -local function process(suffix) - local zsuffix = "" - if (suffix ~= "") and (suffix ~= nil) then - zsuffix = "-z " .. suffix .. " " - end - print(rpm.expand('%goenv ' .. zsuffix .. myenvflags .. '\\n' .. - '%{?currentgoldflags:LDFLAGS="${LDFLAGS} %{?currentgoldflags}" }' .. - '%{?gotestflags:GO_TEST_FLAGS="%{gotestflags}" }' .. - '%{?gotestextldflags:GO_TEST_EXT_LD_FLAGS="%{gotestextldflags}" }' .. - 'go-rpm-integration check ' .. mycheckflags .. '\\n')) -end --- Main loop -if processall then - for _,s in pairs(fedora.getsuffixes("goipath")) do - process(s) - end -else - process(rpm.expand("%{-z*}")) -end -} diff --git a/rpm/macros.d/macros.go-srpm b/rpm/macros.d/macros.go-srpm index 884463f..60b62ac 100644 --- a/rpm/macros.d/macros.go-srpm +++ b/rpm/macros.d/macros.go-srpm @@ -122,72 +122,3 @@ else end } -# Create %package sections for every known kind of go subpackage. Arguments: -# -v be verbose -%gopkg(av) %{expand: -%godevelpkg -a %{-v} -%goaltpkg -a %{-v} -} - -# Create a %package section for a golang-*-devel subpackage. Arguments: -# -z read the zth block of definitions, for example -# %{goipaths} -# -a process all blocks in one go, instead of using separate -# -z calls -# -v be verbose -%godevelpkg(z:av) %{lua: -local go = require "fedora.srpm.go" -local suffix = rpm.expand("%{-z*}") -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local verbose = (rpm.expand("%{-v}") ~= "") -go.pkg("devel", suffix, processall, verbose) -} - -# Create a %package section for a compat-golang-*-devel subpackage. Arguments: -# -z read the zth block of definitions, for example -# %{goaltipaths} -# -a process all blocks in one go, instead of using separate -# -z calls -# -v be verbose -%goaltpkg(z:av) %{lua: -local go = require "fedora.srpm.go" -local suffix = rpm.expand("%{-z*}") -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local verbose = (rpm.expand("%{-v}") ~= "") -go.pkg("alt", suffix, processall, verbose) -} - -# Create %files sections for every known kind of Go subpackage. Arguments: -# -v be verbose -%gopkgfiles(av) %{expand: -%godevelfiles -a %{-v} -%goaltfiles -a %{-v} -} - -# Create a %files section for a golang-*-devel subpackage. Arguments: -# -z read the zth block of definitions, for example -# %{goipaths} -# -a process all blocks in one go, instead of using separate -# -z calls -# -v be verbose -%godevelfiles(z:av) %{lua: -local go = require "fedora.srpm.go" -local suffix = rpm.expand("%{-z*}") -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local verbose = (rpm.expand("%{-v}") ~= "") -go.files("devel", suffix, processall, verbose) -} - -# Create a %files section for a compat-golang-*-devel subpackage. Arguments: -# -z read the zth block of definitions, for example -# %{goaltipaths} -# -a process all blocks in one go, instead of using separate -# -z calls -# -v be verbose -%goaltfiles(z:av) %{lua: -local go = require "fedora.srpm.go" -local suffix = rpm.expand("%{-z*}") -local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") -local verbose = (rpm.expand("%{-v}") ~= "") -go.files("alt", suffix, processall, verbose) -}