gp-compile: Use '-mod=vendor' when using go modules
fixes
@@ -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
