blob: eb1cee53bd51147d74cc502e8995a6e16a0d15e9 [file] [log] [blame]
Abhay Kumara61c5222025-11-10 07:32:50 +00001# Directory containing the Makefile.
2PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
William Kurkianea869482019-04-09 15:16:11 -04003
Abhay Kumara61c5222025-11-10 07:32:50 +00004export GOBIN ?= $(PROJECT_ROOT)/bin
5export PATH := $(GOBIN):$(PATH)
6
7GOVULNCHECK = $(GOBIN)/govulncheck
William Kurkianea869482019-04-09 15:16:11 -04008BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
khenaidoo106c61a2021-08-11 18:05:46 -04009
10# Directories containing independent Go modules.
Abhay Kumara61c5222025-11-10 07:32:50 +000011MODULE_DIRS = . ./exp ./benchmarks ./zapgrpc/internal/test
khenaidoo106c61a2021-08-11 18:05:46 -040012
Abhay Kumara61c5222025-11-10 07:32:50 +000013# Directories that we want to track coverage for.
14COVER_DIRS = . ./exp
William Kurkianea869482019-04-09 15:16:11 -040015
16.PHONY: all
17all: lint test
18
William Kurkianea869482019-04-09 15:16:11 -040019.PHONY: lint
Abhay Kumara61c5222025-11-10 07:32:50 +000020lint: golangci-lint tidy-lint license-lint
khenaidoo106c61a2021-08-11 18:05:46 -040021
Abhay Kumara61c5222025-11-10 07:32:50 +000022.PHONY: golangci-lint
23golangci-lint:
24 @$(foreach mod,$(MODULE_DIRS), \
25 (cd $(mod) && \
26 echo "[lint] golangci-lint: $(mod)" && \
27 golangci-lint run --path-prefix $(mod)) &&) true
khenaidoo106c61a2021-08-11 18:05:46 -040028
Abhay Kumara61c5222025-11-10 07:32:50 +000029.PHONY: tidy
30tidy:
31 @$(foreach dir,$(MODULE_DIRS), \
32 (cd $(dir) && go mod tidy) &&) true
33
34.PHONY: tidy-lint
35tidy-lint:
36 @$(foreach mod,$(MODULE_DIRS), \
37 (cd $(mod) && \
38 echo "[lint] tidy: $(mod)" && \
39 go mod tidy && \
40 git diff --exit-code -- go.mod go.sum) &&) true
41
42
43.PHONY: license-lint
44license-lint:
45 ./checklicense.sh
46
47$(GOVULNCHECK):
48 cd tools && go install golang.org/x/vuln/cmd/govulncheck
William Kurkianea869482019-04-09 15:16:11 -040049
50.PHONY: test
51test:
khenaidoo106c61a2021-08-11 18:05:46 -040052 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
William Kurkianea869482019-04-09 15:16:11 -040053
54.PHONY: cover
55cover:
Abhay Kumara61c5222025-11-10 07:32:50 +000056 @$(foreach dir,$(COVER_DIRS), ( \
57 cd $(dir) && \
58 go test -race -coverprofile=cover.out -coverpkg=./... ./... \
59 && go tool cover -html=cover.out -o cover.html) &&) true
William Kurkianea869482019-04-09 15:16:11 -040060
61.PHONY: bench
62BENCH ?= .
63bench:
khenaidoo106c61a2021-08-11 18:05:46 -040064 @$(foreach dir,$(MODULE_DIRS), ( \
65 cd $(dir) && \
66 go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
67 ) &&) true
William Kurkianea869482019-04-09 15:16:11 -040068
69.PHONY: updatereadme
70updatereadme:
71 rm -f README.md
72 cat .readme.tmpl | go run internal/readme/readme.go > README.md
khenaidoo106c61a2021-08-11 18:05:46 -040073
Abhay Kumara61c5222025-11-10 07:32:50 +000074.PHONY: vulncheck
75vulncheck: $(GOVULNCHECK)
76 $(GOVULNCHECK) ./...