This repository has been archived by the owner on Nov 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.sh
executable file
·163 lines (131 loc) · 4.29 KB
/
generate.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
#!/usr/bin/env bash
current_dir=$(pwd)
echo "${currdir}"
protobuf_dependencies="
protoc
"
#
cita_node_intf_files="
blockchain.proto
snapshot.proto
"
cita_component_intf_files="
auth.proto
citacode.proto
consensus.proto
request.proto
communication.proto
executor.proto
response.proto
sync.proto
"
cita_grpc_intf_files="
citacode.proto
executor.proto
"
function check_dependencies {
local l_dependencies="$1"
for bin in ${l_dependencies}; do
if [ ! -x "$(which ${bin})" ]; then
echo -e "\033[31m[Error] Please check if you have installed \033[43m${bin}\033[0m in your \$PATH. \033[0m"
echo "See dependense decription in README.md for more detail!"
exit 1
fi
done
}
go_dependencies="
${protobuf_dependencies}
protoc-gen-go
"
function gen_go {
check_dependencies "${go_dependencies}"
echo -e "Generate\033[33m go\033[0m files from protos:"
# Support for go sdk, needs only cita_node_intf_files for now.
for protofile in ${cita_node_intf_files}; do
rm -f ${protofile/%.proto/.go.pb}
protoc --go_out=plugins=grpcserial:${current_dir}/go -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/.go.pb}"
done
echo -e "End generate go files, and results write to \$current_dir/go.\n"
}
js_dependencies="
${protobuf_dependencies}
"
function gen_js {
check_dependencies "${js_dependencies}"
echo -e "Generate\033[33m js\033[0m files from protos:"
# Support for js sdk, needs only cita_node_intf_files for now.
for protofile in ${cita_node_intf_files}; do
rm -f ${protofile/%.proto/_pb.js}
protoc --js_out=import_style=commonjs,binary:${current_dir}/js -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/_pb.js}"
done
echo -e "End generate js files, and results write to \$current_dir/js.\n"
}
java_dependencies="
${protobuf_dependencies}
"
function gen_java {
check_dependencies "${java_dependencies}"
echo -e "Generate\033[33m java\033[0m files from protos:"
# Support for java sdk, needs only cita_node_intf_files for now.
for protofile in ${cita_node_intf_files}; do
rm -f ${protofile/%.proto/.java}
protoc --java_out=${current_dir}/java -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/.java}"
done
echo -e "End generate java files, and results write to \$current_dir/java.\n"
}
python_dependencies="
${protobuf_dependencies}
"
function gen_python {
check_dependencies "${python_dependencies}"
echo -e "Generate\033[33m python\033[0m files from protos:"
# Support for python sdk, needs only cita_node_intf_files for now.
for protofile in ${cita_node_intf_files}; do
rm -f ${protofile/%.proto/_pb2.py}
protoc --python_out=${current_dir}/python -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/_pb2.py}"
done
echo -e "End generate python files, and results write to \$current_dir/python.\n"
}
rust_dependencies="
${protobuf_dependencies}
protoc-gen-rust
protoc-gen-rust-grpc
"
function gen_rust {
check_dependencies "${rust_dependencies}"
echo -e "Generate\033[33m rust\033[0m files from protos:"
# Support for rust sdk, needs only cita_node_intf_files for now.
for protofile in ${cita_node_intf_files}; do
rm -f ${protofile/%.proto/.rs}
protoc --rust_out=${current_dir}/rust -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/.rs}"
done
for protofile in ${cita_component_intf_files}; do
rm -f ${protofile/%.proto/.rs}
protoc --rust_out=${current_dir}/rust -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/.rs}"
done
# Generate grpc
for protofile in ${cita_grpc_intf_files}; do
rm -f ${protofile/%.proto/_grpc.rs}
protoc --rust-grpc_out=${current_dir}/rust -Iprotos ${protofile}
echo " ${protofile} -> ${protofile/%.proto/_grpc.rs}"
done
# Need to prefix the codes generated by proto compiler
cd rust
./prefix.sh
cd ..
echo -e "End generate rust files, and results write to \$current_dir/rust.\n"
}
function main {
gen_go
gen_js
gen_java
gen_python
gen_rust
}
main