-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
47 lines (37 loc) · 1.46 KB
/
Copy pathMakefile
File metadata and controls
47 lines (37 loc) · 1.46 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
# Contract toolchain. Run `make tools` once, then `make generate` after every
# change under proto/ and commit the results.
# buf finds protoc-gen-go and protoc-gen-go-grpc through PATH.
GOBIN := $(shell go env GOPATH)/bin
export PATH := $(GOBIN):$(PATH)
BUF ?= $(or $(shell command -v buf 2>/dev/null),$(GOBIN)/buf)
GEN_DIR := gen/go/nginxui/plugin/v1
METHODS := gen/methods.json
# Pinned so that regenerated files do not churn between machines.
BUF_VERSION := v1.73.0
PROTOC_GEN_GO_VERSION := v1.36.12
PROTOC_GEN_GO_GRPC_VERSION := v1.6.2
.PHONY: all tools generate lint check test
all: generate check
tools:
go install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION)
go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VERSION)
generate:
rm -f $(GEN_DIR)/*.pb.go
$(BUF) generate
cd tools && go run ./methods -out ../$(METHODS)
lint:
$(BUF) lint
$(BUF) format --diff --exit-code
# check fails when the generated Go code or gen/methods.json is stale, then
# runs the tests of both Go modules.
check: lint
@tmp=$$(mktemp -d) && trap 'rm -rf "$$tmp"' EXIT && \
$(BUF) generate -o "$$tmp" && \
diff -r "$$tmp/$(GEN_DIR)" $(GEN_DIR) || \
{ echo "$(GEN_DIR) is stale, run 'make generate'"; exit 1; }
cd tools && go run ./methods -out ../$(METHODS) -check
$(MAKE) test
test:
cd gen/go && go vet ./... && go test ./...
cd tools && go vet ./... && go test -count=1 ./...