forked from grpc/grpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregenerate.sh
executable file
·131 lines (111 loc) · 5.34 KB
/
regenerate.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
#!/bin/bash
#
# Copyright 2020 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eu -o pipefail
WORKDIR="/tmp/grpc-go-tools"
mkdir -p "${WORKDIR}"
"$(dirname "${0}")"/install-protoc.sh ${WORKDIR}
export GOBIN="${WORKDIR}"/bin
export PATH="${GOBIN}:${PATH}"
mkdir -p "${GOBIN}"
echo "removing existing generated files..."
# grpc_testing_not_regenerated/*.pb.go is not re-generated,
# see grpc_testing_not_regenerated/README.md for details.
find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerated' | xargs rm -f || true
echo "Executing: go install google.golang.org/protobuf/cmd/protoc-gen-go..."
(cd test/tools && go install google.golang.org/protobuf/cmd/protoc-gen-go)
echo "Executing: go install cmd/protoc-gen-go-grpc..."
(cd cmd/protoc-gen-go-grpc && go install .)
echo "Pulling protos from https://github.com/grpc/grpc-proto..."
if [ -d "${WORKDIR}/grpc-proto" ]; then
(cd "${WORKDIR}/grpc-proto" && git pull)
else
git clone --quiet https://github.com/grpc/grpc-proto "${WORKDIR}/grpc-proto"
fi
echo "Pulling protos from https://github.com/protocolbuffers/protobuf..."
if [ -d "${WORKDIR}/protobuf" ]; then
(cd "${WORKDIR}/protobuf" && git pull)
else
git clone --quiet https://github.com/protocolbuffers/protobuf "${WORKDIR}/protobuf"
fi
# Pull in code.proto as a proto dependency
mkdir -p "${WORKDIR}/googleapis/google/rpc"
echo "Pulling code.proto from https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto..."
curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > "${WORKDIR}/googleapis/google/rpc/code.proto"
mkdir -p "${WORKDIR}/out"
# Generates sources without the embed requirement
LEGACY_SOURCES=(
"${WORKDIR}/grpc-proto/grpc/binlog/v1/binarylog.proto"
"${WORKDIR}/grpc-proto/grpc/channelz/v1/channelz.proto"
"${WORKDIR}/grpc-proto/grpc/health/v1/health.proto"
"${WORKDIR}/grpc-proto/grpc/lb/v1/load_balancer.proto"
profiling/proto/service.proto
"${WORKDIR}/grpc-proto/grpc/reflection/v1alpha/reflection.proto"
"${WORKDIR}/grpc-proto/grpc/reflection/v1/reflection.proto"
)
# Generates only the new gRPC Service symbols
SOURCES=(
$(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^profiling/proto/service.proto$')
"${WORKDIR}/grpc-proto/grpc/gcp/altscontext.proto"
"${WORKDIR}/grpc-proto/grpc/gcp/handshaker.proto"
"${WORKDIR}/grpc-proto/grpc/gcp/transport_security_common.proto"
"${WORKDIR}/grpc-proto/grpc/lookup/v1/rls.proto"
"${WORKDIR}/grpc-proto/grpc/lookup/v1/rls_config.proto"
"${WORKDIR}"/grpc-proto/grpc/testing/*.proto
"${WORKDIR}"/grpc-proto/grpc/core/*.proto
)
# These options of the form 'Mfoo.proto=bar' instruct the codegen to use an
# import path of 'bar' in the generated code when 'foo.proto' is imported in
# one of the sources.
#
# Note that the protos listed here are all for testing purposes. All protos to
# be used externally should have a go_package option (and they don't need to be
# listed here).
OPTS=Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\
Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\
Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing
for src in "${SOURCES[@]}"; do
echo "protoc ${src}"
protoc --go_out="${OPTS}:${WORKDIR}/out" --go-grpc_out="${OPTS}:${WORKDIR}/out" \
-I"." \
-I"${WORKDIR}/grpc-proto" \
-I"${WORKDIR}/googleapis" \
-I"${WORKDIR}/protobuf/src" \
"${src}"
done
for src in "${LEGACY_SOURCES[@]}"; do
echo "protoc ${src}"
protoc --go_out="${OPTS}:${WORKDIR}/out" --go-grpc_out="${OPTS},require_unimplemented_servers=false:${WORKDIR}/out" \
-I"." \
-I"${WORKDIR}/grpc-proto" \
-I"${WORKDIR}/googleapis" \
-I"${WORKDIR}/protobuf/src" \
"${src}"
done
# The go_package option in grpc/lookup/v1/rls.proto doesn't match the
# current location. Move it into the right place.
mkdir -p "${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1"
mv "${WORKDIR}"/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* "${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1"
# grpc_testing_not_regenerated/*.pb.go are not re-generated,
# see grpc_testing_not_regenerated/README.md for details.
rm "${WORKDIR}"/out/google.golang.org/grpc/testdata/grpc_testing_not_regenerated/*.pb.go
cp -R "${WORKDIR}"/out/google.golang.org/grpc/* .