From baaf3c21562886fa1f2df91c2e4259eb8e839699 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Feb 26 2024 00:48:07 +0000 Subject: [PATCH 1/3] rpmeval.sh: remove extra newline in output --- diff --git a/rpmeval.sh b/rpmeval.sh index c09a5e5..72eead4 100755 --- a/rpmeval.sh +++ b/rpmeval.sh @@ -27,6 +27,8 @@ if [ -n "${MACRO_LUA_DIR}" ]; then _default_lua_dir="$(rpm -E '%{lua: print(package.path)}')" _path="$(printf "'%s'" "${MACRO_LUA_DIR}/?.lua;${_default_lua_dir}")" args+=("-E" "%{lua: package.path = ${_path} }") + # Delete the first empty line that's created by the lua expansion. + "${args[@]}" "$@" | sed 1d +else + "${args[@]}" "$@" fi - -exec "${args[@]}" "$@" From 0620a911751807b3f36e98d208e7fc01fc77597e Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Feb 26 2024 00:48:10 +0000 Subject: [PATCH 2/3] Add additional gobuildflags macros This makes it easier to pass Fedora's Go build flags to upstream build scripts. Fixes: https://pagure.io/go-rpm-macros/issue/46 --- diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index 74428a3..56e4a5c 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -20,16 +20,49 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -# This *must* be all on one line, as it will be used in shell -# assignments. eg -# -# GOBUILDFLAGS="%gobuildflags" %configure -# -# Or -# -# %make GOBUILDFLAGS="%gobuildflags" -# -%gobuildflags() %{expand:%{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -linkmode=external -extldflags '%{build_ldflags} %{?__golang_extldflags}'" -a -v -x} +# All flags to pass "go build" other than -ldflags +%gobuild_baseflags %{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -a -v -x +# A shell-escaped version of %gobuild_baseflags. +# Can be used to set an environment or make variable. +# Example from the aerc package: +# %make_build BUILD_OPTS=%{gobuild_baseflags_shescaped} aerc +# NOTE: This cannot be passed to the GOFLAGS environment variable due to +# . +# Upstream build scripts must expose a separate variable to pass arguments +# directly to the "go build" invocation. +%gobuild_baseflags_shescaped "$(cat <. +# Upstream build scripts must expose a separate variable for that. +# For projects that don't provide a separate flag to set -ldflags, use +# %gobuildflags_shescapes which combines %gobuild_baseflags_shescaped and +# %gobuild_ldflags_shescaped. +%gobuild_ldflags_shescaped "$(cat < Date: Feb 29 2024 20:29:16 +0000 Subject: [PATCH 3/3] Add support for GO_BUILDTAGS and GO_LDFLAGS macros Currently, we disable automatic %set_build_flags when any Go macro is used, as $LDFLAGS that it sets includes options that are not supported by the Go linker. For now, we'll support the non-GO-prefixed environment variable names as aliases, but they will eventually be removed entirely. --- diff --git a/bin/go-rpm-integration b/bin/go-rpm-integration index e30de0b..f6aed73 100755 --- a/bin/go-rpm-integration +++ b/bin/go-rpm-integration @@ -392,7 +392,7 @@ GOPATH="${workroot}${GOPATH+:${GOPATH}}" GO111MODULE=off \ GOPATH="${workroot}${GOPATH:+:${GOPATH}}:${gopath}" \ PATH="${workbin:+${workbin}:}${PATH}" \ GO111MODULE=off \ - go test ${GO_TEST_FLAGS} -ldflags "${LDFLAGS:+${LDFLAGS} }-extldflags '${GO_TEST_EXT_LD_FLAGS}'" + go test ${GO_TEST_FLAGS} -ldflags "${GO_LDFLAGS:+${GO_LDFLAGS} }-extldflags '${GO_TEST_EXT_LD_FLAGS}'" popd >/dev/null done } @@ -452,7 +452,7 @@ case $action in echo " PATH: ${workbin:+${workbin}:}${PATH}" echo " GOPATH: ${workroot}${GOPATH:+:${GOPATH}}:${gopath}" echo " GO111MODULE: off" - echo " command: go test ${GO_TEST_FLAGS} -ldflags \"${LDFLAGS:+${LDFLAGS} }-extldflags '${GO_TEST_EXT_LD_FLAGS}'\"" + echo " command: go test ${GO_TEST_FLAGS} -ldflags \"${GO_LDFLAGS:+${GO_LDFLAGS} }-extldflags '${GO_TEST_EXT_LD_FLAGS}'\"" echo " testing: ${goipath}" checks "${goipath}" ;; provides) while read lockfile ; do diff --git a/rpm/macros.d/macros.go-compilers-gcc b/rpm/macros.d/macros.go-compilers-gcc index 3d344d2..1b5aa76 100644 --- a/rpm/macros.d/macros.go-compilers-gcc +++ b/rpm/macros.d/macros.go-compilers-gcc @@ -26,9 +26,9 @@ # Define commands for building %gobuild(o:) %{expand: %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} \\ -go build -compiler gccgo -gccgoflags "$RPM_OPT_FLAGS ${LDFLAGS:-%{?currentgoldflags} %{build_ldflags}} %{?__golang_extldflags}" -a -v -x %{?**}; +go build -compiler gccgo -gccgoflags "$RPM_OPT_FLAGS ${GO_LDFLAGS-${LDFLAGS:-%{?currentgoldflags} %{build_ldflags}}} %{?__golang_extldflags}" -a -v -x %{?**}; } # Define commands for testing -%gotestflags -compiler gccgo -gccgoflags "$RPM_OPT_FLAGS ${LDFLAGS:-%{?currentgoldflags} %{build_ldflags}} %{?__golang_extldflags}" +%gotestflags -compiler gccgo -gccgoflags "$RPM_OPT_FLAGS ${GO_LDFLAGS-${LDFLAGS:-%{?currentgoldflags} %{build_ldflags}}} %{?__golang_extldflags}" %gotest() go test %{gotestflags} %{?**}; diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index 56e4a5c..bb783f9 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -21,7 +21,11 @@ # SPDX-License-Identifier: GPL-3.0-or-later # All flags to pass "go build" other than -ldflags -%gobuild_baseflags %{gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -a -v -x +# BACKWARDS COMPATIBILITY: +# $BUILDTAGS is supported as a deprecated alias to $GO_BUILDTAGS to add additional +# arguments to `go build -tags "..."`. +# Please set $GO_BUILDTAGS instead of $BUILDTAGS. +%gobuild_baseflags %{gocompilerflags} -tags="rpm_crashtraceback ${GO_BUILDTAGS-${BUILDTAGS-}}" -a -v -x # A shell-escaped version of %gobuild_baseflags. # Can be used to set an environment or make variable. # Example from the aerc package: @@ -36,7 +40,11 @@ EOF\ )" # Argument to pass to "go build"'s -ldflags option -%gobuild_ldflags ${LDFLAGS:-} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -linkmode=external -extldflags '%{build_ldflags} %{?__golang_extldflags}' +# BACKWARDS COMPATIBILITY: +# $LDFLAGS is supported as a deprecated alias to $GO_LDFLAGS to add additional +# arguments to `go build -ldflags "..."`. +# Please set $GO_LDFLAGS instead of $LDFLAGS. +%gobuild_ldflags ${GO_LDFLAGS-${LDFLAGS-}} %{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -compressdwarf=false -linkmode=external -extldflags '%{build_ldflags} %{?__golang_extldflags}' # A shell-escaped version of %gobuild_ldflags. # Can be used to set an environment or make variable. # Example from the aerc package: @@ -86,5 +94,5 @@ ${workroot}${GOPATH:+:${GOPATH}} %gotestextldflags %{build_ldflags} %{?__golang_extldflags} %gotest() %{expand: %undefine _auto_set_build_flags - %{?gomodulesmode} go test %{gotestflags} -ldflags "${LDFLAGS:-} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; + %{?gomodulesmode} go test %{gotestflags} -ldflags "${GO_LDFLAGS-${LDFLAGS-}} %{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; } diff --git a/rpm/macros.d/macros.go-rpm b/rpm/macros.d/macros.go-rpm index e4dfee4..5fc75b9 100644 --- a/rpm/macros.d/macros.go-rpm +++ b/rpm/macros.d/macros.go-rpm @@ -358,7 +358,7 @@ local function process(suffix) zsuffix = "-z " .. suffix .. " " end print(rpm.expand('%goenv ' .. zsuffix .. myenvflags .. '\\n' .. - '%{?currentgoldflags:LDFLAGS="${LDFLAGS} %{?currentgoldflags}" }' .. + '%{?currentgoldflags:GO_LDFLAGS="${LDFLAGS} %{?currentgoldflags}" }' .. '%{?gotestflags:GO_TEST_FLAGS="%{gotestflags}" }' .. '%{?gotestextldflags:GO_TEST_EXT_LD_FLAGS="%{gotestextldflags}" }' .. 'go-rpm-integration check ' .. mycheckflags .. '\\n'))