commit 1ca832dde0bfb3d217d1d2b4fea6c55df9c395a9 Author: CentOS Sources Date: Tue May 18 02:58:38 2021 -0400 import go-srpm-macros-2-17.el8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.go-srpm-macros.metadata b/.go-srpm-macros.metadata new file mode 100644 index 0000000..e69de29 diff --git a/SOURCES/macros.go-srpm b/SOURCES/macros.go-srpm new file mode 100644 index 0000000..ddca14a --- /dev/null +++ b/SOURCES/macros.go-srpm @@ -0,0 +1,175 @@ +# Copyright (c) 2015-2021 Jakub Cajka , +# Jan Chaloupka , +# Nicolas Mailhot +# Alejandro Saez Morollon +# This file is distributed under the terms of GNU GPL license version 3, or +# any later version. + +# This file contains macros for building projects in golang for packages +# with golang compiler or gcc-go compiler based on an architecture. +# Golang is primarly for primary architectures, gcc-go for secondary. +# +# This file provides only macros and must not use any other package except +# redhat-rpm-macros. + +# Define arches for PA and SA +%golang_arches x86_64 %{arm} aarch64 ppc64le s390x +%gccgo_arches %{mips} +%go_arches %{golang_arches} %{gccgo_arches} + +# Where to set GOPATH for builds +%gopath %{_datadir}/gocode + +# Define go_compilers macro to signal go-compiler package is available +%go_compiler 1 + +# Sanitize a Go import path that can then serve as rpm package name +# Mandatory parameter: a Go import path +%gorpmname() %{lua: +local goname = rpm.expand("%1") +-- lowercase and end with '/' +goname = string.lower(goname .. "/") +-- remove eventual protocol prefix +goname = string.gsub(goname, "^http(s?)://", "") +-- add golang prefix +goname = "golang-" .. goname +-- remove FQDN root (.com, .org, etc) +goname = string.gsub(goname, "^([^/]+)%.([^%./]+)/", "%1/") +-- special-case x.y.z number-strings as that’s an exception in our naming +-- guidelines +repeat + goname, i = string.gsub(goname, "(%d)%.(%d)", "%1:%2") +until i == 0 +-- replace various separators rpm does not like with - +goname = string.gsub(goname, "[%._/%-]+", "-") +-- because of the Azure sdk +goname = string.gsub(goname, "%-for%-go%-", "-") +-- Tokenize along - separators and remove duplicates to avoid +-- golang-foo-foo-bar-foo names +local result = "" +local tokens = {} +tokens["go"] = true +tokens["git"] = true +for token in string.gmatch(goname, "[^%-]+") do + if not tokens[token] then + result = result .. "-" .. token + tokens[token] = true + end +end +-- reassemble the string, restore x.y.z runs, convert the vx.y.z +-- Go convention to x.y.z as prefered in rpm naming +result = string.gsub(result, "^-", "") +result = string.gsub(result, ":", ".") +-- some projects have a name that end up in a number, and *also* add release +-- numbers on top of it, keep a - prefix before version strings +result = string.gsub(result, "%-v([%.%d])", "-%1") +print(result) +} + +# Map Go information to rpm metadata. This macro will compute default spec +# variable values. +# +# The following spec variable MUST be set before calling the macro: +# +# goipath the packaged Go project import path +# +# The following spec variables SHOULD be set before calling the macro: +# +# forgeurl the project url on the forge, strongly recommended, if it can not +# be deduced from goipath; alternatively, use -u +# Version if applicable, set it with Version: +# tag if applicable +# commit if applicable +# +# The macro will attempt to compute and set the following variables if they are +# not already set by the packager: +# +# goname an rpm-compatible package name derived from goipath +# gosource an URL that can be used as SourceX: value +# gourl an URL that can be used as URL: value +# +# It will delegate processing to the forgemeta macro for: +# +# forgesource an URL that can be used as SourceX: value +# forgesetupargs the correct arguments to pass to %setup for this source +# used by %forgesetup and %forgeautosetup +# archivename the source archive filename, without extentions +# archiveext the source archive filename extensions, without leading dot +# archiveurl the url that can be used to download the source archive, +# without renaming +# scm the scm type, when packaging code snapshots: commits or tags +# +# If the macro is unable to parse your forgeurl value set at least archivename +# and archiveurl before calling it. +# +# Most of the computed variables are both overridable and optional. However, +# the macro WILL REDEFINE %{dist} when packaging a snapshot (commit or tag). +# The previous %{dist} value will be lost. Don’t call the macro if you don’t +# wish %{dist} to be changed. +# +# Optional parameters: +# -u Ignore forgeurl even if it exists and use instead. Note +# that the macro will still end up setting as the forgeurl +# spec variable if it manages to parse it. +# -s Silently ignore problems in forgeurl, use it if it can be parsed, +# ignore it otherwise. +# -p Restore problem handling, override -s. +# -v Be verbose and print every spec variable the macro sets. +# -i Print some info about the state of spec variables the macro may use or +# set at the end of the processing. +%gometa(u:spvi) %{expand:%{lua: +local forgeurl = rpm.expand("%{?-u*}") +if (forgeurl == "") then + forgeurl = rpm.expand("%{?forgeurl}") +end +-- Be explicit about the spec variables we’re setting +local function explicitset(rpmvariable,value) + rpm.define(rpmvariable .. " " .. value) + if (rpm.expand("%{?-v}") ~= "") then + rpm.expand("%{echo:Setting %%{" .. rpmvariable .. "} = " .. value .. "\\n}") + end +end +-- Never ever stomp on a spec variable the packager already set +local function safeset(rpmvariable,value) + if (rpm.expand("%{?" .. rpmvariable .. "}") == "") then + explicitset(rpmvariable,value) + end +end +-- All the Go packaging automation relies on goipath being set +local goipath = rpm.expand("%{?goipath}") +if (goipath == "") then + rpm.expand("%{error:Please set the Go import path in the “goipath” variable before calling “gometa”!}") +end +-- Compute and set spec variables +if (forgeurl ~= "") then + rpm.expand("%forgemeta %{?-v} %{?-i} %{?-s} %{?-p} -u " .. forgeurl .. "\\n") + safeset("gourl", forgeurl) +else + safeset("gourl", "https://" .. goipath) + rpm.expand("%forgemeta %{?-v} %{?-i} -s %{?-p} -u %{gourl}\\n") +end +if (rpm.expand("%{?forgesource}") ~= "") then + safeset("gosource", "%{forgesource}") +else + safeset("gosource", "%{gourl}/%{archivename}.%{archiveext}") +end +safeset("goname", "%gorpmname %{goipath}") +-- Final spec variable summary if the macro was called with -i +if (rpm.expand("%{?-i}") ~= "") then + rpm.expand("%{echo:Go-specific packaging variables}") + rpm.expand("%{echo: goipath: %{?goipath}}") + rpm.expand("%{echo: goname: %{?goname}}") + rpm.expand("%{echo: gourl: %{?gourl}}") + rpm.expand("%{echo: gosource: %{?gosource}}") +end} +BuildRequires: compiler(go-compiler) +ExclusiveArch: %{go_arches} +} + +# Define commands for building +# BUILD_ID can be generated for golang build no matter of debuginfo +%gobuild(o:) \ +CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-all" go build -compiler gc -buildmode pie '-tags=rpm_crashtraceback libtrust_openssl ' -ldflags "-linkmode=external -compressdwarf=false ${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags'" -a -v -x %{?**};\ + +# Define commands for testing +%gotest() go test -compiler gc -ldflags "${LDFLAGS:-}" %{?**}; diff --git a/SPECS/go-srpm-macros.spec b/SPECS/go-srpm-macros.spec new file mode 100644 index 0000000..373482f --- /dev/null +++ b/SPECS/go-srpm-macros.spec @@ -0,0 +1,89 @@ +Name: go-srpm-macros +Version: 2 +Release: 17%{?dist} +Summary: RPM macros for building Golang packages for various architectures +Group: Development/Libraries +License: GPLv3+ +Source0: macros.go-srpm +BuildArch: noarch +# for install command +BuildRequires: coreutils + +%description +The package provides macros for building projects in Go +on various architectures. + +%prep +# nothing to prep + +%build +# nothing to build, just for hooks + +%install +install -m 644 -D %{SOURCE0} %{buildroot}%{_rpmconfigdir}/macros.d/macros.go-srpm + +%files +%{_rpmconfigdir}/macros.d/macros.go-srpm + +%changelog +* Fri Jan 15 11:32:45 CET 2021 Alejandro Sáez - 2-17 +- Add and update the go-compiler functionality (gobuild macro) +- Deprecate ix86 +- Update Source0 +- Resolves: rhbz#1905383 + +* Mon Mar 05 2018 Jan Chaloupka - 2-16 +- Switch to upstream tarball (2nd attempt) + +* Sun Mar 04 2018 Jan Chaloupka - 2-15 +- Build the rawhide gometa completely on rawhide forgemeta + +* Tue Feb 27 2018 Robert-André Mauchin - 2-14 +- Fix the Github download path + +* Fri Feb 23 2018 Jan Chaloupka - 2-13 +- Update only the macros.go-srpm file, the upstream tarball can not be found + +* Fri Feb 23 2018 Jan Chaloupka - 2-12 +- Install go-srpm macros from an upstream tarball + +* Wed Feb 07 2018 Fedora Release Engineering - 2-11 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild + +* Wed Jul 26 2017 Fedora Release Engineering - 2-10 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild + +* Wed Jul 12 2017 Jakub Čajka - 2-9 +- Drop ppc64 from go arches +- https://fedoraproject.org/wiki/Changes/golang1.9 + +* Fri Feb 10 2017 Fedora Release Engineering - 2-8 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild + +* Wed Jul 20 2016 Jakub Čajka - 2-7 +- move s390x to golang +- Related: bz1357394 + +* Wed Feb 03 2016 Fedora Release Engineering - 2-6 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild + +* Thu Jan 28 2016 Jakub Čajka - 2-5 +- move {power64} to golang + +* Wed Dec 30 2015 Michal Toman - 2-4 +- MIPS has gcc-go, mips macro since rpm-4.12.0.1-18 + resolves: #1294875 + +* Thu Sep 10 2015 jchaloup - 2-3 +- Remove compiler specific macros (moved to go-compiler package) +- Define go-compiler macro to signal go-compiler packages is available + +* Sat Aug 29 2015 jchaloup - 2-2 +- Add -ldflags $LDFLAGS to go build/test macro + +* Sun Aug 23 2015 Peter Robinson 2-1 +- aarch64 now has golang + +* Tue Jul 07 2015 jchaloup - 1-1 +- Initial commit + resolves: #1241156