@@ -27,13 +27,18 @@ VALD_DIR = vald-origin
27
27
VALD_SHA = VALD_SHA
28
28
VALD_CLIENT_PYTHON_VERSION = VALD_CLIENT_PYTHON_VERSION
29
29
30
- PWD := $(eval PWD := $(shell pwd) )$(PWD )
31
- GOPATH := $(eval GOPATH := $(shell go env GOPATH) )$(GOPATH )
30
+ BINDIR ?= /usr/local/bin
32
31
33
32
PROTO_ROOT = $(VALD_DIR ) /apis/proto
34
33
PB2DIR_ROOT = src
35
34
36
- SHADOW_ROOT = vald
35
+ BUF_VERSION_URL := https://raw.githubusercontent.com/vdaas/vald/main/versions/BUF_VERSION
36
+ BUF_CONFIGS = \
37
+ $(PROTO_ROOT ) /buf.yaml \
38
+ $(PROTO_ROOT ) /buf.lock
39
+
40
+ SHADOW_ROOT = vald
41
+ SHADOW_PROTO_ROOT = $(SHADOW_ROOT ) /$(SHADOW_ROOT )
37
42
38
43
PROTOS = \
39
44
v1/agent/core/agent.proto \
@@ -48,21 +53,8 @@ PROTOS = \
48
53
v1/vald/upsert.proto \
49
54
v1/payload/payload.proto
50
55
PROTOS := $(PROTOS:%=$(PROTO_ROOT ) /% )
51
- SHADOWS = $(PROTOS:$(PROTO_ROOT ) /%.proto=$(SHADOW_ROOT ) /%.proto )
56
+ SHADOWS = $(PROTOS:$(PROTO_ROOT ) /%.proto=$(SHADOW_PROTO_ROOT ) /%.proto )
52
57
PB2PYS = $(PROTOS:$(PROTO_ROOT ) /%.proto=$(PB2DIR_ROOT ) /$(SHADOW_ROOT ) /%_pb2.py )
53
- PB2PY_VALIDATE = $(PB2DIR_ROOT ) /validate/validate_pb2.py
54
- PB2PY_GOOGLEAPIS = $(PB2DIR_ROOT ) /googleapis/googleapis/google/api/annotations_pb2.py
55
- PB2PY_GOOGLERPCS = $(PB2DIR_ROOT ) /googleapis/googleapis/google/rpc/status_pb2.py
56
- PB2PY_VTEXTPY = $(PB2DIR_ROOT ) /vtproto/ext_pb2.py
57
-
58
- PROTO_PATHS = \
59
- $(PWD ) \
60
- $(PWD ) /$(VALD_DIR ) \
61
- $(PWD ) /$(PROTO_ROOT ) \
62
- $(GOPATH ) /src \
63
- $(GOPATH ) /src/github.com/googleapis/googleapis \
64
- $(GOPATH ) /src/github.com/envoyproxy/protoc-gen-validate \
65
- $(GOPATH ) /src/github.com/planetscale/vtprotobuf/include/github.com/planetscale/vtprotobuf
66
58
67
59
MAKELISTS = Makefile
68
60
@@ -73,14 +65,6 @@ blue = /bin/echo -e "\x1b[34m\#\# $1\x1b[0m"
73
65
pink = /bin/echo -e "\x1b[35m\# \# $1\x1b[0m"
74
66
cyan = /bin/echo -e "\x1b[36m\# \# $1\x1b[0m"
75
67
76
- define go-get
77
- GO111MODULE=on go get -u $1
78
- endef
79
-
80
- define go-get-no-mod
81
- GO111MODULE=off go get -u $1
82
- endef
83
-
84
68
.PHONY : all
85
69
# # execute clean and proto
86
70
all : clean proto
@@ -104,85 +88,28 @@ help:
104
88
.PHONY : clean
105
89
# # clean
106
90
clean :
107
- rm -rf $(PB2DIR_ROOT ) /google $(PB2DIR_ROOT ) /vald $(PB2DIR_ROOT ) /validate $( PB2DIR_ROOT ) /vtproto
91
+ rm -rf $(PB2DIR_ROOT ) /google $(PB2DIR_ROOT ) /vald $(PB2DIR_ROOT ) /buf
108
92
rm -rf $(SHADOW_ROOT )
109
93
rm -rf $(VALD_DIR )
110
94
111
95
.PHONY : proto
112
96
# # build proto
113
- proto : \
114
- $(PB2PYS ) \
115
- $(PB2PY_VALIDATE ) \
116
- $(PB2PY_GOOGLEAPIS ) \
117
- $(PB2PY_GOOGLERPCS ) \
118
- $(PB2PY_VTEXTPY )
97
+ proto : $(PB2PYS )
98
+ @$(call green, "generating pb2.py files...")
99
+ cp -f $(BUF_CONFIGS ) $(SHADOW_ROOT )
100
+ buf generate --include-imports
119
101
120
102
$(PROTOS ) : $(VALD_DIR )
121
103
$(SHADOWS ) : $(PROTOS )
122
- $(SHADOW_ROOT ) /% .proto : $(PROTO_ROOT ) /% .proto
104
+ $(SHADOW_PROTO_ROOT ) /% .proto : $(PROTO_ROOT ) /% .proto
123
105
mkdir -p $(dir $@ )
124
106
cp $< $@
125
- sed -i -e ' s:^import "apis/proto/:import "$(SHADOW_ROOT)/:' $@
126
- sed -i -e ' s:^import "github.com/envoyproxy/protoc-gen-validate/:import ":' $@
127
- sed -i -e ' s:^import "github.com/googleapis/googleapis/:import ":' $@
128
- sed -i -e ' s:^import "github.com/planetscale/vtprotobuf/include/github.com/planetscale/vtprotobuf/:import ":' $@
107
+ sed -i -e ' s:^import "v1:import "$(SHADOW_ROOT)/v1:' $@
129
108
130
109
$(PB2DIR_ROOT ) :
131
110
mkdir -p $@
132
111
133
112
$(PB2PYS ) : proto/deps $(PB2DIR_ROOT ) $(SHADOWS )
134
- $(PB2DIR_ROOT ) /$(SHADOW_ROOT ) /% _pb2.py : $(SHADOW_ROOT ) /% .proto
135
- @$(call green, "generating pb2.py files...")
136
- $(PYTHON ) \
137
- -m grpc_tools.protoc \
138
- $(PROTO_PATHS:%=-I % ) \
139
- --python_out=$(PWD ) /$(PB2DIR_ROOT ) \
140
- --grpc_python_out=$(PWD ) /$(PB2DIR_ROOT ) \
141
- $<
142
-
143
- $(PB2PY_VALIDATE ) : $(GOPATH ) /src/github.com/envoyproxy/protoc-gen-validate
144
- @$(call green, "generating pb2.py files...")
145
- (cd $( GOPATH) /src/github.com/envoyproxy/protoc-gen-validate; \
146
- $(PYTHON ) \
147
- -m grpc_tools.protoc \
148
- $(PROTO_PATHS:%=-I % ) \
149
- -I $(GOPATH ) /src/github.com/envoyproxy/protoc-gen-validate \
150
- --python_out=$(PWD ) /$(PB2DIR_ROOT ) \
151
- --grpc_python_out=$(PWD ) /$(PB2DIR_ROOT ) \
152
- validate/validate.proto)
153
-
154
- $(PB2PY_GOOGLEAPIS ) : $(GOPATH ) /src/github.com/googleapis/googleapis
155
- @$(call green, "generating pb2.py files...")
156
- (cd $( GOPATH) /src/github.com/googleapis/googleapis; \
157
- $(PYTHON ) \
158
- -m grpc_tools.protoc \
159
- $(PROTO_PATHS:%=-I % ) \
160
- -I $(GOPATH ) /src/github.com/googleapis/googleapis \
161
- --python_out=$(PWD ) /$(PB2DIR_ROOT ) \
162
- --grpc_python_out=$(PWD ) /$(PB2DIR_ROOT ) \
163
- google/api/annotations.proto)
164
-
165
- $(PB2PY_GOOGLERPCS ) : $(GOPATH ) /src/github.com/googleapis/googleapis
166
- @$(call green, "generating pb2.py files...")
167
- (cd $( GOPATH) /src/github.com/googleapis/googleapis; \
168
- $(PYTHON ) \
169
- -m grpc_tools.protoc \
170
- $(PROTO_PATHS:%=-I % ) \
171
- -I $(GOPATH ) /src/github.com/googleapis/googleapis \
172
- --python_out=$(PWD ) /$(PB2DIR_ROOT ) \
173
- --grpc_python_out=$(PWD ) /$(PB2DIR_ROOT ) \
174
- google/rpc/status.proto)
175
-
176
- $(PB2PY_VTEXTPY ) : $(GOPATH ) /src/github.com/planetscale/vtprotobuf
177
- @$(call green, "generating pb2.py files...")
178
- (cd $( GOPATH) /src/github.com/planetscale/vtprotobuf; \
179
- $(PYTHON ) \
180
- -m grpc_tools.protoc \
181
- $(PROTO_PATHS:%=-I % ) \
182
- -I $(GOPATH ) /src/github.com/planetscale/vtprotobuf/include/github.com/planetscale/vtprotobuf \
183
- --python_out=$(PWD ) /$(PB2DIR_ROOT ) \
184
- --grpc_python_out=$(PWD ) /$(PB2DIR_ROOT ) \
185
- vtproto/ext.proto)
186
113
187
114
$(VALD_DIR ) :
188
115
git clone --depth 1 https://$(VALDREPO ) $(VALD_DIR )
@@ -227,25 +154,15 @@ vald/client/python/version/update: vald
227
154
228
155
.PHONY : proto/deps
229
156
# # install proto deps
230
- proto/deps : \
231
- $(GOPATH ) /src/github.com/googleapis/googleapis \
232
- $(GOPATH ) /src/github.com/envoyproxy/protoc-gen-validate \
233
- $(GOPATH ) /src/github.com/planetscale/vtprotobuf
234
-
235
- $(GOPATH ) /src/github.com/googleapis/googleapis :
236
- git clone \
237
- --depth 1 \
238
- https://github.com/googleapis/googleapis \
239
- $(GOPATH ) /src/github.com/googleapis/googleapis
240
-
241
- $(GOPATH ) /src/github.com/envoyproxy/protoc-gen-validate :
242
- git clone \
243
- --depth 1 \
244
- https://github.com/envoyproxy/protoc-gen-validate \
245
- $(GOPATH ) /src/github.com/envoyproxy/protoc-gen-validate
246
-
247
- $(GOPATH ) /src/github.com/planetscale/vtprotobuf :
248
- git clone \
249
- --depth 1 \
250
- https://github.com/planetscale/vtprotobuf \
251
- $(GOPATH ) /src/github.com/planetscale/vtprotobuf
157
+ proto/deps : buf/install
158
+
159
+ .PHONY : buf/install
160
+ # # install buf command.
161
+ buf/install : $(BINDIR ) /buf
162
+
163
+ $(BINDIR ) /buf :
164
+ @version=$$(curl -sSL $(BUF_VERSION_URL ) ) ; \
165
+ curl -sSL \
166
+ " https://github.com/bufbuild/buf/releases/download/$$ version/buf-$( shell uname -s) -$( shell uname -m) " \
167
+ -o " ${BINDIR} /buf" && \
168
+ chmod +x " ${BINDIR} /buf"
0 commit comments