github.com/turingchain2020/turingchain@v1.1.21/Makefile (about) 1 # golang1.12 or latest 2 # 1. make help 3 # 2. make dep 4 # 3. make build 5 # ... 6 export GO111MODULE=on 7 SRC := github.com/turingchain2020/turingchain/cmd/turingchain 8 SRC_CLI := github.com/turingchain2020/turingchain/cmd/cli 9 SRC_SIGNATORY := github.com/turingchain2020/turingchain/cmd/signatory-server 10 SRC_MINER := github.com/turingchain2020/turingchain/cmd/miner_accounts 11 APP := build/turingchain 12 CLI := build/turingchain-cli 13 SIGNATORY := build/signatory-server 14 MINER := build/miner_accounts 15 AUTOTEST := build/autotest/autotest 16 SRC_AUTOTEST := github.com/turingchain2020/turingchain/cmd/autotest 17 LDFLAGS := -ldflags "-w -s" 18 BUILD_FLAGS = -ldflags "-X github.com/turingchain2020/turingchain/common/version.GitCommit=`git rev-parse --short=8 HEAD`" 19 MKPATH=$(abspath $(lastword $(MAKEFILE_LIST))) 20 MKDIR=$(dir $(MKPATH)) 21 DAPP := "" 22 PROJ := "build" 23 .PHONY: default dep all build release cli linter race test fmt vet bench msan coverage coverhtml docker docker-compose protobuf clean help autotest 24 25 default: build cli depends 26 27 dep: ## Get the dependencies 28 @go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.17.1 29 @go get -u golang.org/x/tools/cmd/goimports 30 @go get -u github.com/mitchellh/gox 31 @go get -u github.com/vektra/mockery/.../ 32 @go get -u mvdan.cc/sh/cmd/shfmt 33 @go get -u mvdan.cc/sh/cmd/gosh 34 @git checkout go.mod go.sum 35 @apt install clang-format 36 @apt install shellcheck 37 38 all: ## Builds for multiple platforms 39 @gox $(LDFLAGS) $(SRC) 40 @cp cmd/turingchain/turingchain.toml build/ 41 @cp cmd/turingchain/turingchaincoin.toml build/ 42 @mv turingchain* build/ 43 44 build: ## Build the binary file 45 @go build $(BUILD_FLAGS) -v -i -o $(APP) $(SRC) 46 @cp cmd/turingchain/turingchain.toml build/ 47 @cp cmd/turingchain/turingchaincoin.toml build/ 48 49 release: ## Build the binary file 50 @go build -v -i -o $(APP) $(LDFLAGS) $(SRC) 51 @cp cmd/turingchain/turingchain.toml build/ 52 @cp cmd/turingchain/turingchaincoin.toml build/ 53 @cp cmd/turingchain/turingchain.para.toml build/ 54 55 cli: ## Build cli binary 56 @go build -v -i -o $(CLI) $(SRC_CLI) 57 58 execblock: ## Build cli binary 59 @go build -v -i -o build/execblock github.com/turingchain2020/turingchain/cmd/execblock 60 61 62 para: 63 @go build -v -o build/$(NAME) -ldflags "-X $(SRC_CLI)/buildflags.ParaName=user.p.$(NAME). -X $(SRC_CLI)/buildflags.RPCAddr=http://localhost:8901" $(SRC_CLI) 64 65 66 autotest:## build autotest binary 67 @go build -v -i -o $(AUTOTEST) $(SRC_AUTOTEST) 68 @if [ -n "$(dapp)" ]; then \ 69 cd build/autotest && ./run.sh local $(dapp) && cd ../../; fi 70 autotest_ci: autotest ## autotest jerkins ci 71 @cd build/autotest && ./run.sh jerkinsci $(proj) && cd ../../ 72 73 signatory: 74 @cd cmd/signatory-server/signatory && bash ./create_protobuf.sh && cd ../.../.. 75 @go build -v -o $(SIGNATORY) $(SRC_SIGNATORY) 76 @cp cmd/signatory-server/signatory.toml build/ 77 78 miner: 79 @cd cmd/miner_accounts/accounts && bash ./create_protobuf.sh && cd ../.../.. 80 @go build -v -o $(MINER) $(SRC_MINER) 81 @cp cmd/miner_accounts/miner_accounts.toml build/ 82 83 build_ci: depends ## Build the binary file for CI 84 @go build -v -i -o $(CLI) $(SRC_CLI) 85 @go build $(BUILD_FLAGS) -v -o $(APP) $(SRC) 86 @cp cmd/turingchain/turingchain.toml build/ 87 88 linter: vet ineffassign gosec ## Use gometalinter check code, ignore some unserious warning 89 @./golinter.sh "filter" 90 @find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck 91 92 linter_test: ## Use gometalinter check code, for local test 93 @./golinter.sh "test" "${p}" 94 @find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck 95 96 gosec: 97 @golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all --enable=gosec --skip-dirs=commands 98 99 race: ## Run data race detector 100 @go test -race -short `go list ./... | grep -v "mocks"` 101 102 vet: 103 @go vet `go list -f {{.Dir}} ./... | grep -v "common/crypto/sha3"` 104 105 ineffassign: 106 @golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all --enable=ineffassign ./... 107 108 test: ## Run unittests 109 @go clean -testcache 110 @go test -short -race `go list ./... | grep -v "mocks"` 111 112 testq: ## Run unittests 113 @go test `go list ./... | grep -v "mocks"` 114 115 fmt: fmt_proto fmt_shell ## go fmt 116 go fmt ./... 117 find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w 118 119 .PHONY: fmt_proto fmt_shell 120 fmt_proto: ## go fmt protobuf file 121 @find . -name '*.proto' -not -path "./vendor/*" | xargs clang-format -i 122 123 fmt_shell: ## check shell file 124 find . -name '*.sh' -not -path "./vendor/*" | xargs shfmt -w -s -i 4 -ci -bn 125 126 bench: ## Run benchmark of all 127 @go test ./... -v -bench=. 128 129 msan: ## Run memory sanitizer 130 @go test -msan -short $(go list ./... | grep -v "mocks") 131 132 coverage: ## Generate global code coverage report 133 @./build/tools/coverage.sh 134 135 coverhtml: ## Generate global code coverage report in HTML 136 @./build/tools/coverage.sh html 137 138 docker: ## build docker image for turingchain run 139 @sudo docker build . -f ./build/Dockerfile-run -t turingchain:latest 140 141 docker-compose: ## build docker-compose for turingchain run 142 @cd build && if ! [ -d ci ]; then \ 143 make -C ../ ; \ 144 fi; \ 145 cp turingchain* Dockerfile docker-compose* system-test* ci/ && cd ci/ && ./docker-compose-pre.sh run $(PROJ) $(DAPP) && cd ../.. 146 147 docker-compose-down: ## build docker-compose for turingchain run 148 @cd build && if [ -d ci ]; then \ 149 cp turingchain* Dockerfile docker-compose* ci/ && cd ci/ && ./docker-compose-pre.sh down $(PROJ) $(DAPP) && cd .. ; \ 150 fi; \ 151 cd .. 152 153 fork-test: ## build fork-test for turingchain run 154 @cd build && cp turingchain* Dockerfile system-fork-test.sh docker-compose* ci/ && cd ci/ && ./docker-compose-pre.sh forktest $(PROJ) $(DAPP) && cd ../.. 155 156 157 clean: ## Remove previous build 158 @rm -rf $(shell find . -name 'datadir' -not -path "./vendor/*") 159 @rm -rf build/turingchain* 160 @rm -rf build/relayd* 161 @rm -rf build/*.log 162 @rm -rf build/logs 163 @rm -rf build/autotest/autotest 164 @rm -rf build/ci 165 @go clean 166 167 proto:protobuf 168 169 protobuf: ## Generate protbuf file of types package 170 @cd types/proto && ./create_protobuf.sh && cd ../.. 171 @find ./system/dapp ./system/store/mavl -maxdepth 2 -type d -name proto -exec make -C {} \; 172 173 depends: ## Generate depends file of types package 174 @find ./system/dapp -maxdepth 2 -type d -name cmd -exec make -C {} OUT="$(MKDIR)build/ci" FLAG= \; 175 176 help: ## Display this help screen 177 @printf "Help doc:\nUsage: make [command]\n" 178 @printf "[command]\n" 179 @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 180 181 cleandata: 182 rm -rf build/datadir/addrbook 183 rm -rf build/datadir/blockchain.db 184 rm -rf build/datadir/mavltree 185 rm -rf build/turingchain.log 186 187 fmt_go: fmt_shell ## go fmt 188 @go fmt ./... 189 @find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w 190 191 192 .PHONY: checkgofmt 193 checkgofmt: ## get all go files and run go fmt on them 194 @files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s); if [ -n "$$files" ]; then \ 195 echo "Error: 'make fmt' needs to be run on:"; \ 196 find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s ;\ 197 exit 1; \ 198 fi; 199 @files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w); if [ -n "$$files" ]; then \ 200 echo "Error: 'make fmt' needs to be run on:"; \ 201 find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w ;\ 202 exit 1; \ 203 fi; 204 205 .PHONY: mock 206 mock: 207 @cd blockchain/ && mockery -name=CommonStore && mv mocks/CommonStore.go mocks/commonstore.go && cd - 208 @cd blockchain/ && mockery -name=SequenceStore && mv mocks/SequenceStore.go mocks/sequence_store.go && cd - 209 @cd blockchain/ && mockery -name=PostService && mv mocks/PostService.go mocks/post_service.go && cd - 210 @cd client && mockery -name=QueueProtocolAPI && mv mocks/QueueProtocolAPI.go mocks/api.go && cd - 211 @cd common/db && mockery -name=KV && mv mocks/KV.go mocks/kv.go && cd - 212 @cd common/db && mockery -name=KVDB && mv mocks/KVDB.go mocks/kvdb.go && cd - 213 @cd common/db && mockery -name=DB && mv mocks/DB.go mocks/db.go && cd - 214 @cd queue && mockery -name=Client && mv mocks/Client.go mocks/client.go && cd - 215 @cd types/ && mockery -name=TuringchainClient && mv mocks/TuringchainClient.go mocks/turingchainclient.go && cd - 216 217 218 219 .PHONY: auto_ci_before auto_ci_after auto_ci 220 auto_ci_before: clean fmt protobuf mock 221 @echo "auto_ci" 222 @go version 223 @protoc --version 224 @mockery -version 225 @docker version 226 @docker-compose version 227 @git version 228 @git status 229 230 .PHONY: auto_ci_after 231 auto_ci_after: clean fmt protobuf mock 232 @git add *.go *.sh *.proto 233 @git status 234 @files=$$(git status -suno);if [ -n "$$files" ]; then \ 235 git add *.go *.sh *.proto; \ 236 git status; \ 237 git commit -m "auto ci [ci-skip]"; \ 238 git push origin HEAD:$(branch); \ 239 fi; 240 241 .PHONY: auto_ci 242 auto_fmt := find . -name '*.go' -not -path './vendor/*' | xargs goimports -l -w 243 auto_ci: clean fmt_proto fmt_shell protobuf mock 244 @-find . -name '*.go' -not -path './vendor/*' | xargs gofmt -l -w -s 245 @-${auto_fmt} 246 @-find . -name '*.go' -not -path './vendor/*' | xargs gofmt -l -w -s 247 @${auto_fmt} 248 @git status 249 @files=$$(git status -suno);if [ -n "$$files" ]; then \ 250 git add *.go *.sh *.proto; \ 251 git status; \ 252 git commit -a -m "auto ci"; \ 253 git push origin HEAD:$(branch); \ 254 exit 1; \ 255 fi; 256 257 webhook_auto_ci: clean fmt_proto fmt_shell protobuf mock 258 @-find . -name '*.go' -not -path './vendor/*' | xargs gofmt -l -w -s 259 @-${auto_fmt} 260 @-find . -name '*.go' -not -path './vendor/*' | xargs gofmt -l -w -s 261 @${auto_fmt} 262 @git status 263 @files=$$(git status -suno);if [ -n "$$files" ]; then \ 264 git status; \ 265 git commit -a -m "auto ci"; \ 266 git push origin ${b}; \ 267 exit 0; \ 268 fi; 269 270 addupstream: 271 git remote add upstream https://github.com/turingchain2020/turingchain.git 272 git remote -v 273 274 sync: 275 git fetch upstream 276 git checkout master 277 git merge upstream/master 278 git push origin master 279 280 branch: 281 make sync 282 git checkout -b ${b} 283 284 push: 285 @if [ -n "$$m" ]; then \ 286 git commit -a -m "${m}" ; \ 287 fi; 288 make sync 289 git checkout ${b} 290 git merge master 291 git push origin ${b} 292 293 pull: 294 @remotelist=$$(git remote | grep ${name});if [ -z $$remotelist ]; then \ 295 echo ${remotelist}; \ 296 git remote add ${name} https://github.com/${name}/turingchain.git ; \ 297 fi; 298 git fetch ${name} 299 git checkout ${name}/${b} 300 git checkout -b ${name}-${b} 301 pullsync: 302 git fetch ${name} 303 git checkout ${name}-${b} 304 git merge ${name}/${b} 305 pullpush: 306 @if [ -n "$$m" ]; then \ 307 git commit -a -m "${m}" ; \ 308 fi; 309 make pullsync 310 git push ${name} ${name}-${b}:${b} 311 312 webhook: 313 git checkout ${b} 314 make webhook_auto_ci name=${name} b=${b}