Blob Blame History Raw
From 18776c3c93335fc4a8ef98631d65f7ebd44296ec Mon Sep 17 00:00:00 2001
From: Eli Schwartz <eschwartz@archlinux.org>
Date: Tue, 21 May 2019 12:49:38 -0400
Subject: [PATCH 4/5] 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 edb7065f34c15ad24b860e66628c83a0d899b9be..c422ef2490bbf85cc2b340330a0666fbff6373bd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
 SOURCES = $(shell script/build files)
 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)
 export ASMFLAGS := $(FLAGS_ALL)
 
 MIN_COVERAGE = 89.4
@@ -44,11 +45,11 @@ TEXT_WIDTH = 87
 
 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 ./...
 
 test-all: bin/cucumber
diff --git a/script/build b/script/build
index 55782a74502e30b015e4321524a9694810c5fede..9c85da95f4e17e28c2021024fa6e9102d9adc9b6 100755
--- a/script/build
+++ b/script/build
@@ -20,10 +20,11 @@ find_source_files() {
 }
 
 build_hub() {
   mkdir -p "$(dirname "$1")"
   go build \
+	  $MOD_VENDOR_ARG \
 	  $COMPILEPIE \
 	  -compiler gc \
 	  -ldflags "-B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -X github.com/github/hub/version.Version=`./script/version` $LDFLAGS" \
 	  -gcflags "$GCFLAGS" \
 	  -asmflags "$ASMFLAGS" \
-- 
2.21.0