David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 1 | export GOBIN ?= $(shell pwd)/bin |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 2 | |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 3 | GOLINT = $(GOBIN)/golint |
| 4 | STATICCHECK = $(GOBIN)/staticcheck |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 5 | BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 6 | |
| 7 | # Directories containing independent Go modules. |
| 8 | # |
| 9 | # We track coverage only for the main module. |
| 10 | MODULE_DIRS = . ./benchmarks ./zapgrpc/internal/test |
| 11 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 12 | # Many Go tools take file globs or directories as arguments instead of packages. |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 13 | GO_FILES := $(shell \ |
| 14 | find . '(' -path '*/.*' -o -path './vendor' ')' -prune \ |
| 15 | -o -name '*.go' -print | cut -b3-) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 16 | |
| 17 | .PHONY: all |
| 18 | all: lint test |
| 19 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 20 | .PHONY: lint |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 21 | lint: $(GOLINT) $(STATICCHECK) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 22 | @rm -rf lint.log |
| 23 | @echo "Checking formatting..." |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 24 | @gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 25 | @echo "Checking vet..." |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 26 | @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 27 | @echo "Checking lint..." |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 28 | @$(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 |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 31 | @echo "Checking for unresolved FIXMEs..." |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 32 | @git grep -i fixme | grep -v -e Makefile | tee -a lint.log |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 33 | @echo "Checking for license headers..." |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 34 | @./checklicense.sh | tee -a lint.log |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 35 | @[ ! -s lint.log ] |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 36 | @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 |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 48 | |
| 49 | .PHONY: test |
| 50 | test: |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 51 | @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 52 | |
| 53 | .PHONY: cover |
| 54 | cover: |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 55 | go test -race -coverprofile=cover.out -coverpkg=./... ./... |
| 56 | go tool cover -html=cover.out -o cover.html |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 57 | |
| 58 | .PHONY: bench |
| 59 | BENCH ?= . |
| 60 | bench: |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 61 | @$(foreach dir,$(MODULE_DIRS), ( \ |
| 62 | cd $(dir) && \ |
| 63 | go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \ |
| 64 | ) &&) true |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 65 | |
| 66 | .PHONY: updatereadme |
| 67 | updatereadme: |
| 68 | rm -f README.md |
| 69 | cat .readme.tmpl | go run internal/readme/readme.go > README.md |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame^] | 70 | |
| 71 | .PHONY: tidy |
| 72 | tidy: |
| 73 | @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go mod tidy) &&) true |