-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
99 lines (85 loc) · 2.09 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
SHELL:=bash
PROTOWRAP=hack/bin/protowrap
GOIMPORTS=hack/bin/goimports
GOFUMPT=hack/bin/gofumpt
GOLANGCI_LINT=hack/bin/golangci-lint
PROTOC_GEN_GO=hack/bin/protoc-gen-go-lite
GOLIST=go list -f "{{ .Dir }}" -m
export GO111MODULE=on
undefine GOOS
undefine GOARCH
all:
vendor:
go mod vendor
$(GOIMPORTS):
cd ./hack; \
go build -v \
-o ./bin/goimports \
golang.org/x/tools/cmd/goimports
$(GOFUMPT):
cd ./hack; \
go build -v \
-o ./bin/gofumpt \
mvdan.cc/gofumpt
$(PROTOWRAP):
cd ./hack; \
go build -v \
-o ./bin/protowrap \
github.com/aperturerobotics/goprotowrap/cmd/protowrap
$(GOLANGCI_LINT):
cd ./hack; \
go build -v \
-o ./bin/golangci-lint \
github.com/golangci/golangci-lint/cmd/golangci-lint
$(PROTOC_GEN_GO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-lite \
github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite
.PHONY: build
build: vendor
go build -v
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --timeout=10m
.PHONY: fix
fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix --timeout=10m
.PHONY: format
format: $(GOFUMPT) $(GOIMPORTS)
$(GOIMPORTS) -w ./
$(GOFUMPT) -w ./
.PHONY: test
test:
go test -v ./...
.PHONY: gengo
gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO)
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
export PATH=$$(pwd)/hack/bin:$${PATH}; \
mkdir -p $$(pwd)/vendor/$$(dirname $${PROJECT}); \
rm $$(pwd)/vendor/$${PROJECT} || true; \
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
protogen() { \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
-I $$(pwd) \
--go-lite_out=$$(pwd)/vendor \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$2 \
$$(\
git \
ls-files "$$1" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
}; \
for d in ./types/known/*; do \
protogen "$${d}/*.proto" "--go-lite_opt=features=marshal+marshal_strict+unmarshal+unmarshal_unsafe+size+equal+clone+text"; \
done; \
protogen "./types/descriptorpb/*.proto" ""; \
protogen "./testproto/*.proto" ""; \
rm $$(pwd)/vendor/$${PROJECT} || true
$(GOIMPORTS) -w ./