-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathprotogen.sh
executable file
·109 lines (94 loc) · 3.56 KB
/
protogen.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
#!/bin/bash
CUR_DIR="$(pwd)"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ENVOY_REPO="github.com/envoyproxy/data-plane-api"
ENVOY_REPO_PKG="go.aporeto.io/enforcerd/trireme-lib/third_party/generated/envoyproxy/data-plane-api"
PB_OUT="${DIR}/third_party/generated/envoyproxy/data-plane-api"
# gogofaster and gogoslick don't work unfortunately
# also, they currently don't work with validate
PB_GENERATOR="gogofast"
PROTOC="$(which protoc)"
if [ $? -ne 0 ] ; then
echo "ERROR: protoc needs to be installed and in the PATH" 1>&2
exit 2
fi
PB_GENERATOR_BIN="$(which protoc-gen-${PB_GENERATOR})"
if [ $? -ne 0 ] ; then
echo "ERROR: protoc-gen-${PB_GENERATOR} needs to be installed and in the PATH" 1>&2
exit 2
fi
echo "Protobuf compilers are at:"
echo "PROTOC=${PROTOC}"
echo "PB_GENERATOR_BIN=${PB_GENERATOR_BIN}"
echo
echo "Ensuring output folder exists: ${PB_OUT}"
mkdir -v -p ${PB_OUT}
echo
echo "Updating / Downloading necessary packages and repo..."
go get -u -v google.golang.org/grpc
echo
go get -u -v github.com/gogo/protobuf/types
echo
go get -u -v github.com/gogo/googleapis/google/rpc
echo
go get -u -v github.com/gogo/googleapis/google/api
echo
go get -u -v github.com/envoyproxy/protoc-gen-validate
echo "NOTE: it is okay for this to fail, there is no go code in here"
go get -v -u -d ${ENVOY_REPO}
echo
# useful when you need to find out dependencies and things for mapping
# --descriptor_set_out=${PB_OUT}/${input}.descriptor_set \
# --include_imports \
# --dependency_out=${PB_OUT}/${input}.dependencies \
# validate currently doesn't work
# --validate_out=lang=go:${PB_OUT} \
PROTOC_CMD="
${PROTOC} \
-I${GOPATH:-${HOME/go}}/src/${ENVOY_REPO} \
-I${GOPATH:-${HOME/go}}/src/github.com/gogo/protobuf/protobuf \
-I${GOPATH:-${HOME/go}}/src/github.com/gogo/protobuf \
-I${GOPATH:-${HOME/go}}/src/github.com/gogo/googleapis \
-I${GOPATH:-${HOME/go}}/src/github.com/envoyproxy/protoc-gen-validate \
--${PB_GENERATOR}_out=plugins=\
grpc,\
Menvoy/type/percent.proto=${ENVOY_REPO_PKG}/envoy/type,\
Menvoy/type/http_status.proto=${ENVOY_REPO_PKG}/envoy/type,\
Menvoy/api/v2/discovery.proto=${ENVOY_REPO_PKG}/envoy/api/v2,\
Menvoy/api/v2/core/address.proto=${ENVOY_REPO_PKG}/envoy/api/v2/core,\
Menvoy/api/v2/core/base.proto=${ENVOY_REPO_PKG}/envoy/api/v2/core,\
Menvoy/api/v2/core/http_uri.proto=${ENVOY_REPO_PKG}/envoy/api/v2/core,\
Mgoogle/rpc/status.proto=github.com/gogo/googleapis/google/rpc,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types\
:${PB_OUT} \
"
echo "Changing working directory to the envoy repo..."
cd ${GOPATH:-${HOME/go}}/src/${ENVOY_REPO}
echo "running protoc for dependencies from envoy/type..."
$PROTOC_CMD \
envoy/type/http_status.proto \
envoy/type/percent.proto
echo
echo "running protoc for dependencies from envoy/api/v2/core..."
$PROTOC_CMD \
envoy/api/v2/core/address.proto \
envoy/api/v2/core/base.proto \
envoy/api/v2/core/http_uri.proto
echo
echo "running protoc for ext_authz_v2..."
$PROTOC_CMD \
envoy/service/auth/v2/attribute_context.proto \
envoy/service/auth/v2/external_auth.proto
echo
echo "running protoc for discovery..."
$PROTOC_CMD \
envoy/api/v2/discovery.proto
echo "running protoc for disovery services..."
$PROTOC_CMD \
envoy/service/discovery/v2/sds.proto
cd ${CUR_DIR}