-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgo.mk
More file actions
293 lines (239 loc) · 6.49 KB
/
go.mk
File metadata and controls
293 lines (239 loc) · 6.49 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Managed by makego. DO NOT EDIT.
# Must be set
$(call _assert_var,MAKEGO)
$(call _conditional_include,$(MAKEGO)/base.mk)
$(call _conditional_include,$(MAKEGO)/dep_bandeps.mk)
$(call _conditional_include,$(MAKEGO)/dep_bufstyle.mk)
$(call _conditional_include,$(MAKEGO)/dep_bufprivateusage.mk)
$(call _conditional_include,$(MAKEGO)/dep_godoclint.mk)
$(call _conditional_include,$(MAKEGO)/dep_golangci_lint.mk)
$(call _conditional_include,$(MAKEGO)/dep_govulncheck.mk)
$(call _conditional_include,$(MAKEGO)/dep_yq.mk)
# Must be set
$(call _assert_var,GO_MODULE)
$(call _assert_var,GOLANGCI_LINT)
$(call _assert_var,TMP)
$(call _assert_var,OPEN_CMD)
# Settable
GO_BINS ?=
# Settable
GO_TEST_BINS ?=
# Settable
GO_TEST_WASM_BINS ?=
# Settable
GO_GET_PKGS ?=
# Settable
GO_MOD_VERSION ?= 1.25.6
# Settable
GO_MOD_TOOLCHAIN ?=
# Settable
GO_ALL_REPO_PKGS ?= ./cmd/... ./internal/...
# Settable
SKIP_BUFSTYLE ?=
# Settable
SKIP_GODOCLINT ?=
# Settable
SKIP_GOLANGCI_LINT ?=
# Settable
SKIP_GOVULNCHECK ?=
# Settable
DISALLOW_NOLINT ?=
# Settable
BUFPRIVATEUSAGE_PKGS ?=
# Settable
BANDEPS_CONFIG ?=
# Settable
GO_BUILD_EXTRA_FLAGS ?=
# Settable
GO_INSTALL_EXTRA_FLAGS ?= $(GO_BUILD_EXTRA_FLAGS)
# Settable
GO_TEST_EXTRA_FLAGS ?= $(GO_BUILD_EXTRA_FLAGS)
# Runtime
GOPKGS ?= $(GO_ALL_REPO_PKGS)
# Runtime
GOLANGCILINTTIMEOUT ?= 3m0s
# Runtime GONOTESTCACHE
# Runtime COVEROPEN
COVER_HTML := $(TMP)/cover.html
COVER_TXT := $(TMP)/cover.txt
ifdef GONOTESTCACHE
GO_TEST_FLAGS := -count=1 $(GO_TEST_EXTRA_FLAGS)
else
GO_TEST_FLAGS := $(GO_TEST_EXTRA_FLAGS)
endif
.DEFAULT_GOAL := shortall
.PHONY: all
all: ## Run make lint and make test.
@$(MAKE) lint
@$(MAKE) test
postupgrade:: all
.PHONY: shortall
shortall: ## Run make shortlint and make shorttest.
@$(MAKE) shortlint
@$(MAKE) shorttest
.PHONY: ci
ci:
@$(MAKE) lint
@$(MAKE) test
.PHONY: postupgradegodeps
postupgradegodeps::
.PHONY: upgradegodeps
upgradegodeps:
rm -f go.mod go.sum
go mod init $(GO_MODULE)
go mod edit -go=$(GO_MOD_VERSION)
ifneq ($(GO_MOD_TOOLCHAIN),)
go mod edit -toolchain=go$(GO_MOD_TOOLCHAIN)
endif
ifneq ($(GO_GET_PKGS),)
go get $(GO_GET_PKGS)
endif
go get -u -t $(GO_ALL_REPO_PKGS) $(GO_GET_PKGS)
go mod tidy -v
@$(MAKE) postupgradegodeps
preupgrade:: upgradegodeps
initmakego:: upgradegodeps
.PHONY: godeps
godeps: deps
go mod download
.PHONY: gofmtmodtidy
gofmtmodtidy: $(GOLANGCI_LINT)
@echo gofmt -s -w ALL_GO_FILES
@gofmt -s -w .
go mod tidy -v
ifeq ($(SKIP_GOLANGCI_LINT),)
golangci-lint fmt
endif
format:: gofmtmodtidy
ifneq ($(BUFPRIVATEUSAGE_PKGS),)
.PHONY: bufprivateusage
bufprivateusage: $(BUFPRIVATEUSAGE)
bufprivateusage $(BUFPRIVATEUSAGE_PKGS)
postprepostgenerate:: bufprivateusage
endif
.PHONY: checknolintlint
checknolintlint: $(YQ)
ifneq ($(DISALLOW_NOLINT),)
@if grep -r --include "*.go" '//nolint'; then \
echo '//nolint directives found, surface ignores in .golangci.yml instead' >&2; \
exit 1; \
fi
else
bash $(MAKEGO)/scripts/checknolintlint.bash
endif
.PHONY: bufstyle
bufstyle: $(BUFSTYLE)
ifneq ($(SKIP_BUFSTYLE),)
@echo Skipping bufstyle...
else
@echo bufstyle GOPKGS
@bufstyle $(GOPKGS)
endif
.PHONY: godoclint
godoclint: $(GODOCLINT)
ifneq ($(SKIP_GODOCLINT),)
@echo Skipping godoclint...
else
@echo godoclint GOPKGS
@godoclint $(GOPKGS)
endif
.PHONY: golangcilint
golangcilint: $(GOLANGCI_LINT)
ifneq ($(SKIP_GOLANGCI_LINT),)
@echo Skipping golangci-lint...
else
golangci-lint fmt --diff
golangci-lint run --timeout $(GOLANGCILINTTIMEOUT)
endif
.PHONY: govulncheck
govulncheck: $(GOVULNCHECK)
@echo govulncheck GOPKGS
@govulncheck $(GOPKGS)
.PHONY: postlint
postlint::
.PHONY: postlonglint
postlonglint::
ifneq ($(BANDEPS_CONFIG),)
.PHONY: bandeps
bandeps: $(BANDEPS)
bandeps -f $(BANDEPS_CONFIG)
postlonglint:: bandeps
endif
.PHONY: shortlint
shortlint: ## Run all linters but exclude long-running linters.
@$(MAKE) checknodiffgenerated
@$(MAKE) checknolintlint bufstyle godoclint golangcilint govulncheck postlint
.PHONY: lint
lint: ## Run all linters.
@$(MAKE) shortlint
@$(MAKE) postlonglint
.PHONY: prebuild
prebuild::
.PHONY: build
build: prebuild ## Run go build.
go build $(GO_BUILD_EXTRA_FLAGS) ./...
.PHONY: pretest
pretest::
.PHONY: test
test: pretest installtest installtestwasm ## Run all go tests.
go test $(GO_TEST_FLAGS) $(GOPKGS)
.PHONY: testrace
testrace: pretest installtest
go test -race $(GO_TEST_FLAGS) $(GOPKGS)
.PHONY: shorttest
shorttest: pretest installtest ## Run all go tests but exclude long-running tests.
go test -test.short $(GO_TEST_FLAGS) $(GOPKGS)
.PHONY: deppkgs
deppkgs:
@go list -f '{{join .Deps "\n"}}' $(GOPKGS) | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
.PHONY: coverpkgs
coverpkgs:
@go list $(GOPKGS) | grep -v \/gen\/ | tr '\n' ',' | sed "s/,$$//"
.PHONY: cover
cover: pretest installtest
@mkdir -p $(dir $(COVER_HTML)) $(dir $(COVER_TXT))
@rm -f $(COVER_HTML) $(COVER_TXT)
go test -race -coverprofile=$(COVER_TXT) -coverpkg=$(shell GOPKGS=$(GOPKGS) $(MAKE) -s coverpkgs) $(GOPKGS)
@go tool cover -html=$(COVER_TXT) -o $(COVER_HTML)
@echo
@go tool cover -func=$(COVER_TXT) | grep total
@echo
ifndef COVEROPEN
@echo $(OPEN_CMD) $(COVER_HTML)
else
$(OPEN_CMD) $(COVER_HTML)
endif
.PHONY: install
install:: ## Install all go binaries.
define gobinfunc
.PHONY: install$(notdir $(1))
install$(notdir $(1)):
go install $(GO_INSTALL_EXTRA_FLAGS) ./$(1)
install:: install$(notdir $(1))
.PHONY: lint$(notdir $(1))
lint$(notdir $(1)):
bash $(MAKEGO)/scripts/checkcmdpackage.bash ./$(1)
postlint:: lint$(notdir $(1))
endef
$(foreach gobin,$(sort $(GO_BINS)),$(eval $(call gobinfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))
.PHONY: installtest
installtest::
define gotestbinfunc
.PHONY: installtest$(notdir $(1))
installtest$(notdir $(1)):
go install $(GO_INSTALL_EXTRA_FLAGS) ./$(1)
installtest:: installtest$(notdir $(1))
endef
$(foreach gobin,$(sort $(GO_TEST_BINS)),$(eval $(call gotestbinfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_TEST_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))
.PHONY: installtestwasm
installtestwasm::
define gotestwasmfunc
.PHONY: installtestwasm$(notdir $(1))
installtestwasm$(notdir $(1)):
GOOS=wasip1 GOARCH=wasm go build $(GO_BUILD_EXTRA_FLAGS) -o $(GOBIN)/$(notdir $(1)).wasm ./$(1)
installtestwasm:: installtestwasm$(notdir $(1))
endef
$(foreach gobin,$(sort $(GO_TEST_WASM_BINS)),$(eval $(call gotestwasmfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_TEST_WASM_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))