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.

346 lines
11 KiB

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