From 765e5f0b8899b7f2fa40a27670c8e82fab303a7e Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Sun, 14 Feb 2021 13:37:24 +0000 Subject: [PATCH] gp-compile: Use '-mod=vendor' when using go modules fixes https://github.com/linuxkit/linuxkit/issues/3599 Signed-off-by: Rolf Neugebauer --- tools/go-compile/compile.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/go-compile/compile.sh b/tools/go-compile/compile.sh index ca1e967bd..a86ffe141 100755 --- a/tools/go-compile/compile.sh +++ b/tools/go-compile/compile.sh @@ -73,12 +73,15 @@ fi cd "$dir" +# Use '-mod=vendor' for builds which have switched to go modules +[ -f go.mod ] && MOD_ARG="-mod=vendor" + # lint before building >&2 echo "gofmt..." test -z $(gofmt -s -l .| grep -v .pb. | grep -v vendor/ | tee /dev/stderr) >&2 echo "govet..." -test -z $(GOOS=linux go vet -printf=false . 2>&1 | grep -v "^#" | grep -v vendor/ | tee /dev/stderr) +test -z $(GOOS=linux go vet $MOD_ARG -printf=false . 2>&1 | grep -v "^#" | grep -v vendor/ | tee /dev/stderr) >&2 echo "golint..." test -z $(find . -type f -name "*.go" -not -path "*/vendor/*" -not -name "*.pb.*" -exec golint {} \; | tee /dev/stderr) @@ -92,12 +95,12 @@ if [ "$GOOS" = "darwin" -o "$GOOS" = "windows" ] then if [ -z "$ldflags" ] then - go build -o $out "$package" + go build $MOD_ARG -o $out "$package" else - go build -o $out -ldflags "${ldflags}" "$package" + go build $MOD_ARG -o $out -ldflags "${ldflags}" "$package" fi else - go build -o $out -buildmode pie -ldflags "-s -w ${ldflags} -extldflags \"-static\"" "$package" + go build $MOD_ARG -o $out -buildmode pie -ldflags "-s -w ${ldflags} -extldflags \"-static\"" "$package" fi tar cf - $out