blob: 9b1bc3b0e1d891f34507d5454a00642942c66561 [file] [log] [blame]
khenaidoo26721882021-08-11 17:42:52 -04001export GOBIN ?= $(shell pwd)/bin
Scott Baker2c1c4822019-10-16 11:02:41 -07002
khenaidoo26721882021-08-11 17:42:52 -04003GOLINT = $(GOBIN)/golint
4STATICCHECK = $(GOBIN)/staticcheck
Scott Baker2c1c4822019-10-16 11:02:41 -07005BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
khenaidoo26721882021-08-11 17:42:52 -04006
7# Directories containing independent Go modules.
8#
9# We track coverage only for the main module.
10MODULE_DIRS = . ./benchmarks ./zapgrpc/internal/test
11
Scott Baker2c1c4822019-10-16 11:02:41 -070012# Many Go tools take file globs or directories as arguments instead of packages.
khenaidoo26721882021-08-11 17:42:52 -040013GO_FILES := $(shell \
14 find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
15 -o -name '*.go' -print | cut -b3-)
Scott Baker2c1c4822019-10-16 11:02:41 -070016
17.PHONY: all
18all: lint test
19
Scott Baker2c1c4822019-10-16 11:02:41 -070020.PHONY: lint
khenaidoo26721882021-08-11 17:42:52 -040021lint: $(GOLINT) $(STATICCHECK)
Scott Baker2c1c4822019-10-16 11:02:41 -070022 @rm -rf lint.log
23 @echo "Checking formatting..."
khenaidoo26721882021-08-11 17:42:52 -040024 @gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
Scott Baker2c1c4822019-10-16 11:02:41 -070025 @echo "Checking vet..."
khenaidoo26721882021-08-11 17:42:52 -040026 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
Scott Baker2c1c4822019-10-16 11:02:41 -070027 @echo "Checking lint..."
khenaidoo26721882021-08-11 17:42:52 -040028 @$(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
Scott Baker2c1c4822019-10-16 11:02:41 -070031 @echo "Checking for unresolved FIXMEs..."
khenaidoo26721882021-08-11 17:42:52 -040032 @git grep -i fixme | grep -v -e Makefile | tee -a lint.log
Scott Baker2c1c4822019-10-16 11:02:41 -070033 @echo "Checking for license headers..."
khenaidoo26721882021-08-11 17:42:52 -040034 @./checklicense.sh | tee -a lint.log
Scott Baker2c1c4822019-10-16 11:02:41 -070035 @[ ! -s lint.log ]
khenaidoo26721882021-08-11 17:42:52 -040036 @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
Scott Baker2c1c4822019-10-16 11:02:41 -070048
49.PHONY: test
50test:
khenaidoo26721882021-08-11 17:42:52 -040051 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
Scott Baker2c1c4822019-10-16 11:02:41 -070052
53.PHONY: cover
54cover:
khenaidoo26721882021-08-11 17:42:52 -040055 go test -race -coverprofile=cover.out -coverpkg=./... ./...
56 go tool cover -html=cover.out -o cover.html
Scott Baker2c1c4822019-10-16 11:02:41 -070057
58.PHONY: bench
59BENCH ?= .
60bench:
khenaidoo26721882021-08-11 17:42:52 -040061 @$(foreach dir,$(MODULE_DIRS), ( \
62 cd $(dir) && \
63 go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
64 ) &&) true
Scott Baker2c1c4822019-10-16 11:02:41 -070065
66.PHONY: updatereadme
67updatereadme:
68 rm -f README.md
69 cat .readme.tmpl | go run internal/readme/readme.go > README.md
khenaidoo26721882021-08-11 17:42:52 -040070
71.PHONY: tidy
72tidy:
73 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go mod tidy) &&) true