Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 1 | export GO15VENDOREXPERIMENT=1 |
| 2 | |
| 3 | BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem |
| 4 | PKGS ?= $(shell glide novendor) |
| 5 | # Many Go tools take file globs or directories as arguments instead of packages. |
| 6 | PKG_FILES ?= *.go zapcore benchmarks buffer zapgrpc zaptest zaptest/observer internal/bufferpool internal/exit internal/color internal/ztest |
| 7 | |
| 8 | # The linting tools evolve with each Go version, so run them only on the latest |
| 9 | # stable release. |
| 10 | GO_VERSION := $(shell go version | cut -d " " -f 3) |
| 11 | GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION))) |
Scott Baker | f579f13 | 2019-10-24 14:31:41 -0700 | [diff] [blame] | 12 | LINTABLE_MINOR_VERSIONS := 12 |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 13 | ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),) |
| 14 | SHOULD_LINT := true |
| 15 | endif |
| 16 | |
| 17 | |
| 18 | .PHONY: all |
| 19 | all: lint test |
| 20 | |
| 21 | .PHONY: dependencies |
| 22 | dependencies: |
| 23 | @echo "Installing Glide and locked dependencies..." |
| 24 | glide --version || go get -u -f github.com/Masterminds/glide |
| 25 | glide install |
| 26 | @echo "Installing test dependencies..." |
| 27 | go install ./vendor/github.com/axw/gocov/gocov |
| 28 | go install ./vendor/github.com/mattn/goveralls |
| 29 | ifdef SHOULD_LINT |
| 30 | @echo "Installing golint..." |
| 31 | go install ./vendor/github.com/golang/lint/golint |
| 32 | else |
| 33 | @echo "Not installing golint, since we don't expect to lint on" $(GO_VERSION) |
| 34 | endif |
| 35 | |
| 36 | # Disable printf-like invocation checking due to testify.assert.Error() |
| 37 | VET_RULES := -printf=false |
| 38 | |
| 39 | .PHONY: lint |
| 40 | lint: |
| 41 | ifdef SHOULD_LINT |
| 42 | @rm -rf lint.log |
| 43 | @echo "Checking formatting..." |
| 44 | @gofmt -d -s $(PKG_FILES) 2>&1 | tee lint.log |
| 45 | @echo "Installing test dependencies for vet..." |
| 46 | @go test -i $(PKGS) |
| 47 | @echo "Checking vet..." |
Scott Baker | f579f13 | 2019-10-24 14:31:41 -0700 | [diff] [blame] | 48 | @go vet $(VET_RULES) $(PKGS) 2>&1 | tee -a lint.log |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 49 | @echo "Checking lint..." |
| 50 | @$(foreach dir,$(PKGS),golint $(dir) 2>&1 | tee -a lint.log;) |
| 51 | @echo "Checking for unresolved FIXMEs..." |
| 52 | @git grep -i fixme | grep -v -e vendor -e Makefile | tee -a lint.log |
| 53 | @echo "Checking for license headers..." |
| 54 | @./check_license.sh | tee -a lint.log |
| 55 | @[ ! -s lint.log ] |
| 56 | else |
| 57 | @echo "Skipping linters on" $(GO_VERSION) |
| 58 | endif |
| 59 | |
| 60 | .PHONY: test |
| 61 | test: |
| 62 | go test -race $(PKGS) |
| 63 | |
| 64 | .PHONY: cover |
| 65 | cover: |
| 66 | ./scripts/cover.sh $(PKGS) |
| 67 | |
| 68 | .PHONY: bench |
| 69 | BENCH ?= . |
| 70 | bench: |
| 71 | @$(foreach pkg,$(PKGS),go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) $(pkg);) |
| 72 | |
| 73 | .PHONY: updatereadme |
| 74 | updatereadme: |
| 75 | rm -f README.md |
| 76 | cat .readme.tmpl | go run internal/readme/readme.go > README.md |