-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (73 loc) · 2.26 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
PACKAGE = github.com/linkedin/diderot
SOURCE_FILES = $(wildcard $(shell git ls-files))
PROFILES = $(PWD)/out
COVERAGE = $(PROFILES)/diderot.cov
GOBIN = $(shell go env GOPATH)/bin
# "all" is invoked on a bare "make" call since it's the first recipe. It just formats the code and
# checks that all packages can be compiled
.PHONY: all
all: fmt build
build:
go build -v ./...
go test -v -c -o /dev/null $$(go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./...)
tidy:
go mod tidy
vet:
go vet ./...
$(GOBIN)/goimports:
go install golang.org/x/tools/cmd/goimports@latest
.PHONY: fmt
fmt: $(GOBIN)/goimports
$(GOBIN)/goimports -w .
# Can be used to change the number of tests run, defaults to 1 to prevent caching
TESTCOUNT = 1
# Can be used to add flags to the go test invocation: make test TESTFLAGS=-v
TESTFLAGS =
# Can be used to change which package gets tested, defaults to all packages.
TESTPKG = ./...
test:
go test -race -count=$(TESTCOUNT) $(TESTFLAGS) $(TESTPKG)
# Can be used to generate coverage reports for a specific package
COVERPKG = $(PACKAGE)
.PHONY: $(COVERAGE)
coverage: $(COVERAGE)
$(COVERAGE):
@mkdir -p $(@D)
$(MAKE) test TESTFLAGS='-coverprofile=$(COVERAGE) -coverpkg=$(COVERPKG)/...'
go tool cover -html=$(COVERAGE)
profile_cache:
$(MAKE) -B $(PROFILES)/BenchmarkCacheThroughput.bench BENCH_PKG=./cache
profile_handlers:
$(MAKE) -B $(PROFILES)/BenchmarkHandlers.bench BENCH_PKG=./internal/server
BENCHCOUNT = 1
BENCHTIME = 1s
$(PROFILES)/%.bench:
ifdef BENCH_PKG
$(eval BENCHBIN=$(PROFILES)/$*)
mkdir -p $(PROFILES)
go test -c \
-o $(BENCHBIN) \
./$(BENCH_PKG)
cd $(BENCH_PKG) && $(BENCHBIN) \
-test.count $(BENCHCOUNT) \
-test.benchmem \
-test.bench="^$*$$" \
-test.cpuprofile $(PROFILES)/$*.cpu \
-test.memprofile $(PROFILES)/$*.mem \
-test.blockprofile $(PROFILES)/$*.block \
-test.benchtime $(BENCHTIME) \
-test.run "^$$" $(BENCHVERBOSE) \
. | tee $(abspath $@) $(abspath $(BENCHOUT))
else
$(error BENCH_PKG undefined)
endif
ifdef OPEN_PROFILES
go tool pprof $(BENCHBIN) $(PROFILES)/$*.cpu <<< web
go tool pprof $(PROFILES)/$*.mem <<< web
else
$(info Not opening profiles since OPEN_PROFILES is not set)
endif
$(GOBIN)/pkgsite:
go install golang.org/x/pkgsite/cmd/pkgsite@latest
docs: $(GOBIN)/pkgsite
$(GOBIN)/pkgsite -open .