2018-01-05 22:35:57 -08:00
GOTOOLS = \
2018-07-04 14:48:45 -04:00
github.com/mitchellh/gox \
2018-02-27 03:59:50 -08:00
github.com/golang/dep/cmd/dep \
2019-02-06 15:00:55 +04:00
github.com/golangci/golangci-lint/cmd/golangci-lint \
2018-07-04 14:48:45 -04:00
github.com/gogo/protobuf/protoc-gen-gogo \
2018-07-04 17:11:34 -04:00
github.com/square/certstrap
2018-10-09 10:28:15 -07:00
GOBIN ?= ${ GOPATH } /bin
2018-07-27 06:23:19 +04:00
PACKAGES = $( shell go list ./...)
2018-07-23 22:16:34 -04:00
2018-07-04 14:48:45 -04:00
INCLUDE = -I= . -I= ${ GOPATH } /src -I= ${ GOPATH } /src/github.com/gogo/protobuf/protobuf
2018-06-21 01:57:35 -07:00
BUILD_TAGS ?= 'tendermint'
2018-01-08 16:41:23 -06:00
BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
2017-12-04 17:35:42 -06:00
2018-03-08 18:55:14 +04:00
all : check build test install
2015-07-13 11:49:09 -07:00
2018-08-05 14:14:56 -04:00
check : check_tools get_vendor_deps
2017-12-23 02:23:05 -08:00
########################################
2018-07-04 14:48:45 -04:00
### Build Tendermint
2014-12-28 16:26:53 -08:00
2017-01-04 00:32:39 +04:00
build :
2018-06-21 01:57:35 -07:00
CGO_ENABLED = 0 go build $( BUILD_FLAGS) -tags $( BUILD_TAGS) -o build/tendermint ./cmd/tendermint/
2015-04-21 19:51:23 -07:00
2018-09-23 01:14:05 -04:00
build_c :
CGO_ENABLED = 1 go build $( BUILD_FLAGS) -tags " $( BUILD_TAGS) gcc " -o build/tendermint ./cmd/tendermint/
2017-01-04 00:32:39 +04:00
build_race :
2018-06-21 01:57:35 -07:00
CGO_ENABLED = 0 go build -race $( BUILD_FLAGS) -tags $( BUILD_TAGS) -o build/tendermint ./cmd/tendermint
2018-01-08 16:41:23 -06:00
install :
2018-09-23 01:14:05 -04:00
CGO_ENABLED = 0 go install $( BUILD_FLAGS) -tags $( BUILD_TAGS) ./cmd/tendermint
2018-01-08 16:41:23 -06:00
2018-11-28 17:25:23 +04:00
install_c :
CGO_ENABLED = 1 go install $( BUILD_FLAGS) -tags " $( BUILD_TAGS) gcc " ./cmd/tendermint
2018-07-04 14:48:45 -04:00
########################################
2018-07-17 13:56:42 +01:00
### Protobuf
2018-10-29 14:16:50 +01:00
protoc_all : protoc_libs protoc_merkle protoc_abci protoc_grpc protoc_proto 3types
2018-07-04 14:48:45 -04:00
2018-07-17 13:56:42 +01:00
%.pb.go : %.proto
2018-07-04 14:48:45 -04:00
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
2018-08-05 23:22:09 -04:00
## Note the $< here is substituted for the %.proto
## Note the $@ here is substituted for the %.pb.go
2018-07-27 06:23:19 +04:00
protoc $( INCLUDE) $< --gogo_out= Mgoogle/protobuf/timestamp.proto= github.com/golang/protobuf/ptypes/timestamp,plugins= grpc:.
2018-07-17 13:56:42 +01:00
########################################
### Build ABCI
2018-08-05 23:22:09 -04:00
# see protobuf section above
2018-07-17 13:56:42 +01:00
protoc_abci : abci /types /types .pb .go
2018-07-04 14:48:45 -04:00
2018-10-29 14:16:50 +01:00
protoc_proto3types : types /proto 3/block .pb .go
2018-07-04 14:48:45 -04:00
build_abci :
@go build -i ./abci/cmd/...
install_abci :
@go install ./abci/cmd/...
2018-01-08 16:41:23 -06:00
########################################
### Distribution
2014-12-28 17:10:03 -08:00
2017-01-23 13:45:14 +04:00
# dist builds binaries for all platforms and packages them for distribution
2018-07-04 14:48:45 -04:00
# TODO add abci to these scripts
2017-01-23 13:45:14 +04:00
dist :
2018-06-21 01:57:35 -07:00
@BUILD_TAGS= $( BUILD_TAGS) sh -c " ' $( CURDIR) /scripts/dist.sh' "
2017-01-23 13:45:14 +04:00
2017-12-23 02:23:05 -08:00
########################################
### Tools & dependencies
check_tools :
2018-01-05 22:35:57 -08:00
@# https://stackoverflow.com/a/25668869
2018-01-08 16:41:23 -06:00
@echo " Found tools: $( foreach tool,$( notdir $( GOTOOLS) ) ,\
2018-01-05 22:35:57 -08:00
$( if $( shell which $( tool) ) ,$( tool) ,$( error " No $( tool) in PATH " ) ) ) "
2017-12-23 02:23:05 -08:00
get_tools :
@echo "--> Installing tools"
2018-10-09 10:28:15 -07:00
./scripts/get_tools.sh
2018-11-14 05:17:07 -05:00
2017-12-23 02:23:05 -08:00
update_tools :
@echo "--> Updating tools"
2018-10-09 10:28:15 -07:00
./scripts/get_tools.sh
2017-12-23 02:23:05 -08:00
2018-07-25 09:09:52 -07:00
#Update dependencies
2017-12-23 02:23:05 -08:00
get_vendor_deps :
2018-02-27 03:59:50 -08:00
@echo "--> Running dep"
2018-02-27 17:20:56 +04:00
@dep ensure
2017-12-23 02:23:05 -08:00
2018-07-04 17:11:34 -04:00
#For ABCI and libs
2018-07-04 14:48:45 -04:00
get_protoc :
@# https://github.com/google/protobuf/releases
2018-08-10 09:14:17 +04:00
curl -L https://github.com/google/protobuf/releases/download/v3.6.1/protobuf-cpp-3.6.1.tar.gz | tar xvz && \
cd protobuf-3.6.1 && \
2018-07-04 14:48:45 -04:00
DIST_LANG = cpp ./configure && \
make && \
2018-08-10 09:14:17 +04:00
make check && \
sudo make install && \
sudo ldconfig && \
2018-07-04 14:48:45 -04:00
cd .. && \
2018-08-10 09:14:17 +04:00
rm -rf protobuf-3.6.1
2018-07-04 14:48:45 -04:00
2017-12-23 02:23:05 -08:00
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
2018-02-28 08:23:31 +01:00
get_deps_bin_size :
@# Copy of build recipe with additional flags to perform binary size analysis
2018-06-21 01:57:35 -07:00
$( eval $( shell go build -work -a $( BUILD_FLAGS) -tags $( BUILD_TAGS) -o build/tendermint ./cmd/tendermint/ 2>& 1) )
2018-02-28 08:23:31 +01:00
@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 "
2017-12-23 02:23:05 -08:00
2018-07-04 17:11:34 -04:00
########################################
### Libs
2018-07-17 13:56:42 +01:00
protoc_libs : libs /common /types .pb .go
2018-07-04 17:11:34 -04:00
gen_certs : clean_certs
## Generating certificates for TLS testing...
certstrap init --common-name "tendermint.com" --passphrase ""
certstrap request-cert -ip "::" --passphrase ""
certstrap sign "::" --CA "tendermint.com" --passphrase ""
mv out/::.crt out/::.key db/remotedb
clean_certs :
## Cleaning TLS testing certificates...
rm -rf out
rm -f db/remotedb/::.crt db/remotedb/::.key
test_libs : gen_certs
2018-07-17 10:33:00 -07:00
GOCACHE = off go test -tags gcc $( PACKAGES)
2018-07-04 17:11:34 -04:00
make clean_certs
grpc_dbserver :
protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out= plugins = grpc:db/remotedb/proto
2018-07-17 13:56:42 +01:00
protoc_grpc : rpc /grpc /types .pb .go
2018-09-29 09:03:19 +09:00
protoc_merkle : crypto /merkle /merkle .pb .go
2017-12-23 02:23:05 -08:00
########################################
### Testing
2018-03-08 22:52:38 +08:00
## required to be run first by most tests
build_docker_test_image :
docker build -t tester -f ./test/docker/Dockerfile .
### coverage, app, persistence, and libs tests
test_cover :
# run the go unit tests with coverage
bash test/test_cover.sh
2018-03-08 18:55:14 +04:00
2018-03-08 22:52:38 +08:00
test_apps :
# run the app tests using bash
# requires `abci-cli` and `tendermint` binaries installed
bash test/app/test.sh
2018-07-04 14:48:45 -04:00
test_abci_apps :
bash abci/tests/test_app/test.sh
test_abci_cli :
# test the cli against the examples in the tutorial at:
# ./docs/abci-cli.md
# if test fails, update the docs ^
@ bash abci/tests/test_cli/test.sh
2018-03-08 22:52:38 +08:00
test_persistence :
# run the persistence tests using bash
# requires `abci-cli` installed
docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
# TODO undockerize
# bash test/persist/test_failure_indices.sh
test_p2p :
docker rm -f rsyslog || true
rm -rf test/logs || true
mkdir test/logs
cd test/
docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
cd ..
# requires 'tester' the image from above
bash test/p2p/test.sh tester
2018-10-08 02:49:50 -04:00
# the `docker cp` takes a really long time; uncomment for debugging
#
# mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs
2018-03-08 22:52:38 +08:00
2017-01-04 00:32:39 +04:00
test_integrations :
2018-03-08 22:52:38 +08:00
make build_docker_test_image
make get_tools
make get_vendor_deps
make install
make test_cover
make test_apps
2018-07-04 14:54:53 -04:00
make test_abci_apps
2018-07-04 14:48:45 -04:00
make test_abci_cli
2018-07-04 17:11:34 -04:00
make test_libs
2018-03-08 22:52:38 +08:00
make test_persistence
make test_p2p
2017-12-04 17:37:32 -06:00
test_release :
2017-10-25 19:20:33 -07:00
@go test -tags release $( PACKAGES)
2017-01-30 12:02:24 +04:00
test100 :
2017-01-22 18:03:20 +04:00
@for i in { 1..100} ; do make test; done
2016-04-29 15:32:50 -07:00
2017-12-08 18:36:58 +01:00
vagrant_test :
vagrant up
vagrant ssh -c 'make test_integrations'
2018-03-08 22:52:38 +08:00
### go tests
test :
@echo "--> Running go test"
2018-05-29 01:03:03 -07:00
@GOCACHE= off go test -p 1 $( PACKAGES)
2018-03-08 22:52:38 +08:00
test_race :
@echo "--> Running go test --race"
2018-05-29 01:03:03 -07:00
@GOCACHE= off go test -p 1 -v -race $( PACKAGES)
2018-03-08 22:52:38 +08:00
2019-01-28 14:57:47 +04:00
# uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
test_with_deadlock :
2019-02-06 10:29:51 -05:00
make set_with_deadlock
make test
make cleanup_after_test_with_deadlock
set_with_deadlock :
2019-01-28 14:57:47 +04:00
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 goimports -w
# cleanes up after you ran test_with_deadlock
cleanup_after_test_with_deadlock :
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.RWMutex/sync.RWMutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.Mutex/sync.Mutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
2017-02-08 19:28:25 +01:00
2017-12-23 02:23:05 -08:00
########################################
2017-05-30 13:27:31 -04:00
### Formatting, linting, and vetting
2017-12-23 02:23:05 -08:00
fmt :
@go fmt ./...
2017-02-08 19:28:25 +01:00
2019-02-06 15:00:55 +04:00
lint :
2017-12-23 02:23:05 -08:00
@echo "--> Running linter"
2019-02-06 15:00:55 +04:00
@golangci-lint run
2017-12-23 02:23:05 -08:00
2018-07-25 17:37:08 -04:00
DESTINATION = ./index.html.md
rpc-docs :
cat rpc/core/slate_header.txt > $( DESTINATION)
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)
2018-07-25 09:09:52 -07:00
check_dep :
dep status >> /dev/null
!( grep -n branch Gopkg.toml)
2018-04-16 11:34:01 -04:00
###########################################################
### Docker image
build-docker :
cp build/tendermint DOCKER/tendermint
docker build --label= tendermint --tag= "tendermint/tendermint" DOCKER
rm -rf DOCKER/tendermint
2018-04-12 13:15:16 +02:00
###########################################################
### Local testnet using docker
# Build linux binary on other platforms
2019-02-07 06:58:23 -05:00
build-linux : get_tools get_vendor_deps
2018-04-12 13:15:16 +02:00
GOOS = linux GOARCH = amd64 $( MAKE) build
2018-05-19 23:21:19 -04:00
build-docker-localnode :
2019-01-15 02:33:33 +04:00
@cd networks/local && make
2018-05-19 23:21:19 -04:00
2018-04-12 13:15:16 +02:00
# Run a 4-node testnet locally
2018-05-10 14:02:31 +04:00
localnet-start : localnet -stop
2018-04-13 21:03:25 -04:00
@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
2018-04-12 13:15:16 +02:00
docker-compose up
# Stop testnet
2018-04-17 12:28:05 -04:00
localnet-stop :
2018-04-12 13:15:16 +02:00
docker-compose down
2018-04-13 21:03:25 -04:00
###########################################################
### Remote full-nodes (sentry) using terraform and ansible
# Server management
2018-04-24 14:22:19 -04:00
sentry-start :
2018-04-16 11:34:01 -04:00
@if [ -z " $( DO_API_TOKEN) " ] ; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
2018-04-13 21:03:25 -04:00
@if ! [ -f $( HOME) /.ssh/id_rsa.pub ] ; then ssh-keygen ; fi
cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN = " $( DO_API_TOKEN) " -var SSH_KEY_FILE = " $( HOME) /.ssh/id_rsa.pub "
2018-04-16 11:34:01 -04:00
@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
2018-04-24 14:22:19 -04:00
cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING = False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
2018-05-18 13:22:04 -04:00
@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.)"
2018-04-13 21:03:25 -04:00
# Configuration management
2018-04-24 14:22:19 -04:00
sentry-config :
cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY = $( CURDIR) /build/tendermint -e CONFIGDIR = $( CURDIR) /build
2018-04-16 11:34:01 -04:00
2018-04-24 14:22:19 -04:00
sentry-stop :
2018-04-16 11:34:01 -04:00
@if [ -z " $( DO_API_TOKEN) " ] ; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN = " $( DO_API_TOKEN) " -var SSH_KEY_FILE = " $( HOME) /.ssh/id_rsa.pub "
2018-04-13 21:03:25 -04:00
2018-05-25 07:59:24 -04:00
# meant for the CI, inspect script & adapt accordingly
build-slate :
bash scripts/slate.sh
2017-12-23 02:23:05 -08:00
# 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
2019-02-06 15:00:55 +04:00
.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_p 2p test test_race test_integrations test_release test 100 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