blob: 073e9aa910a8eb9e7ed84fa6eab34ef558d8a969 [file] [log] [blame]
Prince Pereirac1c21d62021-04-22 08:38:15 +00001export GO15VENDOREXPERIMENT=1
2
3BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
4PKGS ?= $(shell glide novendor)
5# Many Go tools take file globs or directories as arguments instead of packages.
6PKG_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.
10GO_VERSION := $(shell go version | cut -d " " -f 3)
11GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION)))
12LINTABLE_MINOR_VERSIONS := 12
13ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),)
14SHOULD_LINT := true
15endif
16
17
18.PHONY: all
19all: lint test
20
21.PHONY: dependencies
22dependencies:
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
29ifdef SHOULD_LINT
30 @echo "Installing golint..."
31 go install ./vendor/github.com/golang/lint/golint
32else
33 @echo "Not installing golint, since we don't expect to lint on" $(GO_VERSION)
34endif
35
36# Disable printf-like invocation checking due to testify.assert.Error()
37VET_RULES := -printf=false
38
39.PHONY: lint
40lint:
41ifdef 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..."
48 @go vet $(VET_RULES) $(PKGS) 2>&1 | tee -a lint.log
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 ]
56else
57 @echo "Skipping linters on" $(GO_VERSION)
58endif
59
60.PHONY: test
61test:
62 go test -race $(PKGS)
63
64.PHONY: cover
65cover:
66 ./scripts/cover.sh $(PKGS)
67
68.PHONY: bench
69BENCH ?= .
70bench:
71 @$(foreach pkg,$(PKGS),go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) $(pkg);)
72
73.PHONY: updatereadme
74updatereadme:
75 rm -f README.md
76 cat .readme.tmpl | go run internal/readme/readme.go > README.md