From d4ee438cd72148ca29943024bcbc5c756df65d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Schr=C3=B6der?= Date: Tue, 18 Apr 2017 15:03:51 -0700 Subject: [PATCH] Faster dev builds (#2924) This patch runs 'go install' instead of gox which runs 'go build' for 'make dev' and copies the binary into ./bin and ./pkg/${GOOS}_${GOARCH} to mimick the previous behavior. This reduces the roundtrip times for a dev build from 11 sec to 500ms if there weren't any changes. --- GNUmakefile | 18 ++++++++++++++++-- scripts/build.sh | 8 +------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 9e3b646a5..55faa4a6e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -7,6 +7,17 @@ GOTOOLS = \ TEST ?= ./... GOTAGS ?= consul GOFILES ?= $(shell go list $(TEST) | grep -v /vendor/) +GOOS=$(shell go env GOOS) +GOARCH=$(shell go env GOARCH) + +# Get the git commit +GIT_COMMIT=$(shell git rev-parse --short HEAD) +GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) +GIT_DESCRIBE=$(shell git describe --tags --always) +GIT_IMPORT=github.com/hashicorp/consul/version +GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).GitDescribe=$(GIT_DESCRIBE) + +export GOLDFLAGS # all builds binaries for all targets all: bin @@ -16,8 +27,11 @@ bin: tools @GOTAGS='$(GOTAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" # dev creates binaries for testing locally - these are put into ./bin and $GOPATH -dev: format - @CONSUL_DEV=1 GOTAGS='$(GOTAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" +dev: + mkdir -p pkg/$(GOOS)_$(GOARCH) + go install -ldflags '$(GOLDFLAGS)' -tags '$(GOTAGS)' + cp $(GOPATH)/bin/consul bin + cp $(GOPATH)/bin/consul pkg/$(GOOS)_$(GOARCH) # dist builds binaries for all platforms and packages them for distribution dist: diff --git a/scripts/build.sh b/scripts/build.sh index 2011bd598..566dbc6cc 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -13,12 +13,6 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" # Change into that directory cd "$DIR" -# Get the git commit -GIT_COMMIT="$(git rev-parse --short HEAD)" -GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)" -GIT_DESCRIBE="$(git describe --tags --always)" -GIT_IMPORT="github.com/hashicorp/consul/version" - # Determine the arch/os combos we're building for XC_ARCH=${XC_ARCH:-"386 amd64 arm"} XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"} @@ -41,7 +35,7 @@ echo "==> Building..." -os="${XC_OS}" \ -arch="${XC_ARCH}" \ -osarch="!darwin/arm" \ - -ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X ${GIT_IMPORT}.GitDescribe='${GIT_DESCRIBE}'" \ + -ldflags "${GOLDFLAGS}" \ -output "pkg/{{.OS}}_{{.Arch}}/consul" \ -tags="${GOTAGS}" \ .