Update Makefile to not repeat build when possible

This commit is contained in:
Tim Hockin 2019-01-28 10:53:16 -08:00
parent 497c7df123
commit 1c374dab1f
1 changed files with 28 additions and 14 deletions

View File

@ -87,24 +87,33 @@ all-push: $(addprefix push-, $(ALL_PLATFORMS))
build: bin/$(OS)_$(ARCH)/$(BIN) build: bin/$(OS)_$(ARCH)/$(BIN)
BUILD_DIRS := bin/$(OS)_$(ARCH) .go/src/$(PKG) .go/pkg .go/bin .go/std/$(OS)_$(ARCH) .go/cache BUILD_DIRS := \
bin/$(OS)_$(ARCH) \
.go/src/$(PKG) \
.go/pkg \
.go/bin/$(OS)_$(ARCH) \
.go/std/$(OS)_$(ARCH) \
.go/cache
# TODO: This is .PHONY because building Go code uses a compiler-internal DAG, # The following structure defeats Go's (intentional) behavior to always touch
# so we have to run the go tool. Unfortunately, go always touches the binary # result files, even if they have not changed. This will still run `go` but
# during `go install` even if it didn't change anything (as per md5sum). This # will not trigger further work if nothing has actually changed.
# makes make unhappy. Better would be to run go, see that the result did not OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
# change, and then bypass further processing. Sadly not possible for now. $(OUTBIN): .go/$(OUTBIN).stamp
.PHONY: bin/$(OS)_$(ARCH)/$(BIN) @true
bin/$(OS)_$(ARCH)/$(BIN): $(BUILD_DIRS)
@echo "building: $@" # This will build the binary under ./.go and update the real binary iff needed.
.PHONY: .go/$(OUTBIN).stamp
.go/$(OUTBIN).stamp: $(BUILD_DIRS)
@echo "making $(OUTBIN)"
@docker run \ @docker run \
-ti \ -ti \
--rm \ --rm \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \ -v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(OS)_$(ARCH):/go/bin \ -v $$(pwd)/.go:/go \
-v $$(pwd)/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \ -v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/std/$(OS)_$(ARCH):/usr/local/go/pkg/$(OS)_$(ARCH)_static \ -v $$(pwd)/.go/std/$(OS)_$(ARCH):/usr/local/go/pkg/$(OS)_$(ARCH)_static \
-v $$(pwd)/.go/cache:/.cache \ -v $$(pwd)/.go/cache:/.cache \
-w /go/src/$(PKG) \ -w /go/src/$(PKG) \
@ -118,6 +127,10 @@ bin/$(OS)_$(ARCH)/$(BIN): $(BUILD_DIRS)
PKG=$(PKG) \ PKG=$(PKG) \
./build/build.sh \ ./build/build.sh \
" "
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
cat .go/$(OUTBIN) > $(OUTBIN); \
date >$@; \
fi
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG) DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
@ -165,9 +178,10 @@ test: $(BUILD_DIRS)
@docker run \ @docker run \
-ti \ -ti \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \ -v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(OS)_$(ARCH):/go/bin \ -v $$(pwd)/.go:/go \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/std/$(OS)_$(ARCH):/usr/local/go/pkg/$(OS)_$(ARCH)_static \ -v $$(pwd)/.go/std/$(OS)_$(ARCH):/usr/local/go/pkg/$(OS)_$(ARCH)_static \
-v $$(pwd)/.go/cache:/.cache \ -v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \ --env HTTP_PROXY=$(HTTP_PROXY) \