From 32e1652c9ca826d602e783ec96cba192705a8085 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Thu, 1 Aug 2019 13:20:14 +0200 Subject: [PATCH] go build: use `-mod=vendor` for go >= 1.11.x Go 1.13.x isn't sensitive to the `GO111MODULE` environment variable causing `make binary-local` to not use the vendored sources in `./vendor`. Force builds of module-supporting go versions to use the vendored sources by setting `-mod=vendor`. Verified in a `fedora:rawhide` container. Signed-off-by: Valentin Rothberg --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 64450cba..568956ea 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,5 @@ .PHONY: all binary build-container docs docs-in-container build-local clean install install-binary install-completions shell test-integration .install.vndr vendor -export GO111MODULE=off - ifeq ($(shell uname),Darwin) PREFIX ?= ${DESTDIR}/usr/local DARWIN_BUILD_TAG=containers_image_ostree_stub @@ -26,6 +24,12 @@ GO ?= go CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker) GOMD2MAN ?= $(shell command -v go-md2man || echo '$(GOBIN)/go-md2man') +GO_BUILD=$(GO) build +# Go module support: set `-mod=vendor` to use the vendored sources +ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true) + GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor +endif + ifeq ($(DEBUG), 1) override GOGCFLAGS += -N -l endif @@ -95,10 +99,10 @@ binary-static: cmd/skopeo # Build w/o using containers binary-local: - $(GPGME_ENV) $(GO) build ${GO_DYN_FLAGS} -ldflags "-X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo + $(GPGME_ENV) $(GO_BUILD) ${GO_DYN_FLAGS} -ldflags "-X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo binary-local-static: - $(GPGME_ENV) $(GO) build -ldflags "-extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo + $(GPGME_ENV) $(GO_BUILD) -ldflags "-extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo build-container: ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -t "$(IMAGE)" .