/
RUNME.sh
executable file
·411 lines (337 loc) · 11.1 KB
/
RUNME.sh
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# chmod +x cloneConvertTensorflow.sh
#
# please join grpc channel ->
# https://tensorflowtalk.slack.com/
#
#
#!/bin/bash
printf "\033c"
printf "Intention of this script is it checkout latest apple protobuf + tensorflow proto files then build protobuf files en masse."
function gitCloneGrpcSwift {
printf "\033c"
echo "🚀 Fetching github.com/grpc/grpc-swift.git"
rm -rf grpc-swift
git clone https://github.com/grpc/grpc-swift.git
cd grpc-swift
make
cd third_party
echo "🚀 Fetching github.com/apple/swift-protobuf.git"
git clone https://github.com/apple/swift-protobuf.git
echo "🚀 Fetching github.com/grpc/grpc.git"
git clone https://github.com/grpc/grpc.git
cd ..
cd Plugin
make
cd ..
cd ..
}
function installProtocDoc {
printf "\033c"
echo "🚀 Installing protoc doc generation"
brew update
brew install protobuf
export PROTOBUF_PREFIX=$(brew --prefix protobuf)
git clone https://github.com/estan/protoc-gen-doc.git
cd protoc-gen-doc
qmake
make
cp protoc-gen-doc /usr/local/bin/
cd ..
}
function installPythonProtobuffer {
printf "\033c"
echo "🚀 Installing GRPC with all plugins via brew";
curl -fsSL https://goo.gl/getgrpc | bash -s -- --with-plugins
}
function cloneTensorFlowRemoveAllFilesExceptProto {
printf "\033c"
echo "🚀 Fetching latest proto files from github.com/tensorflow/tensorflow.git"
#
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
find . -type f ! \( -name "*.proto" -o -name "*.pbtxt" \) -delete #remove any file not proto /pbtxt
find . -type d -empty -delete #remove empty directories
cd ..
}
function cloneMagentaFlowRemoveAllFilesExceptProto {
printf "\033c"
echo "🚀 Fetching latest proto files from github.com/tensorflow/magenta.git"
#
git clone https://github.com/tensorflow/magenta.git
cd magenta
find . -type f ! \( -name "*.proto" -o -name "*.pbtxt" \) -delete #remove any file not proto /pbtxt
find . -type d -empty -delete #remove empty directories
cd ..
}
function cloneTensorFlowServingRemoveAllFilesExceptProto {
printf "\033c"
echo "🚀 Fetching latest proto files github.com/tensorflow/serving.git"
#
git clone https://github.com/tensorflow/serving.git
cd serving
find . -type f ! \( -name "*.proto" -o -name "*.pbtxt" \) -delete #remove any file not proto pbtxt
find . -type d -empty -delete #remove empty directories
cd ..
}
# PROTOCO DOCUMENTATION
if ! which protoc-gen-doc >/dev/null; then
installProtocDoc
fi
if ! xcode-select -p >/dev/null; then
echo "🚀 Installing xcode command line tools";
sudo xcode-select --install
fi
printf "\033c"
if ! which grpc_python_plugin >/dev/null; then
installPythonProtobuffer
fi
if which protoc ==/dev/null; then
echo "🚬 warning: Protoc not installed"
exit
fi
# MAGENTA
if [ -d "magenta" ] ; then
read -p "⚠️ Existing magenta 🚀 directory detected - do you want to blow away 🔫 & fetch latest code ? [y/N]" CONFIRM;
if [ "$CONFIRM" == "y" ]; then
rm -rf magenta
cloneMagentaFlowRemoveAllFilesExceptProto
fi
else
cloneMagentaFlowRemoveAllFilesExceptProto
fi
# TENSORFLOW
if [ -d "tensorflow" ] ; then
read -p "⚠️ Existing tensorflow 🚀 directory detected - do you want to blow away 🔫 & fetch latest code ? [y/N]" CONFIRM;
if [ "$CONFIRM" == "y" ]; then
rm -rf tensorflow
cloneTensorFlowRemoveAllFilesExceptProto
fi
else
cloneTensorFlowRemoveAllFilesExceptProto
fi
# TENSORFLOW SERVING
if [ -d "serving" ] ; then
read -p "⚠️ Existing tensorflow serving ⛳️ directory detected - do you want to blow away 🔫 & fetch latest code ? [y/N]" CONFIRM;
if [ "$CONFIRM" == "y" ]; then
rm -rf serving
cloneTensorFlowServingRemoveAllFilesExceptProto
fi
else
cloneTensorFlowServingRemoveAllFilesExceptProto
fi
cp -R tensorflow/tensorflow serving
cp -R magenta/magenta/protobuf serving
printf "\033c"
printf "\n\n"
printf "\n\n"
echo "🚀 - Generate Tensorflow + Tensorflow Serving + magenta protobuf classes \n\n"
printf "\n\n"
echo "1 - Swift 🚀"
echo "1b - Swift - (todo exclude grpc) 🚀"
echo "2 - ObjC"
echo "3 - Python 🐍"
echo "4 - Ruby 💎"
echo "5 - Node 🎱"
echo "6 - c#"
echo "7 - c++"
echo "8 - Java 🦑"
echo "9 - Go 🐎"
printf "\n\n"
printf "[1], 2, 3, 4, 5, 6, 7, 8, 9"
printf "\n\n"
read -p "" CONDITION;
# clear screen
printf "\033c"
# create updated ops.pb file for all file generations.
for opdef_file_path in $(find ./serving -type f -name "op_def.proto" ); do
#https://github.com/LaurentMazare/tensorflow-ocaml/blob/master/src/gen_ops/how_to_update.txt
protoc \
--proto_path=serving \
--encode=tensorflow.OpList \
--proto_path serving $opdef_file_path \
< ./tensorflow/tensorflow/core/ops/ops.pbtxt > ops.pb
done
# Swift
if [ "$CONDITION" == "1" ] ; then
# GOOGLE GRPC SWIFT
if [ -d "grpc-swift" ] ; then
read -p "⚠️ Existing grpc-swift 📡 detected - do you want to blow away & fetch latest code ? [y/N]" CONFIRM;
if [ "$CONFIRM" == "y" ] ; then
rm -rf grpc-swift
gitCloneGrpcSwift
fi
else
gitCloneGrpcSwift
fi
fi
# Go
if [ "$CONDITION" == "9" ] ; then
go get google.golang.org/grpc
go get github.com/golang/protobuf/protoc-gen-go
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
# move golang files to this directory
rm -rf GoGenerated
mkdir GoGenerated
fi
if [ "$CONDITION" == "5" ] ; then
# move java files to this directory
rm -rf NodeGenerated
mkdir NodeGenerated
fi
if [ "$CONDITION" == "8" ] ; then
# move java files to this directory
rm -rf JavaGenerated
mkdir JavaGenerated
fi
for file_path in $(find ./serving -type f -name "*.proto" ); do
DIR=$(dirname $file_path)
file=$(basename $file_path)
test=$file_path
output_file=${test/.proto/.pb}
doc_output_file=${test/.proto/.md}
if [ "$CONDITION" == "1" ] ; then
# Swift
# https://github.com/grpc/grpc-swift/blob/574c47b6a39959ff4f2e3eda1874108f95e00fa9/Plugin/README.md
echo "\n ⛳️ protoc --plugin=./grpc-swift/Plugin/protoc-gen-swiftgrpc \ \n--proto_path=serving \ \n--swiftgrpc_out=. \ \n$file_path \n"
protoc --plugin=./grpc-swift/Plugin/protoc-gen-swiftgrpc \
--proto_path=serving \
--swiftgrpc_out=. \
$file_path
# \
# output swift file
echo "\n👾 protoc --plugin=./grpc-swift/Plugin/protoc-gen-swift --swift_opt=Visibility=Public \ \n--proto_path=serving \ \n--swift_out=. \ \n $file_path \n \n"
protoc --plugin=./grpc-swift/Plugin/protoc-gen-swift \
--swift_opt=Visibility=Public \
--proto_path=serving \
--swift_out="." \
$file_path
# output swift proto documentation
#echo "\n📚 protoc --proto_path=serving \ \n --doc_out=markdown,$doc_output_file:. \ \n $file_path "
#protoc \
#--proto_path=serving \
#--doc_out=markdown,$doc_output_file:"." \
#$file_path
# \No such file or directory - related to directory - https://github.com/estan/protoc-gen-doc/issues/267
fi
# Objective -C
if [ "$CONDITION" == "2" ] ; then
protoc --plugin=protoc-gen-grpc=$(which grpc_objective_c_plugin) \
--proto_path=serving \
--objc_out=. \
--grpc_out=. \
-I . \
-I $DIR \
#--doc_out=markdown,$html_output_file:"." \
#--descriptor_set_out $output_file \
$file_path
fi
# Python
if [ "$CONDITION" == "3" ] ; then
printf "\033c"
echo "\n🐍 protoc protoc --plugin=protoc-gen-grpc=$(which grpc_python_plugin)--proto_path=serving --python_out=. --grpc_out=. $file_path"
protoc --plugin=protoc-gen-grpc=$(which grpc_python_plugin) \
--proto_path=serving \
--python_out=. \
--grpc_out=. \
$file_path
fi
# Ruby
if [ "$CONDITION" == "4" ] ; then
echo "\n💎 protoc --plugin=protoc-gen-grpc=/usr/local/bin/grpc_ruby_plugin --proto_path=serving --ruby_out=./RubyGenerated/ --grpc_out=./RubyGenerated/ $file_path"
protoc --plugin=protoc-gen-grpc=$(which grpc_ruby_plugin) \
--proto_path=serving \
--ruby_out=./RubyGenerated/ \
--grpc_out=./RubyGenerated/ \
$file_path
fi
# Node
if [ "$CONDITION" == "5" ] ; then
protoc --plugin=protoc-gen-grpc=$(which grpc_node_plugin) \
--proto_path=serving \
--js_out=./NodeGenerated/ \
--grpc_out=./NodeGenerated/ \
$file_path
#--doc_out=markdown,$html_output_file:"." \
#--descriptor_set_out $output_file \
fi
# C#
if [ "$CONDITION" == "6" ] ; then
protoc --plugin=protoc-gen-grpc=$(which grpc_csharp_plugin) \
--proto_path=serving \
--csharp_out=. \
--grpc_out=. \
$file_path
#--doc_out=markdown,$html_output_file:"." \
#--descriptor_set_out $output_file \
fi
# C++
if [ "$CONDITION" == "7" ] ; then
echo "\n👾 protoc --proto_path=serving --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(which grpc_cpp_plugin) $file_path \n \n"
protoc --plugin=protoc-gen-grpc=$(which grpc_cpp_plugin) \
--proto_path=serving \
--cpp_out=. \
--grpc_out=. \
$file_path
fi
# Java
if [ "$CONDITION" == "8" ] ; then
#
echo "\n🦑 protoc --plugin=protoc-gen-grpc-java=$(which protoc-gen-grpc-java) --proto_path=serving --java_out=. --grpc-java_out=. $file_path "
protoc --plugin=protoc-gen-grpc-java=$(which protoc-gen-grpc-java) \
--proto_path=serving \
--java_out=./JavaGenerated/ \
--grpc-java_out=./JavaGenerated/ \
$file_path
fi
# Go
if [ "$CONDITION" == "9" ] ; then
echo "\n🐎 -I=. --plugin=$(which protoc-gen-go) --proto_path=serving --go_out=./GoGenerated/ $file_path "
protoc -I=. --plugin=$(which protoc-gen-go) \
--proto_path=serving \
--go_out=plugins=grpc:. \
$file_path
fi
done
if [ "$CONDITION" == "1" ] ; then
# move swift files to this directory
rm -rf Sources
mkdir Sources
read -p "add grpc service files? [y/N]" CONFIRM;
if [ "$CONFIRM" == "y" ] ; then
find . -maxdepth 1 -name "*.swift" -exec mv {} Sources \;
else
rm . -maxdepth 1 -name "*.swift" -exec mv {} Sources \;
fi
find ./tensorflow -name "*.swift" -exec mv {} Sources \;
find ./tensorflow_serving -name "*.swift" -exec mv {} Sources \;
find ./protobuf -name "*.swift" -exec mv {} Sources \;
fi
if [ "$CONDITION" == "3" ] ; then
# move swift files to this directory
rm -rf PythonGenerated
mkdir PythonGenerated
mv tensorflow tensorflow_serving PythonGenerated
echo "\n🐍 files can be found at PythonGenerated \n \n"
fi
if [ "$CONDITION" == "4" ] ; then
# move swift files to this directory
rm -rf RubyGenerated
mkdir RubyGenerated
mv tensorflow tensorflow_serving RubyGenerated
find . -maxdepth 1 -name "*.rb" -exec mv {} RubyGenerated \;
echo "\n⛳️ files can be found at RubyGenerated \n \n"
fi
if [ "$CONDITION" == "7" ] ; then
# move swift files to this directory
rm -rf CPPGenerated
mkdir CPPGenerated
mv tensorflow tensorflow_serving CPPGenerated
echo "\n⛳️ files can be found at CPPGenerated \n \n"
fi
if [ "$CONDITION" == "9" ] ; then
# move swift files to this directory
rm -rf GoGenerated
mkdir GoGenerated
mv tensorflow tensorflow_serving GoGenerated
echo "\n⛳️ files can be found at GoGenerated \n \n"
fi