-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_proto.sh
executable file
·79 lines (70 loc) · 2.44 KB
/
generate_proto.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
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s nullglob
root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
xds=${root}/vendor/github.com/envoyproxy/data-plane-api
echo "Expecting protoc version >= 3.5.0:"
protoc=$(which protoc)
$protoc --version
imports=(
${xds}
"${root}/vendor/github.com/lyft/protoc-gen-validate"
"${root}/vendor/github.com/gogo/protobuf"
"${root}/vendor/github.com/gogo/protobuf/protobuf"
"${root}/vendor/istio.io/gogo-genproto/prometheus"
"${root}/vendor/istio.io/gogo-genproto/googleapis"
"${root}/vendor/istio.io/gogo-genproto/opencensus/proto/trace"
)
protocarg=""
for i in "${imports[@]}"
do
protocarg+="--proto_path=$i "
done
mappings=(
"google/api/annotations.proto=github.com/gogo/googleapis/google/api"
"google/api/http.proto=github.com/gogo/googleapis/google/api"
"google/rpc/code.proto=github.com/gogo/googleapis/google/rpc"
"google/rpc/error_details.proto=github.com/gogo/googleapis/google/rpc"
"google/rpc/status.proto=github.com/gogo/googleapis/google/rpc"
"google/protobuf/any.proto=github.com/gogo/protobuf/types"
"google/protobuf/duration.proto=github.com/gogo/protobuf/types"
"google/protobuf/empty.proto=github.com/gogo/protobuf/types"
"google/protobuf/struct.proto=github.com/gogo/protobuf/types"
"google/protobuf/timestamp.proto=github.com/gogo/protobuf/types"
"google/protobuf/wrappers.proto=github.com/gogo/protobuf/types"
"gogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto"
"trace.proto=istio.io/gogo-genproto/opencensus/proto/trace"
"metrics.proto=istio.io/gogo-genproto/prometheus"
)
gogoarg="plugins=grpc"
# assign importmap for canonical protos
for mapping in "${mappings[@]}"
do
gogoarg+=",M$mapping"
done
# assign importmap for all referenced protos in data-plane-api
for path in $(find ${xds}/envoy -type d)
do
path_protos=(${path}/*.proto)
if [[ ${#path_protos[@]} > 0 ]]
then
for path_proto in "${path_protos[@]}"
do
mapping=${path_proto##${xds}/}=github.com/morvencao/kube-envoy-xds/${path##${xds}/}
gogoarg+=",M$mapping"
done
fi
done
for path in $(find ${xds}/envoy -type d)
do
path_protos=(${path}/*.proto)
if [[ ${#path_protos[@]} > 0 ]]
then
echo "Generating protos ${path} ..."
$protoc ${protocarg} ${path}/*.proto \
--plugin=protoc-gen-gogofast=${root}/bin/gogofast --gogofast_out=${gogoarg}:. \
--plugin=protoc-gen-validate=${root}/bin/validate --validate_out="lang=gogo:."
fi
done