From d7ac6e516aafce1aac84215dea78d51035b8e2a8 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sat, 23 Dec 2017 02:23:05 -0800 Subject: [PATCH] Cleaned up makefile --- Makefile | 101 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 57cb844ab..2aed1acf4 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,21 @@ GOTOOLS = \ - github.com/mitchellh/gox \ - github.com/tcnksm/ghr \ - gopkg.in/alecthomas/gometalinter.v2 - + github.com/mitchellh/gox \ + github.com/Masterminds/glide \ + github.com/tcnksm/ghr \ + gopkg.in/alecthomas/gometalinter.v2 +GOTOOLS_CHECK = gox glide ghr gometalinter.v2 PACKAGES=$(shell go list ./... | grep -v '/vendor/') BUILD_TAGS?=tendermint TMHOME = $${TMHOME:-$$HOME/.tendermint} - BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short HEAD`" -all: get_vendor_deps install test +all: check build test install metalinter -install: - go install $(BUILD_FLAGS) ./cmd/tendermint +check: check_tools get_vendor_deps + + +######################################## +### Build build: go build $(BUILD_FLAGS) -o build/tendermint ./cmd/tendermint/ @@ -24,9 +27,42 @@ build_race: dist: @BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'" +install: + go install $(BUILD_FLAGS) ./cmd/tendermint + + +######################################## +### Tools & dependencies + +check_tools: + @# https://stackoverflow.com/a/25668869 + @echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\ + $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))" + +get_tools: + @echo "--> Installing tools" + go get -u -v $(GOTOOLS) + @gometalinter.v2 --install + +update_tools: + @echo "--> Updating tools" + @go get -u $(GOTOOLS) + +get_vendor_deps: + @rm -rf vendor/ + @echo "--> Running glide install" + @glide install + +draw_deps: + @# requires brew install graphviz or apt-get install graphviz + go get github.com/RobotsAndPencils/goviz + @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png + + +######################################## +### Testing + test: - @echo "--> Running linter" - @make metalinter_test @echo "--> Running go test" @go test $(PACKAGES) @@ -49,46 +85,21 @@ vagrant_test: vagrant ssh -c 'make test_race' vagrant ssh -c 'make test_integrations' -draw_deps: - # requires brew install graphviz or apt-get install graphviz - go get github.com/RobotsAndPencils/goviz - @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png - -get_vendor_deps: - @hash glide 2>/dev/null || go get github.com/Masterminds/glide - @rm -rf vendor/ - @echo "--> Running glide install" - @glide install - @make check_tools - -update_vendor_deps: - @glide update - -update_tools: - @echo "--> Updating tools" - @go get -u $(GOTOOLS) - -check_tools: - which gox || make tools - -tools: - @echo "--> Installing tools" - @go get $(GOTOOLS) - @gometalinter.v2 --install +######################################## ### Formatting, linting, and vetting -metalinter: - gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... +fmt: + @go fmt ./... -metalinter_test: +metalinter: + @echo "--> Running linter" gometalinter.v2 --vendor --deadline=600s --disable-all \ --enable=deadcode \ --enable=gosimple \ --enable=misspell \ --enable=safesql \ ./... - #--enable=gas \ #--enable=maligned \ #--enable=dupl \ @@ -110,4 +121,12 @@ metalinter_test: #--enable=vet \ #--enable=vetshadow \ -.PHONY: install build build_race check_tools dist test test_race test_integrations test100 draw_deps get_vendor_deps update_vendor_deps update_tools tools test_release +metalinter_all: + @echo "--> Running linter (all)" + gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... + + +# To avoid unintended conflicts with file names, always add to .PHONY +# unless there is a reason not to. +# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html +.PHONY: check build build_race dist install check_tools get_tools update_tools get_vendor_deps draw_deps test test_race test_integrations test_release test100 vagrant_test fmt metalinter metalinter_all