blob: 9b1bc3b0e1d891f34507d5454a00642942c66561 [file] [log] [blame]
David K. Bainbridge06631892021-08-19 13:07:00 +00001export GOBIN ?= $(shell pwd)/bin
Matteo Scandoloa4285862020-12-01 18:10:10 -08002
David K. Bainbridge06631892021-08-19 13:07:00 +00003GOLINT = $(GOBIN)/golint
4STATICCHECK = $(GOBIN)/staticcheck
Matteo Scandoloa4285862020-12-01 18:10:10 -08005BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
David K. Bainbridge06631892021-08-19 13:07:00 +00006
7# Directories containing independent Go modules.
8#
9# We track coverage only for the main module.
10MODULE_DIRS = . ./benchmarks ./zapgrpc/internal/test
11
Matteo Scandoloa4285862020-12-01 18:10:10 -080012# Many Go tools take file globs or directories as arguments instead of packages.
David K. Bainbridge06631892021-08-19 13:07:00 +000013GO_FILES := $(shell \
14 find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
15 -o -name '*.go' -print | cut -b3-)
Matteo Scandoloa4285862020-12-01 18:10:10 -080016
17.PHONY: all
18all: lint test
19
Matteo Scandoloa4285862020-12-01 18:10:10 -080020.PHONY: lint
David K. Bainbridge06631892021-08-19 13:07:00 +000021lint: $(GOLINT) $(STATICCHECK)
Matteo Scandoloa4285862020-12-01 18:10:10 -080022 @rm -rf lint.log
23 @echo "Checking formatting..."
David K. Bainbridge06631892021-08-19 13:07:00 +000024 @gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
Matteo Scandoloa4285862020-12-01 18:10:10 -080025 @echo "Checking vet..."
David K. Bainbridge06631892021-08-19 13:07:00 +000026 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
Matteo Scandoloa4285862020-12-01 18:10:10 -080027 @echo "Checking lint..."
David K. Bainbridge06631892021-08-19 13:07:00 +000028 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(GOLINT) ./... 2>&1) &&) true | tee -a lint.log
29 @echo "Checking staticcheck..."
30 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(STATICCHECK) ./... 2>&1) &&) true | tee -a lint.log
Matteo Scandoloa4285862020-12-01 18:10:10 -080031 @echo "Checking for unresolved FIXMEs..."
David K. Bainbridge06631892021-08-19 13:07:00 +000032 @git grep -i fixme | grep -v -e Makefile | tee -a lint.log
Matteo Scandoloa4285862020-12-01 18:10:10 -080033 @echo "Checking for license headers..."
David K. Bainbridge06631892021-08-19 13:07:00 +000034 @./checklicense.sh | tee -a lint.log
Matteo Scandoloa4285862020-12-01 18:10:10 -080035 @[ ! -s lint.log ]
David K. Bainbridge06631892021-08-19 13:07:00 +000036 @echo "Checking 'go mod tidy'..."
37 @make tidy
38 @if ! git diff --quiet; then \
39 echo "'go mod tidy' resulted in changes or working tree is dirty:"; \
40 git --no-pager diff; \
41 fi
42
43$(GOLINT):
44 cd tools && go install golang.org/x/lint/golint
45
46$(STATICCHECK):
47 cd tools && go install honnef.co/go/tools/cmd/staticcheck
Matteo Scandoloa4285862020-12-01 18:10:10 -080048
49.PHONY: test
50test:
David K. Bainbridge06631892021-08-19 13:07:00 +000051 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
Matteo Scandoloa4285862020-12-01 18:10:10 -080052
53.PHONY: cover
54cover:
David K. Bainbridge06631892021-08-19 13:07:00 +000055 go test -race -coverprofile=cover.out -coverpkg=./... ./...
56 go tool cover -html=cover.out -o cover.html
Matteo Scandoloa4285862020-12-01 18:10:10 -080057
58.PHONY: bench
59BENCH ?= .
60bench:
David K. Bainbridge06631892021-08-19 13:07:00 +000061 @$(foreach dir,$(MODULE_DIRS), ( \
62 cd $(dir) && \
63 go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
64 ) &&) true
Matteo Scandoloa4285862020-12-01 18:10:10 -080065
66.PHONY: updatereadme
67updatereadme:
68 rm -f README.md
69 cat .readme.tmpl | go run internal/readme/readme.go > README.md
David K. Bainbridge06631892021-08-19 13:07:00 +000070
71.PHONY: tidy
72tidy:
73 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go mod tidy) &&) true