spec: build test binaries against installed libraries

On Fedora, the `%gobuild` macro turns off go modules and sets gopath to
installed libraries (in `/usr/share/gocode`).

When building the test binaries, we used `go test -c` directly, which
downloaded the libraries into GOPATH. That's wasteful and doesn't work
in mock (without internet). Replicate what `%gobuild` does by setting
`GO111MODULE=off` and `GOPATH` to the correct value.

RHEL uses modules as intended. No change is necessary.
This commit is contained in:
Lars Karlitski 2020-03-19 18:41:06 +01:00 committed by Ondřej Budai
parent 600a0f50a9
commit c5823d92b4
2 changed files with 14 additions and 0 deletions

View file

@ -82,6 +82,13 @@ export GOFLAGS=-mod=vendor
# Build test binaries with `go test -c`, so that they can take advantage of
# golang's testing package. The golang rpm macros don't support building them
# directly. Thus, do it manually, taking care to also include a build id.
#
# On Fedora, also turn off go modules and set the path to the one into which
# the golang-* packages install source code.
%if 0%{?fedora}
export GO111MODULE=off
export GOPATH=%{gobuilddir}:%{gopath}
%endif
TEST_LDFLAGS="${LDFLAGS:-} -B 0x$(od -N 20 -An -tx1 -w100 /dev/urandom | tr -d ' ')"