github.com/eris-ltd/erisdb@v0.25.0/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 := /bin/bash 14 REPO := $(shell pwd) 15 GOFILES_NOVENDOR := $(shell go list -f "{{.Dir}}" ./...) 16 PACKAGES_NOVENDOR := $(shell go list ./...) 17 18 # Protobuf generated go files 19 PROTO_FILES = $(shell find . -path ./vendor -prune -o -path ./.gopath_bos -prune -o -type f -name '*.proto' -print) 20 PROTO_GO_FILES = $(patsubst %.proto, %.pb.go, $(PROTO_FILES)) 21 PROTO_GO_FILES_REAL = $(shell find . -path ./vendor -prune -o -type f -name '*.pb.go' -print) 22 23 # Our own Go files containing the compiled bytecode of solidity files as a constant 24 SOLIDITY_FILES = $(shell find . -path ./vendor -prune -o -path ./tests -prune -o -type f -name '*.sol' -print) 25 SOLIDITY_GO_FILES = $(patsubst %.sol, %.sol.go, $(SOLIDITY_FILES)) 26 27 CI_IMAGE="hyperledger/burrow:ci" 28 29 ### Formatting, linting and vetting 30 31 # check the code for style standards; currently enforces go formatting. 32 # display output first, then check for success 33 .PHONY: check 34 check: 35 @echo "Checking code for formatting style compliance." 36 @gofmt -l -d ${GOFILES_NOVENDOR} 37 @gofmt -l ${GOFILES_NOVENDOR} | read && echo && echo "Your marmot has found a problem with the formatting style of the code." 1>&2 && exit 1 || true 38 39 # Just fix it 40 .PHONY: fix 41 fix: 42 @goimports -l -w ${GOFILES_NOVENDOR} 43 44 # fmt runs gofmt -w on the code, modifying any files that do not match 45 # the style guide. 46 .PHONY: fmt 47 fmt: 48 @echo "Correcting any formatting style corrections." 49 @gofmt -l -w ${GOFILES_NOVENDOR} 50 51 # lint installs golint and prints recommendations for coding style. 52 lint: 53 @echo "Running lint checks." 54 go get -u github.com/golang/lint/golint 55 @for file in $(GOFILES_NOVENDOR); do \ 56 echo; \ 57 golint --set_exit_status $${file}; \ 58 done 59 60 # vet runs extended compilation checks to find recommendations for 61 # suspicious code constructs. 62 .PHONY: vet 63 vet: 64 @echo "Running go vet." 65 @go vet ${PACKAGES_NOVENDOR} 66 67 # run the megacheck tool for code compliance 68 .PHONY: megacheck 69 megacheck: 70 @go get honnef.co/go/tools/cmd/megacheck 71 @for pkg in ${PACKAGES_NOVENDOR}; do megacheck "$$pkg"; done 72 73 # Protobuffing 74 .PHONY: protobuf_deps 75 protobuf_deps: 76 @go get -u github.com/gogo/protobuf/protoc-gen-gogo 77 # @go get -u github.com/golang/protobuf/protoc-gen-go 78 79 # Implicit compile rule for GRPC/proto files (note since pb.go files no longer generated 80 # in same directory as proto file this just regenerates everything 81 %.pb.go: %.proto 82 cp -a vendor/github.com/gogo/protobuf/gogoproto/gogo.proto protobuf/github.com/gogo/protobuf/gogoproto/gogo.proto 83 protoc -I protobuf -I vendor $< --gogo_out=plugins=grpc:${GOPATH}/src 84 85 .PHONY: protobuf 86 protobuf: $(PROTO_GO_FILES) 87 88 .PHONY: clean_protobuf 89 clean_protobuf: 90 @rm -f $(PROTO_GO_FILES_REAL) 91 92 ### Dependency management for github.com/hyperledger/burrow 93 # erase vendor wipes the full vendor directory 94 .PHONY: erase_vendor 95 erase_vendor: 96 rm -rf ${REPO}/vendor/ 97 98 # install vendor uses dep to install vendored dependencies 99 .PHONY: reinstall_vendor 100 reinstall_vendor: erase_vendor 101 @go get -u github.com/golang/dep/cmd/dep 102 @dep ensure -v 103 104 # delete the vendor directy and pull back using dep lock and constraints file 105 # will exit with an error if the working directory is not clean (any missing files or new 106 # untracked ones) 107 .PHONY: ensure_vendor protobuf 108 ensure_vendor: reinstall_vendor 109 @scripts/is_checkout_dirty.sh 110 111 ### Building github.com/hyperledger/burrow 112 113 # Output commit_hash but only if we have the git repo (e.g. not in docker build 114 .PHONY: commit_hash 115 commit_hash: 116 @git status &> /dev/null && scripts/commit_hash.sh > commit_hash.txt || true 117 118 # build all targets in github.com/hyperledger/burrow 119 .PHONY: build 120 build: check build_burrow 121 122 # build all targets in github.com/hyperledger/burrow with checks for race conditions 123 .PHONY: build_race 124 build_race: check build_race_db 125 126 # build burrow and vent 127 .PHONY: build_burrow 128 build_burrow: commit_hash 129 go build -ldflags "-extldflags '-static' \ 130 -X github.com/hyperledger/burrow/project.commit=$(shell cat commit_hash.txt) \ 131 -X github.com/hyperledger/burrow/project.date=$(shell date '+%Y-%m-%d')" \ 132 -o ${REPO}/bin/burrow ./cmd/burrow 133 134 # With the sqlite tag - enabling Vent sqlite adapter support, but building a CGO binary 135 .PHONY: build_burrow_sqlite 136 build_burrow_sqlite: commit_hash 137 go build -tags sqlite \ 138 -ldflags "-extldflags '-static' \ 139 -X github.com/hyperledger/burrow/project.commit=$(shell cat commit_hash.txt) \ 140 -X github.com/hyperledger/burrow/project.date=$(shell date -I)" \ 141 -o ${REPO}/bin/burrow-vent-sqlite ./cmd/burrow 142 143 .PHONY: install_burrow 144 install_burrow: build_burrow 145 cp ${REPO}/bin/burrow ${GOPATH}/bin/burrow 146 147 # build burrow with checks for race conditions 148 .PHONY: build_race_db 149 build_race_db: 150 go build -race -o ${REPO}/bin/burrow ./cmd/burrow 151 152 ### Build docker images for github.com/hyperledger/burrow 153 154 # build docker image for burrow 155 .PHONY: docker_build 156 docker_build: check commit_hash 157 @scripts/build_tool.sh 158 159 ### Testing github.com/hyperledger/burrow 160 161 # Solidity fixtures 162 %.sol.go: %.sol 163 @go run ./deploy/compile/solgo/main.go $^ 164 165 .PHONY: solidity 166 solidity: $(SOLIDITY_GO_FILES) 167 168 # Test 169 170 .PHONY: test 171 test: check bin/solc 172 @tests/scripts/bin_wrapper.sh go test ./... ${GOPACKAGES_NOVENDOR} 173 174 .PHONY: test_keys 175 test_keys: build_burrow 176 burrow_bin="${REPO}/bin/burrow" tests/keys_server/test.sh 177 178 .PHONY: test_integration_vent 179 test_integration_vent: 180 # Include sqlite adapter with tests - will build with CGO but that's probably fine 181 go test -v -tags 'integration sqlite' ./vent/... 182 183 .PHONY: test_integration_vent_postgres 184 test_integration_vent_postgres: 185 docker-compose run burrow make test_integration_vent 186 187 .PHONY: test_restore 188 test_restore: build_burrow bin/solc 189 @tests/scripts/bin_wrapper.sh tests/dump/test.sh 190 191 # Go will attempt to run separate packages in parallel 192 .PHONY: test_integration 193 test_integration: test_keys test_deploy test_integration_vent_postgres test_restore 194 @go test -v -tags integration ./integration/... 195 196 .PHONY: test_integration_no_postgres 197 test_integration_no_postgres: test_keys test_deploy test_integration_vent test_restore 198 @go test -v -tags integration ./integration/... 199 200 .PHONY: test_deploy 201 test_deploy: bin/solc build_burrow 202 @tests/scripts/bin_wrapper.sh tests/deploy.sh 203 204 bin/solc: ./tests/scripts/deps/solc.sh 205 @mkdir -p bin 206 @tests/scripts/deps/solc.sh bin/solc 207 @touch bin/solc 208 209 # test burrow with checks for race conditions 210 .PHONY: test_race 211 test_race: build_race 212 @go test -race ${PACKAGES_NOVENDOR} 213 214 ### Clean up 215 216 # clean removes the target folder containing build artefacts 217 .PHONY: clean 218 clean: 219 -rm -r ./bin 220 221 ### Release and versioning 222 223 # Print version 224 .PHONY: version 225 version: 226 @go run ./project/cmd/version/main.go 227 228 # Generate full changelog of all release notes 229 CHANGELOG.md: project/history.go project/cmd/changelog/main.go 230 @go run ./project/cmd/changelog/main.go > CHANGELOG.md 231 232 # Generated release note for this version 233 NOTES.md: project/history.go project/cmd/notes/main.go 234 @go run ./project/cmd/notes/main.go > NOTES.md 235 236 .PHONY: docs 237 docs: CHANGELOG.md NOTES.md 238 239 # Tag the current HEAD commit with the current release defined in 240 # ./release/release.go 241 .PHONY: tag_release 242 tag_release: test check CHANGELOG.md NOTES.md build 243 @scripts/tag_release.sh 244 245 .PHONY: release 246 release: docs check test docker_build 247 @scripts/is_checkout_dirty.sh || (echo "checkout is dirty so not releasing!" && exit 1) 248 @scripts/release.sh 249 250 .PHONY: release_dev 251 release_dev: test docker_build 252 @scripts/release_dev.sh 253 254 .PHONY: build_ci_image 255 build_ci_image: 256 docker build -t ${CI_IMAGE} -f ./.circleci/Dockerfile . 257 258 .PHONY: push_ci_image 259 push_ci_image: build_ci_image 260 docker push ${CI_IMAGE} 261 262 .PHONY: ready_for_pull_request 263 ready_for_pull_request: ensure_vendor docs fix