This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
150 lines (128 loc) · 3.56 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
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
# https://github.com/aperturerobotics/protobuf-project
PROTOWRAP=hack/bin/protowrap
PROTOC_GEN_GO=hack/bin/protoc-gen-go
PROTOC_GEN_GO_GRPC=hack/bin/protoc-gen-go-grpc
PROTOC_GEN_VTPROTO=hack/bin/protoc-gen-go-vtproto
GOIMPORTS=hack/bin/goimports
GOLANGCI_LINT=hack/bin/golangci-lint
GO_MOD_OUTDATED=hack/bin/go-mod-outdated
GOLIST=go list -f "{{ .Dir }}" -m
export GO111MODULE=on
undefine GOARCH
undefine GOOS
all:
vendor:
go mod vendor
$(PROTOC_GEN_GO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go \
google.golang.org/protobuf/cmd/protoc-gen-go
$(PROTOC_GEN_GO_GRPC):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-grpc \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
$(PROTOC_GEN_VTPROTO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-vtproto \
github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto
$(GOIMPORTS):
cd ./hack; \
go build -v \
-o ./bin/goimports \
golang.org/x/tools/cmd/goimports
$(PROTOWRAP):
cd ./hack; \
go build -v \
-o ./bin/protowrap \
github.com/square/goprotowrap/cmd/protowrap
$(GOLANGCI_LINT):
cd ./hack; \
go build -v \
-o ./bin/golangci-lint \
github.com/golangci/golangci-lint/cmd/golangci-lint
$(GO_MOD_OUTDATED):
cd ./hack; \
go build -v \
-o ./bin/go-mod-outdated \
github.com/psampaz/go-mod-outdated
# Add --go-grpc_out=$$(pwd)/vendor to use the GRPC protoc generator.
# .. and remove the "grpc" option from the vtprotobuf features list.
.PHONY: gengo
gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) $(PROTOC_GEN_VTPROTO)
go mod vendor
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} ; \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
--go_out=$$(pwd)/vendor \
--go-vtproto_out=$$(pwd)/vendor \
--go-vtproto_opt=features=marshal+unmarshal+size+equal+grpc \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "*.proto" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
rm $$(pwd)/vendor/$${PROJECT} || true
$(GOIMPORTS) -w ./
node_modules:
yarn install
.PHONY: gents
gents: $(PROTOWRAP) node_modules
go mod vendor
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} ; \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=$$(pwd)/vendor \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_opt=fileSuffix=.pb \
--ts_proto_opt=forceLong=long \
--ts_proto_opt=oneof=unions \
--ts_proto_opt=outputServices=default,outputServices=generic-definitions \
--ts_proto_opt=useDate=true \
--ts_proto_opt=useAsyncIterable=true \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "*.proto" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
go mod vendor
.PHONY: genproto
genproto: gengo gents
.PHONY: gen
gen: genproto
.PHONY: outdated
outdated: $(GO_MOD_OUTDATED)
go list -mod=mod -u -m -json all | $(GO_MOD_OUTDATED) -update -direct
.PHONY: list
list: $(GO_MOD_OUTDATED)
go list -mod=mod -u -m -json all | $(GO_MOD_OUTDATED)
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run
.PHONY: fix
fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix
.PHONY: test
test:
go test -v ./...