github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/Makefile (about) 1 # ---------------------------------------------------------- 2 # REQUIREMENTS 3 4 # - Go 1.12 5 # - Make 6 # - jq 7 # - find 8 # - bash 9 # - protoc (for rebuilding protobuf files) 10 11 # ---------------------------------------------------------- 12 13 SHELL := /usr/bin/env bash 14 REPO := $(shell pwd) 15 16 # Our own Go files containing the compiled bytecode of solidity files as a constant 17 18 export CI_IMAGE=hyperledger/burrow:ci-3 19 20 VERSION := $(shell scripts/version.sh) 21 # Gets implicit default GOPATH if not set 22 GOPATH?=$(shell go env GOPATH) 23 BIN_PATH?=$(GOPATH)/bin 24 HELM_PATH?=helm/package 25 HELM_PACKAGE=$(HELM_PATH)/burrow-$(VERSION).tgz 26 ARCH?=linux-amd64 27 PID_DIR=.pid 28 29 export GO111MODULE=on 30 31 ### Formatting, linting and vetting 32 33 # check the code for style standards; currently enforces go formatting. 34 # display output first, then check for success 35 .PHONY: check 36 check: 37 @echo "Checking code for formatting style compliance." 38 @gofmt -l -d $(shell go list -f "{{.Dir}}" ./...) 39 @gofmt -l $(shell go list -f "{{.Dir}}" ./...) | read && echo && echo "Your marmot has found a problem with the formatting style of the code." 1>&2 && exit 1 || true 40 41 # Just fix it 42 .PHONY: fix 43 fix: 44 @goimports -l -w $(shell go list -f "{{.Dir}}" ./...) 45 46 # fmt runs gofmt -w on the code, modifying any files that do not match 47 # the style guide. 48 .PHONY: fmt 49 fmt: 50 @echo "Correcting any formatting style corrections." 51 @gofmt -l -w $(shell go list -f "{{.Dir}}" ./...) 52 53 # lint installs golint and prints recommendations for coding style. 54 lint: 55 @echo "Running lint checks." 56 go get -u github.com/golang/lint/golint 57 @for file in $(shell go list -f "{{.Dir}}" ./...); do \ 58 echo; \ 59 golint --set_exit_status $${file}; \ 60 done 61 62 # vet runs extended compilation checks to find recommendations for 63 # suspicious code constructs. 64 .PHONY: vet 65 vet: 66 @echo "Running go vet." 67 @go vet $(shell go list ./... ) 68 69 # run the megacheck tool for code compliance 70 .PHONY: megacheck 71 megacheck: 72 @go get honnef.co/go/tools/cmd/megacheck 73 @for pkg in $(shell go list ./... ); do megacheck "$$pkg"; done 74 75 # Protobuffing 76 77 BURROW_TS_PATH = ./js 78 PROTO_GEN_TS_PATH = ${BURROW_TS_PATH}/proto 79 NODE_BIN = ${BURROW_TS_PATH}/node_modules/.bin 80 81 # To access Tendermint bundled protobuf files from go module cache 82 TENDERMINT_MOD?=github.com/tendermint/tendermint 83 TENDERMINT_VERSION?=$(shell go list -m -f '{{ .Version }}' $(TENDERMINT_MOD)) 84 TENDERMINT_SRC?=$(shell go env GOMODCACHE)/$(TENDERMINT_MOD)@$(TENDERMINT_VERSION) 85 TENDERMINT_PROTO?=$(TENDERMINT_SRC)/proto 86 87 PROTO_FILES = $(shell find . $(TENDERMINT_PROTO) -path $(BURROW_TS_PATH) -prune -o -path '*/node_modules' -prune -o -type f -name '*.proto' -print) 88 PROTO_GO_FILES = $(patsubst %.proto, %.pb.go, $(PROTO_FILES)) 89 PROTO_GO_FILES_REAL = $(shell find . -type f -name '*.pb.go' -print) 90 PROTO_TS_FILES = $(patsubst %.proto, %.pb.ts, $(PROTO_FILES)) 91 92 .PHONY: protobuf 93 protobuf: $(PROTO_GO_FILES) $(PROTO_TS_FILES) fix 94 95 # Implicit compile rule for GRPC/proto files (note since pb.go files no longer generated 96 # in same directory as proto file this just regenerates everything 97 %.pb.go: %.proto 98 protoc -I ./protobuf -I $(TENDERMINT_PROTO) $< --gogo_out=${GOPATH}/src --go-grpc_out=${GOPATH}/src 99 100 # Note: we are not actually building any of the target .pb.ts files here, but nevermind 101 # Using this: https://github.com/agreatfool/grpc_tools_node_protoc_ts 102 %.pb.ts: %.proto 103 mkdir -p $(PROTO_GEN_TS_PATH) 104 $(NODE_BIN)/grpc_tools_node_protoc -I protobuf -I $(TENDERMINT_PROTO) \ 105 --plugin="protoc-gen-ts=$(NODE_BIN)/protoc-gen-ts" \ 106 --js_out="import_style=commonjs,binary:${PROTO_GEN_TS_PATH}" \ 107 --ts_out="grpc_js:${PROTO_GEN_TS_PATH}" \ 108 --grpc_out="grpc_js:${PROTO_GEN_TS_PATH}" \ 109 $< 110 111 .PHONY: protobuf_deps 112 protobuf_deps: 113 @go get -u github.com/gogo/protobuf/protoc-gen-gogo 114 @cd ${BURROW_TS_PATH} && yarn install --only=dev 115 116 .PHONY: clean_protobuf 117 clean_protobuf: 118 @rm -f $(PROTO_GO_FILES_REAL) 119 120 ### PEG query grammar 121 122 # This allows us to filter tagged objects with things like (EventID = 'foo' OR Height > 10) AND EventName CONTAINS 'frog' 123 124 .PHONY: peg_deps 125 peg_deps: 126 go get -u github.com/pointlander/peg 127 128 # regenerate the parser 129 .PHONY: peg 130 peg: 131 peg event/query/query.peg 132 133 ### Building github.com/hyperledger/burrow 134 135 # Output commit_hash but only if we have the git repo (e.g. not in docker build 136 .PHONY: commit_hash 137 commit_hash: 138 @git status &> /dev/null && scripts/commit_hash.sh > commit_hash.txt || true 139 140 # build all targets in github.com/hyperledger/burrow 141 .PHONY: build 142 build: check build_burrow build_burrow_debug 143 144 # build all targets in github.com/hyperledger/burrow with checks for race conditions 145 .PHONY: build_race 146 build_race: check build_race_db 147 148 # build burrow and vent 149 .PHONY: build_burrow 150 build_burrow: commit_hash 151 go build $(BURROW_BUILD_FLAGS) -ldflags "-extldflags '-static' \ 152 -X github.com/hyperledger/burrow/project.commit=$(shell cat commit_hash.txt) \ 153 -X github.com/hyperledger/burrow/project.date=$(shell date '+%Y-%m-%d')" \ 154 -o ${REPO}/bin/burrow$(BURROW_BUILD_SUFFIX) ./cmd/burrow 155 156 # With the sqlite tag - enabling Vent sqlite adapter support, but building a CGO binary 157 .PHONY: build_burrow_sqlite 158 build_burrow_sqlite: export BURROW_BUILD_SUFFIX=-vent-sqlite 159 build_burrow_sqlite: export BURROW_BUILD_FLAGS=-tags sqlite 160 build_burrow_sqlite: 161 $(MAKE) build_burrow 162 163 # Builds a binary suitable for delve line-by-line debugging through CGO with optimisations (-N) and inling (-l) disabled 164 .PHONY: build_burrow_debug 165 build_burrow_debug: export BURROW_BUILD_SUFFIX=-debug 166 build_burrow_debug: export BURROW_BUILD_FLAGS=-gcflags "all=-N -l" 167 build_burrow_debug: 168 $(MAKE) build_burrow 169 170 .PHONY: install 171 install: build_burrow 172 mkdir -p ${BIN_PATH} 173 install ${REPO}/bin/burrow ${BIN_PATH}/burrow 174 175 # build burrow with checks for race conditions 176 .PHONY: build_race_db 177 build_race_db: 178 go build -race -o ${REPO}/bin/burrow ./cmd/burrow 179 180 ### Build docker images for github.com/hyperledger/burrow 181 182 # build docker image for burrow 183 .PHONY: docker_build 184 docker_build: check commit_hash 185 @scripts/build_tool.sh 186 187 ### Testing github.com/hyperledger/burrow 188 189 # Solidity fixtures 190 .PHONY: solidity 191 solidity: $(patsubst %.sol, %.sol.go, $(wildcard ./execution/solidity/*.sol)) build_burrow 192 193 %.sol.go: %.sol 194 @burrow compile $^ 195 196 # Solang fixtures 197 .PHONY: solang 198 solang: $(patsubst %.solang, %.solang.go, $(wildcard ./execution/solidity/*.solang) $(wildcard ./execution/wasm/*.solang)) build_burrow 199 200 %.solang.go: %.solang 201 @burrow compile --wasm $^ 202 203 # node/js 204 .PHONY: yarn_install 205 yarn_install: 206 @cd ${BURROW_TS_PATH} && yarn install 207 208 # Test 209 210 .PHONY: test_js 211 test_js: 212 @cd ${BURROW_TS_PATH} && yarn test 213 214 .PHONY: publish_js 215 publish_js: 216 yarn --cwd js install 217 yarn --cwd js build 218 yarn --cwd js publish --access public --non-interactive --no-git-tag-version --new-version $(shell ./scripts/local_version.sh) 219 220 .PHONY: clean_js 221 clean_js: 222 find js -name '*.abi.ts' -exec rm '{}' ';' -print 223 224 .PHONY: test 225 test: check bin/solc bin/solang 226 @tests/scripts/bin_wrapper.sh go test ./... ${GO_TEST_ARGS} 227 228 .PHONY: test_keys 229 test_keys: 230 burrow_bin="${REPO}/bin/burrow" tests/keys_server/test.sh 231 232 .PHONY: test_truffle 233 test_truffle: 234 burrow_bin="${REPO}/bin/burrow" tests/web3/truffle.sh 235 236 .PHONY: test_integration_vent 237 test_integration_vent: 238 # Include sqlite adapter with tests - will build with CGO but that's probably fine 239 go test -count=1 -v -tags 'integration sqlite' ./vent/... 240 241 .PHONY: test_integration_vent_complete 242 test_integration_vent_complete: 243 docker-compose run burrow make test_integration_vent test_integration_vent_ethereum 244 245 .PHONY: test_integration_vent_ethereum 246 test_integration_vent_ethereum: start_ganache 247 go test -count=1 -v -tags 'integration !sqlite ethereum' ./vent/... 248 $(MAKE) stop_ganache 249 250 .PHONY: test_integration_ethereum 251 test_integration_ethereum: start_ganache 252 go test -v -tags 'integration ethereum' ./rpc/... 253 $(MAKE) stop_ganache 254 255 $(PID_DIR)/ganache.pid: 256 mkdir -p $(PID_DIR) 257 yarn --cwd vent/test/eth install 258 @echo "Starting ganache in background..." 259 { yarn --cwd vent/test/eth ganache & echo $$! > $@; } 260 @sleep 3 261 @echo "Ganache process started (pid at $@)" 262 263 .PHONY: start_ganache 264 start_ganache: $(PID_DIR)/ganache.pid 265 266 .PHONY: stop_ganache 267 stop_ganache: $(PID_DIR)/ganache.pid 268 @kill $(shell cat $<) && echo "Ganache process stopped." && rm $< || rm $< 269 270 # For local debug 271 .PHONY: postgres 272 postgres: 273 docker run -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres:11-alpine 274 275 .PHONY: test_restore 276 test_restore: 277 @tests/scripts/bin_wrapper.sh tests/dump/test.sh 278 279 # Go will attempt to run separate packages in parallel 280 281 .PHONY: test_integration 282 test_integration: 283 @go test -count=1 -v -tags integration ./integration/... 284 285 .PHONY: test_integration_all 286 test_integration_all: test_keys test_deploy test_integration_vent_complete test_restore test_truffle test_integration 287 288 .PHONY: test_integration_all_no_postgres 289 test_integration_all_no_postgres: test_keys test_deploy test_integration_vent test_restore test_truffle test_integration 290 291 .PHONY: test_deploy 292 test_deploy: 293 @tests/scripts/bin_wrapper.sh tests/deploy.sh 294 295 bin/solc: ./tests/scripts/deps/solc.sh 296 @mkdir -p bin 297 @tests/scripts/deps/solc.sh bin/solc 298 @touch bin/solc 299 300 bin/solang: ./tests/scripts/deps/solang.sh 301 @mkdir -p bin 302 @tests/scripts/deps/solang.sh bin/solang 303 @touch bin/solang 304 305 # test burrow with checks for race conditions 306 .PHONY: test_race 307 test_race: build_race 308 @go test -race $(shell go list ./... ) 309 310 ### Clean up 311 312 # clean removes the target folder containing build artefacts 313 .PHONY: clean 314 clean: 315 -rm -r ./bin 316 317 ### Release and versioning 318 319 # Print version 320 .PHONY: version 321 version: 322 @echo $(VERSION) 323 324 # Generate full changelog of all release notes 325 CHANGELOG.md: project/history.go project/cmd/changelog/main.go 326 @go run ./project/cmd/changelog/main.go > CHANGELOG.md 327 328 # Generated release note for this version 329 NOTES.md: project/history.go project/cmd/notes/main.go 330 @go run ./project/cmd/notes/main.go > NOTES.md 331 332 .PHONY: docs 333 docs: CHANGELOG.md NOTES.md 334 335 # Tag the current HEAD commit with the current release defined in 336 # ./project/history.go 337 .PHONY: tag_release 338 tag_release: test check docs build 339 @scripts/tag_release.sh 340 341 .PHONY: build_ci_image 342 build_ci_image: 343 docker build -t ${CI_IMAGE} -f ./.github/Dockerfile . 344 345 .PHONY: push_ci_image 346 push_ci_image: build_ci_image 347 docker push ${CI_IMAGE} 348 349 .PHONY: ready_for_pull_request 350 ready_for_pull_request: docs fix 351 352 .PHONY: staticcheck 353 staticcheck: 354 go get honnef.co/go/tools/cmd/staticcheck 355 staticcheck ./... 356 357 # Note --set flag currently needs helm 3 version < 3.0.3 https://github.com/helm/helm/issues/3141 - but hopefully they will reintroduce support 358 bin/helm: 359 @echo Downloading helm... 360 mkdir -p bin 361 curl https://get.helm.sh/helm-v3.0.2-$(ARCH).tar.gz | tar xvzO $(ARCH)/helm > bin/helm && chmod +x bin/helm 362 363 364 // TODO: reinstate 365 366 .PHONY: helm_deps 367 helm_deps: bin/helm 368 @bin/helm repo add --username "$(HELM_USERNAME)" --password "$(HELM_PASSWORD)" chartmuseum $(HELM_URL) 369 370 .PHONY: helm_test 371 helm_test: bin/helm 372 bin/helm dep up helm/burrow 373 bin/helm lint helm/burrow 374 375 helm_package: $(HELM_PACKAGE) 376 377 $(HELM_PACKAGE): helm_test bin/helm 378 bin/helm package helm/burrow \ 379 --version "$(VERSION)" \ 380 --app-version "$(VERSION)" \ 381 --set "image.tag=$(VERSION)" \ 382 --dependency-update \ 383 --destination helm/package 384 385 .PHONY: helm_push 386 helm_push: helm_package 387 @echo pushing helm chart... 388 @curl -u ${CM_USERNAME}:${CM_PASSWORD} \ 389 --data-binary "@$(HELM_PACKAGE)" $(CM_URL)/api/charts