You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
10 KiB

7 years ago
6 years ago
9 years ago
  1. GOTOOLS = \
  2. github.com/mitchellh/gox \
  3. github.com/golang/dep/cmd/dep \
  4. github.com/golangci/golangci-lint/cmd/golangci-lint \
  5. github.com/gogo/protobuf/protoc-gen-gogo \
  6. github.com/square/certstrap
  7. GOBIN?=${GOPATH}/bin
  8. PACKAGES=$(shell go list ./...)
  9. INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
  10. BUILD_TAGS?='tendermint'
  11. BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
  12. all: check build test install
  13. check: check_tools get_vendor_deps
  14. ########################################
  15. ### Build Tendermint
  16. build:
  17. CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o build/tendermint ./cmd/tendermint/
  18. build_c:
  19. CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) gcc" -o build/tendermint ./cmd/tendermint/
  20. build_race:
  21. CGO_ENABLED=0 go build -race $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o build/tendermint ./cmd/tendermint
  22. install:
  23. CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
  24. install_c:
  25. CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) gcc" ./cmd/tendermint
  26. ########################################
  27. ### Protobuf
  28. protoc_all: protoc_libs protoc_merkle protoc_abci protoc_grpc protoc_proto3types
  29. %.pb.go: %.proto
  30. ## If you get the following error,
  31. ## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
  32. ## See https://stackoverflow.com/a/25518702
  33. ## Note the $< here is substituted for the %.proto
  34. ## Note the $@ here is substituted for the %.pb.go
  35. protoc $(INCLUDE) $< --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,plugins=grpc:.
  36. ########################################
  37. ### Build ABCI
  38. # see protobuf section above
  39. protoc_abci: abci/types/types.pb.go
  40. protoc_proto3types: types/proto3/block.pb.go
  41. build_abci:
  42. @go build -i ./abci/cmd/...
  43. install_abci:
  44. @go install ./abci/cmd/...
  45. ########################################
  46. ### Distribution
  47. # dist builds binaries for all platforms and packages them for distribution
  48. # TODO add abci to these scripts
  49. dist:
  50. @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
  51. ########################################
  52. ### Tools & dependencies
  53. check_tools:
  54. @# https://stackoverflow.com/a/25668869
  55. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  56. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  57. get_tools:
  58. @echo "--> Installing tools"
  59. ./scripts/get_tools.sh
  60. update_tools:
  61. @echo "--> Updating tools"
  62. ./scripts/get_tools.sh
  63. #Update dependencies
  64. get_vendor_deps:
  65. @echo "--> Running dep"
  66. @dep ensure
  67. #For ABCI and libs
  68. get_protoc:
  69. @# https://github.com/google/protobuf/releases
  70. curl -L https://github.com/google/protobuf/releases/download/v3.6.1/protobuf-cpp-3.6.1.tar.gz | tar xvz && \
  71. cd protobuf-3.6.1 && \
  72. DIST_LANG=cpp ./configure && \
  73. make && \
  74. make check && \
  75. sudo make install && \
  76. sudo ldconfig && \
  77. cd .. && \
  78. rm -rf protobuf-3.6.1
  79. draw_deps:
  80. @# requires brew install graphviz or apt-get install graphviz
  81. go get github.com/RobotsAndPencils/goviz
  82. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  83. get_deps_bin_size:
  84. @# Copy of build recipe with additional flags to perform binary size analysis
  85. $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o build/tendermint ./cmd/tendermint/ 2>&1))
  86. @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
  87. @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
  88. ########################################
  89. ### Libs
  90. protoc_libs: libs/common/types.pb.go
  91. gen_certs: clean_certs
  92. ## Generating certificates for TLS testing...
  93. certstrap init --common-name "tendermint.com" --passphrase ""
  94. certstrap request-cert -ip "::" --passphrase ""
  95. certstrap sign "::" --CA "tendermint.com" --passphrase ""
  96. mv out/::.crt out/::.key db/remotedb
  97. clean_certs:
  98. ## Cleaning TLS testing certificates...
  99. rm -rf out
  100. rm -f db/remotedb/::.crt db/remotedb/::.key
  101. test_libs: gen_certs
  102. GOCACHE=off go test -tags gcc $(PACKAGES)
  103. make clean_certs
  104. grpc_dbserver:
  105. protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out=plugins=grpc:db/remotedb/proto
  106. protoc_grpc: rpc/grpc/types.pb.go
  107. protoc_merkle: crypto/merkle/merkle.pb.go
  108. ########################################
  109. ### Testing
  110. ## required to be run first by most tests
  111. build_docker_test_image:
  112. docker build -t tester -f ./test/docker/Dockerfile .
  113. ### coverage, app, persistence, and libs tests
  114. test_cover:
  115. # run the go unit tests with coverage
  116. bash test/test_cover.sh
  117. test_apps:
  118. # run the app tests using bash
  119. # requires `abci-cli` and `tendermint` binaries installed
  120. bash test/app/test.sh
  121. test_abci_apps:
  122. bash abci/tests/test_app/test.sh
  123. test_abci_cli:
  124. # test the cli against the examples in the tutorial at:
  125. # ./docs/abci-cli.md
  126. # if test fails, update the docs ^
  127. @ bash abci/tests/test_cli/test.sh
  128. test_persistence:
  129. # run the persistence tests using bash
  130. # requires `abci-cli` installed
  131. docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
  132. # TODO undockerize
  133. # bash test/persist/test_failure_indices.sh
  134. test_p2p:
  135. docker rm -f rsyslog || true
  136. rm -rf test/logs || true
  137. mkdir test/logs
  138. cd test/
  139. docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
  140. cd ..
  141. # requires 'tester' the image from above
  142. bash test/p2p/test.sh tester
  143. # the `docker cp` takes a really long time; uncomment for debugging
  144. #
  145. # mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs
  146. test_integrations:
  147. make build_docker_test_image
  148. make get_tools
  149. make get_vendor_deps
  150. make install
  151. make test_cover
  152. make test_apps
  153. make test_abci_apps
  154. make test_abci_cli
  155. make test_libs
  156. make test_persistence
  157. make test_p2p
  158. test_release:
  159. @go test -tags release $(PACKAGES)
  160. test100:
  161. @for i in {1..100}; do make test; done
  162. vagrant_test:
  163. vagrant up
  164. vagrant ssh -c 'make test_integrations'
  165. ### go tests
  166. test:
  167. @echo "--> Running go test"
  168. @GOCACHE=off go test -p 1 $(PACKAGES)
  169. test_race:
  170. @echo "--> Running go test --race"
  171. @GOCACHE=off go test -p 1 -v -race $(PACKAGES)
  172. # uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
  173. test_with_deadlock:
  174. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/'
  175. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/'
  176. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
  177. make test
  178. make cleanup_after_test_with_deadlock
  179. # cleanes up after you ran test_with_deadlock
  180. cleanup_after_test_with_deadlock:
  181. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.RWMutex/sync.RWMutex/'
  182. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.Mutex/sync.Mutex/'
  183. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
  184. ########################################
  185. ### Formatting, linting, and vetting
  186. fmt:
  187. @go fmt ./...
  188. lint:
  189. @echo "--> Running linter"
  190. @golangci-lint run
  191. DESTINATION = ./index.html.md
  192. rpc-docs:
  193. cat rpc/core/slate_header.txt > $(DESTINATION)
  194. godoc2md -template rpc/core/doc_template.txt github.com/tendermint/tendermint/rpc/core | grep -v -e "pipe.go" -e "routes.go" -e "dev.go" | sed 's,/src/target,https://github.com/tendermint/tendermint/tree/master/rpc/core,' >> $(DESTINATION)
  195. check_dep:
  196. dep status >> /dev/null
  197. !(grep -n branch Gopkg.toml)
  198. ###########################################################
  199. ### Docker image
  200. build-docker:
  201. cp build/tendermint DOCKER/tendermint
  202. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  203. rm -rf DOCKER/tendermint
  204. ###########################################################
  205. ### Local testnet using docker
  206. # Build linux binary on other platforms
  207. build-linux:
  208. GOOS=linux GOARCH=amd64 $(MAKE) build
  209. build-docker-localnode:
  210. @cd networks/local && make
  211. # Run a 4-node testnet locally
  212. localnet-start: localnet-stop
  213. @if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --v 4 --o . --populate-persistent-peers --starting-ip-address 192.167.10.2 ; fi
  214. docker-compose up
  215. # Stop testnet
  216. localnet-stop:
  217. docker-compose down
  218. ###########################################################
  219. ### Remote full-nodes (sentry) using terraform and ansible
  220. # Server management
  221. sentry-start:
  222. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  223. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  224. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  225. @if ! [ -f $(CURDIR)/build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --v 0 --n 4 --o . ; fi
  226. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  227. @echo "Next step: Add your validator setup in the genesis.json and config.tml files and run \"make sentry-config\". (Public key of validator, chain ID, peer IP and node ID.)"
  228. # Configuration management
  229. sentry-config:
  230. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  231. sentry-stop:
  232. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  233. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  234. # meant for the CI, inspect script & adapt accordingly
  235. build-slate:
  236. bash scripts/slate.sh
  237. # To avoid unintended conflicts with file names, always add to .PHONY
  238. # unless there is a reason not to.
  239. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  240. .PHONY: check build build_race build_abci dist install install_abci check_dep check_tools get_tools update_tools get_vendor_deps draw_deps get_protoc protoc_abci protoc_libs gen_certs clean_certs grpc_dbserver test_cover test_apps test_persistence test_p2p test test_race test_integrations test_release test100 vagrant_test fmt rpc-docs build-linux localnet-start localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop build-slate protoc_grpc protoc_all build_c install_c test_with_deadlock cleanup_after_test_with_deadlock lint