Browse Source

makefile: place phony markers after targets (#4408)

The .PHONY targets in the Makefile are usually placed far away from the actual targets, and thus aren't always updated. Placing the .PHONY targets right next to the targets they cover make them more visible and thus more likely to be updated when necessary.
pull/4423/head
Erik Grinaker 5 years ago
committed by GitHub
parent
commit
5f5e0e1d02
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 15 deletions
  1. +28
    -11
      Makefile
  2. +17
    -2
      tests.mk
  3. +11
    -2
      tools.mk

+ 28
- 11
Makefile View File

@ -6,6 +6,7 @@ LD_FLAGS = -X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)" BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
all: check build test install all: check build test install
.PHONY: all
# The below include contains the tools. # The below include contains the tools.
include tools.mk include tools.mk
@ -17,24 +18,30 @@ include tests.mk
build: build:
CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/
.PHONY: build
build_c: build_c:
CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" -o $(OUTPUT) ./cmd/tendermint/ CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" -o $(OUTPUT) ./cmd/tendermint/
.PHONY: build_c
build_race: build_race:
CGO_ENABLED=1 go build -race $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint CGO_ENABLED=1 go build -race $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint
.PHONY: build_race
install: install:
CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
.PHONY: install
install_c: install_c:
CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" ./cmd/tendermint CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" ./cmd/tendermint
.PHONY: install_c
############################################################################### ###############################################################################
### Protobuf ### ### Protobuf ###
############################################################################### ###############################################################################
proto-all: proto-gen proto-lint proto-check-breaking proto-all: proto-gen proto-lint proto-check-breaking
.PHONY: proto-all
proto-gen: proto-gen:
## If you get the following error, ## If you get the following error,
@ -43,14 +50,15 @@ proto-gen:
## Note the $< here is substituted for the %.proto ## Note the $< here is substituted for the %.proto
## Note the $@ here is substituted for the %.pb.go ## Note the $@ here is substituted for the %.pb.go
@sh scripts/protocgen.sh @sh scripts/protocgen.sh
.PHONY: proto-gen
proto-lint: proto-lint:
@buf check lint --error-format=json @buf check lint --error-format=json
.PHONY: proto-lint
proto-check-breaking: proto-check-breaking:
@buf check breaking --against-input '.git#branch=master' @buf check breaking --against-input '.git#branch=master'
.PHONY: proto-all proto-gen proto-lint proto-check-breaking
.PHONY: proto-check-breaking
############################################################################### ###############################################################################
### Build ABCI ### ### Build ABCI ###
@ -58,9 +66,11 @@ proto-check-breaking:
build_abci: build_abci:
@go build -mod=readonly -i ./abci/cmd/... @go build -mod=readonly -i ./abci/cmd/...
.PHONY: build_abci
install_abci: install_abci:
@go install -mod=readonly ./abci/cmd/... @go install -mod=readonly ./abci/cmd/...
.PHONY: install_abci
############################################################################### ###############################################################################
### Distribution ### ### Distribution ###
@ -70,6 +80,7 @@ install_abci:
# TODO add abci to these scripts # TODO add abci to these scripts
dist: dist:
@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'" @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
.PHONY: dist
go-mod-cache: go.sum go-mod-cache: go.sum
@echo "--> Download go modules to local cache" @echo "--> Download go modules to local cache"
@ -85,12 +96,14 @@ draw_deps:
@# requires brew install graphviz or apt-get install graphviz @# requires brew install graphviz or apt-get install graphviz
go get github.com/RobotsAndPencils/goviz go get github.com/RobotsAndPencils/goviz
@goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
.PHONY: draw_deps
get_deps_bin_size: get_deps_bin_size:
@# Copy of build recipe with additional flags to perform binary size analysis @# Copy of build recipe with additional flags to perform binary size analysis
$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1)) $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1))
@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
@echo "Results can be found here: $(CURDIR)/deps_bin_size.log" @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
.PHONY: get_deps_bin_size
############################################################################### ###############################################################################
### Libs ### ### Libs ###
@ -104,11 +117,13 @@ gen_certs: clean_certs
mv out/server.crt rpc/lib/server/test.crt mv out/server.crt rpc/lib/server/test.crt
mv out/server.key rpc/lib/server/test.key mv out/server.key rpc/lib/server/test.key
rm -rf out rm -rf out
.PHONY: gen_certs
# deletes generated certificates # deletes generated certificates
clean_certs: clean_certs:
rm -f rpc/lib/server/test.crt rm -f rpc/lib/server/test.crt
rm -f rpc/lib/server/test.key rm -f rpc/lib/server/test.key
.PHONY: clean_certs
############################################################################### ###############################################################################
### Formatting, linting, and vetting ### ### Formatting, linting, and vetting ###
@ -116,10 +131,12 @@ clean_certs:
fmt: fmt:
@go fmt ./... @go fmt ./...
.PHONY: fmt
lint: lint:
@echo "--> Running linter" @echo "--> Running linter"
@golangci-lint run @golangci-lint run
.PHONY: lint
DESTINATION = ./index.html.md DESTINATION = ./index.html.md
@ -135,6 +152,7 @@ build-docs:
cp -r .vuepress/dist/* ~/output/$${p}/ ; \ cp -r .vuepress/dist/* ~/output/$${p}/ ; \
cp ~/output/$${p}/index.html ~/output ; \ cp ~/output/$${p}/index.html ~/output ; \
done < versions ; done < versions ;
.PHONY: build-docs
sync-docs: sync-docs:
cd ~/output && \ cd ~/output && \
@ -152,6 +170,7 @@ build-docker:
cp $(OUTPUT) DOCKER/tendermint cp $(OUTPUT) DOCKER/tendermint
docker build --label=tendermint --tag="tendermint/tendermint" DOCKER docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
rm -rf DOCKER/tendermint rm -rf DOCKER/tendermint
.PHONY: build-docker
############################################################################### ###############################################################################
### Local testnet using docker ### ### Local testnet using docker ###
@ -160,9 +179,11 @@ build-docker:
# Build linux binary on other platforms # Build linux binary on other platforms
build-linux: tools build-linux: tools
GOOS=linux GOARCH=amd64 $(MAKE) build GOOS=linux GOARCH=amd64 $(MAKE) build
.PHONY: build-linux
build-docker-localnode: build-docker-localnode:
@cd networks/local && make @cd networks/local && make
.PHONY: build-docker-localnode
# Runs `make build_c` from within an Amazon Linux (v2)-based Docker build # Runs `make build_c` from within an Amazon Linux (v2)-based Docker build
# container in order to build an Amazon Linux-compatible binary. Produces a # container in order to build an Amazon Linux-compatible binary. Produces a
@ -170,15 +191,18 @@ build-docker-localnode:
build_c-amazonlinux: build_c-amazonlinux:
$(MAKE) -C ./DOCKER build_amazonlinux_buildimage $(MAKE) -C ./DOCKER build_amazonlinux_buildimage
docker run --rm -it -v `pwd`:/tendermint tendermint/tendermint:build_c-amazonlinux docker run --rm -it -v `pwd`:/tendermint tendermint/tendermint:build_c-amazonlinux
.PHONY: build_c-amazonlinux
# Run a 4-node testnet locally # Run a 4-node testnet locally
localnet-start: localnet-stop build-docker-localnode localnet-start: localnet-stop build-docker-localnode
@if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --config /etc/tendermint/config-template.toml --v 4 --o . --populate-persistent-peers --starting-ip-address 192.167.10.2; fi @if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --config /etc/tendermint/config-template.toml --v 4 --o . --populate-persistent-peers --starting-ip-address 192.167.10.2; fi
docker-compose up docker-compose up
.PHONY: localnet-start
# Stop testnet # Stop testnet
localnet-stop: localnet-stop:
docker-compose down docker-compose down
.PHONY: localnet-stop
# Build hooks for dredd, to skip or add information on some steps # Build hooks for dredd, to skip or add information on some steps
build-contract-tests-hooks: build-contract-tests-hooks:
@ -187,6 +211,7 @@ ifeq ($(OS),Windows_NT)
else else
go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests
endif endif
.PHONY: build-contract-tests-hooks
# Run a nodejs tool to test endpoints against a localnet # Run a nodejs tool to test endpoints against a localnet
# The command takes care of starting and stopping the network # The command takes care of starting and stopping the network
@ -195,12 +220,4 @@ endif
# The binaries should be built beforehand # The binaries should be built beforehand
contract-tests: contract-tests:
dredd dredd
# 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 build_abci dist install install_abci check_tools tools update_tools draw_deps \
protoc_abci protoc_libs gen_certs clean_certs grpc_dbserver fmt build-linux localnet-start \
localnet-stop build-docker build-docker-localnode protoc_grpc protoc_all \
build_c install_c test_with_deadlock cleanup_after_test_with_deadlock lint build-contract-tests-hooks contract-tests \
build_c-amazonlinux
.PHONY: contract-tests

+ 17
- 2
tests.mk View File

@ -8,25 +8,30 @@ BINDIR ?= $(GOPATH)/bin
## required to be run first by most tests ## required to be run first by most tests
build_docker_test_image: build_docker_test_image:
docker build -t tester -f ./test/docker/Dockerfile . docker build -t tester -f ./test/docker/Dockerfile .
.PHONY: build_docker_test_image
### coverage, app, persistence, and libs tests ### coverage, app, persistence, and libs tests
test_cover: test_cover:
# run the go unit tests with coverage # run the go unit tests with coverage
bash test/test_cover.sh bash test/test_cover.sh
.PHONY: test_cover
test_apps: test_apps:
# run the app tests using bash # run the app tests using bash
# requires `abci-cli` and `tendermint` binaries installed # requires `abci-cli` and `tendermint` binaries installed
bash test/app/test.sh bash test/app/test.sh
.PHONY: test_apps
test_abci_apps: test_abci_apps:
bash abci/tests/test_app/test.sh bash abci/tests/test_app/test.sh
.PHONY: test_abci_apps
test_abci_cli: test_abci_cli:
# test the cli against the examples in the tutorial at: # test the cli against the examples in the tutorial at:
# ./docs/abci-cli.md # ./docs/abci-cli.md
# if test fails, update the docs ^ # if test fails, update the docs ^
@ bash abci/tests/test_cli/test.sh @ bash abci/tests/test_cli/test.sh
.PHONY: test_abci_cli
test_persistence: test_persistence:
# run the persistence tests using bash # run the persistence tests using bash
@ -35,6 +40,7 @@ test_persistence:
# TODO undockerize # TODO undockerize
# bash test/persist/test_failure_indices.sh # bash test/persist/test_failure_indices.sh
.PHONY: test_persistence
test_p2p: test_p2p:
docker rm -f rsyslog || true docker rm -f rsyslog || true
@ -45,6 +51,7 @@ test_p2p:
# the `docker cp` takes a really long time; uncomment for debugging # the `docker cp` takes a really long time; uncomment for debugging
# #
# mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs # mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs
.PHONY: test_p2p
test_p2p_ipv6: test_p2p_ipv6:
# IPv6 tests require Docker daemon with IPv6 enabled, e.g. in daemon.json: # IPv6 tests require Docker daemon with IPv6 enabled, e.g. in daemon.json:
@ -63,6 +70,7 @@ test_p2p_ipv6:
# the `docker cp` takes a really long time; uncomment for debugging # the `docker cp` takes a really long time; uncomment for debugging
# #
# mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs # mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs
.PHONY: test_p2p_ipv6
test_integrations: test_integrations:
make build_docker_test_image make build_docker_test_image
@ -77,31 +85,38 @@ test_integrations:
make test_p2p make test_p2p
# Disabled by default since it requires Docker daemon with IPv6 enabled # Disabled by default since it requires Docker daemon with IPv6 enabled
#make test_p2p_ipv6 #make test_p2p_ipv6
.PHONY: test_integrations
test_release: test_release:
@go test -tags release $(PACKAGES) @go test -tags release $(PACKAGES)
.PHONY: test_release
test100: test100:
@for i in {1..100}; do make test; done @for i in {1..100}; do make test; done
.PHONY: test100
vagrant_test: vagrant_test:
vagrant up vagrant up
vagrant ssh -c 'make test_integrations' vagrant ssh -c 'make test_integrations'
.PHONY: vagrant_test
### go tests ### go tests
test: test:
@echo "--> Running go test" @echo "--> Running go test"
@go test -p 1 $(PACKAGES) @go test -p 1 $(PACKAGES)
.PHONY: test
test_race: test_race:
@echo "--> Running go test --race" @echo "--> Running go test --race"
@go test -p 1 -v -race $(PACKAGES) @go test -p 1 -v -race $(PACKAGES)
.PHONY: test_race
# uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks # uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
test_with_deadlock: test_with_deadlock:
make set_with_deadlock make set_with_deadlock
make test make test
make cleanup_after_test_with_deadlock make cleanup_after_test_with_deadlock
.PHONY: test_with_deadlock
set_with_deadlock: set_with_deadlock:
@echo "Get Goid" @echo "Get Goid"
@ -111,6 +126,7 @@ set_with_deadlock:
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/' find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/' find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
.PHONY: set_with_deadlock
# cleanes up after you ran test_with_deadlock # cleanes up after you ran test_with_deadlock
cleanup_after_test_with_deadlock: cleanup_after_test_with_deadlock:
@ -119,5 +135,4 @@ cleanup_after_test_with_deadlock:
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
# cleans up the deps to not include the need libs # cleans up the deps to not include the need libs
go mod tidy go mod tidy
.PHONY: test_cover test_apps test_persistence test_p2p test test_race test_integrations test_release test100 vagrant_test
.PHONY: cleanup_after_test_with_deadlock

+ 11
- 2
tools.mk View File

@ -51,25 +51,31 @@ PROTOBUF = $(TOOLS_DESTDIR)/protoc
GOODMAN = $(TOOLS_DESTDIR)/goodman GOODMAN = $(TOOLS_DESTDIR)/goodman
all: tools all: tools
.PHONY: all
tools: certstrap protobuf goodman tools: certstrap protobuf goodman
.PHONY: tools
check: check_tools check: check_tools
.PHONY: check
check_tools: check_tools:
@# https://stackoverflow.com/a/25668869 @# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\ @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))" $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
.PHONY: check_tools
certstrap: $(CERTSTRAP) certstrap: $(CERTSTRAP)
$(CERTSTRAP): $(CERTSTRAP):
@echo "Get Certstrap" @echo "Get Certstrap"
@go get github.com/square/certstrap@v1.2.0 @go get github.com/square/certstrap@v1.2.0
.PHONY: certstrap
protobuf: $(PROTOBUF) protobuf: $(PROTOBUF)
$(PROTOBUF): $(PROTOBUF):
@echo "Get GoGo Protobuf" @echo "Get GoGo Protobuf"
@go get github.com/gogo/protobuf/protoc-gen-gogo@v1.3.1 @go get github.com/gogo/protobuf/protoc-gen-gogo@v1.3.1
.PHONY: protobuf
buf: protoc-gen-buf-check-breaking protoc-gen-buf-check-lint buf: protoc-gen-buf-check-breaking protoc-gen-buf-check-lint
@echo "Installing buf..." @echo "Installing buf..."
@ -77,6 +83,7 @@ buf: protoc-gen-buf-check-breaking protoc-gen-buf-check-lint
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-${UNAME_S}-${UNAME_M}" \ "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/buf" && \ -o "${BIN}/buf" && \
chmod +x "${BIN}/buf" chmod +x "${BIN}/buf"
.PHONY: buf
protoc-gen-buf-check-breaking: protoc-gen-buf-check-breaking:
@echo "Installing protoc-gen-buf-check-breaking..." @echo "Installing protoc-gen-buf-check-breaking..."
@ -91,17 +98,20 @@ protoc-gen-buf-check-lint:
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-lint-${UNAME_S}-${UNAME_M}" \ "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-lint-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/protoc-gen-buf-check-lint" && \ -o "${BIN}/protoc-gen-buf-check-lint" && \
chmod +x "${BIN}/protoc-gen-buf-check-lint" chmod +x "${BIN}/protoc-gen-buf-check-lint"
.PHONY: protoc-gen-buf-check-lint
goodman: $(GOODMAN) goodman: $(GOODMAN)
$(GOODMAN): $(GOODMAN):
@echo "Get Goodman" @echo "Get Goodman"
@go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888 @go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
.PHONY: goodman
tools-clean: tools-clean:
rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN) rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
rm -f tools-stamp rm -f tools-stamp
rm -rf /usr/local/include/google/protobuf rm -rf /usr/local/include/google/protobuf
rm -f /usr/local/bin/protoc rm -f /usr/local/bin/protoc
.PHONY: tooks-clean
### ###
# Non Go tools # Non Go tools
@ -127,5 +137,4 @@ protoc:
@unzip -o $(PROTOC_ZIP) -d /usr/local bin/protoc @unzip -o $(PROTOC_ZIP) -d /usr/local bin/protoc
@unzip -o $(PROTOC_ZIP) -d /usr/local 'include/*' @unzip -o $(PROTOC_ZIP) -d /usr/local 'include/*'
@rm -f $(PROTOC_ZIP) @rm -f $(PROTOC_ZIP)
.PHONY: all tools tools-clean protoc
.PHONY: protoc

Loading…
Cancel
Save