-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
114 lines (90 loc) · 2.89 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
SHELL = /bin/bash
# Cross-platform way to find the directory holding this Makefile.
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
export GOBIN ?= $(PROJECT_ROOT)/bin
export PATH := $(GOBIN):$(PATH)
MODULES ?= . ./examples ./internal/tests ./tools ./docs
TEST_FLAGS ?= -race
BUILD_FLAGS ?=
CFF = bin/cff
MOCKGEN = bin/mockgen
STATICCHECK = bin/staticcheck
MDOX = bin/mdox
# 'make cover' should not run on docs by default.
# We run that separately explicitly on a specific platform.
COVER_MODULES ?= $(filter-out ./docs ./tools,$(MODULES))
# 'make lint' should not run on internal/tests or tools.
LINT_MODULES ?= $(filter-out ./internal/tests ./tools,$(MODULES))
SRC_FILES = $(shell find . '(' -path './.*' -o -path '*test*' -o -path '*/examples/*' -o -path './docs/*' -prune ')' -o -name '*.go' -print)
# All go files are in scope for formatting -- even if they're generated.
GOFMT_FILES = $(shell find . -path './.*' -prune -o -name '*.go' -print)
.PHONY: build
build: $(CFF)
.PHONY: test
test: build
@$(foreach dir,$(COVER_MODULES),( \
cd $(dir) && \
echo "--- [test] $(dir)" && \
go test $(TEST_FLAGS) ./... \
) &&) true
.PHONY: cover
cover: build
@$(foreach dir,$(COVER_MODULES),( \
cd $(dir) && \
echo "--- [cover] $(dir)" && \
go test $(TEST_FLAGS) -coverprofile=cover.out -coverpkg=go.uber.org/cff/... ./... && \
go tool cover -html=cover.out -o cover.html \
) &&) true
# We run 'go generate' with '-tags cff'
# because build tags can be inside cff-tagged files.
.PHONY: generate
generate: $(CFF) $(MOCKGEN)
@$(foreach dir,$(MODULES),( \
cd $(dir) && \
echo "--- [generate] $(dir)" && \
go generate -tags cff -x ./... \
) &&) true
# Run 'make generate' with a coverage-instrumented cff binary,
# and write the coverage profile to a file.
.PHONY: generate-cover
generate-cover:
$(eval BIN := $(shell mktemp -d))
$(eval COVERDIR := $(shell mktemp -d))
GOCOVERDIR=$(COVERDIR) make generate \
GOBIN=$(BIN) \
BUILD_FLAGS="-cover -coverpkg=go.uber.org/cff/..."
go tool covdata textfmt -i=$(COVERDIR) -o=cover.out
go tool cover -html=cover.out -o cover.html
.PHONY: tidy
tidy:
@$(foreach dir,$(MODULES),( \
cd $(dir) && \
echo "--- [tidy] $(dir)" && \
go mod tidy \
) &&) true
.PHONY: fmt
fmt:
@gofmt -w -l $(GOFMT_FILES)
.PHONY: lint
lint: golangci-lint docs-check
.PHONY: golangci-lint
golangci-lint:
@$(foreach mod,$(LINT_MODULES), \
(cd $(mod) && \
echo "[lint] golangci-lint: $(mod)" && \
golangci-lint run --path-prefix $(mod)) &&) true
.PHONY: docs
docs:
cd docs && yarn build
.PHONY: docs-check
docs-check: $(MDOX)
@echo "Checking documentation"
@make -C docs check
$(CFF): $(SRC_FILES)
go install $(BUILD_FLAGS) go.uber.org/cff/cmd/cff
$(MOCKGEN): go.mod
go install github.com/golang/mock/mockgen
$(STATICCHECK): tools/go.mod
cd tools && go install honnef.co/go/tools/cmd/staticcheck
$(MDOX): tools/go.mod
cd tools && go install github.com/bwplotka/mdox