From 7d915e232caed4f89b95f9c93c94c98b3f38a9c9 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 21 May 2019 12:49:38 -0400 Subject: [PATCH] build: pass mod vendoring flag on newer versions of go When go autodetects that it is being run as a go mod, and that there is a vendor directory, it will still try to redownload all sources over the network, unless you use -mod=vendor to tell it to use that. Additionally, when using -mod=vendor the compiler will nicely avoid messing with $GOPATH at all, since it can operate in a completely self-contained manner. Take advantage of this, when the detected go version is at least 1.11 (when the -mod flag was introduced). --- Makefile | 3 ++- script/build | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 126a28667..b8e05bfb2 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SOURCE_DATE_EPOCH ?= $(shell date +%s) BUILD_DATE = $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" '+%d %b %Y' 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" '+%d %b %Y') HUB_VERSION = $(shell bin/hub version | tail -1) FLAGS_ALL = $(shell go version | grep -q 'go1.[89]' || echo 'all=') +export MOD_VENDOR_ARG := $(shell go version | grep -q 'go1.1[^0]' && echo '-mod=vendor') export LDFLAGS := -extldflags '$(LDFLAGS)' export GCFLAGS := $(FLAGS_ALL)-trimpath '$(PWD)' export ASMFLAGS := $(FLAGS_ALL)-trimpath '$(PWD)' @@ -46,7 +47,7 @@ bin/hub: $(SOURCES) script/build -o $@ bin/md2roff: $(SOURCES) - go build -o $@ github.com/github/hub/md2roff-bin + go build $(MOD_VENDOR_ARG) -o $@ github.com/github/hub/md2roff-bin test: go test ./... diff --git a/script/build b/script/build index 09d1a7cbe..a0447b647 100755 --- a/script/build +++ b/script/build @@ -14,6 +14,7 @@ find_source_files() { build_hub() { mkdir -p "$(dirname "$1")" go build \ + $MOD_VENDOR_ARG \ -ldflags "-X github.com/github/hub/version.Version=`./script/version` $LDFLAGS" \ -gcflags "$GCFLAGS" \ -asmflags "$ASMFLAGS" \