blob: 58c802f8aec7af40bb3b9fe42089642028e0013a [file] [log] [blame]
khenaidoo5fc5cea2021-08-11 17:39:16 -04001#!/bin/bash
2# Copyright 2020 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -eu -o pipefail
17
18WORKDIR=$(mktemp -d)
19
20function finish {
21 rm -rf "$WORKDIR"
22}
23trap finish EXIT
24
25export GOBIN=${WORKDIR}/bin
26export PATH=${GOBIN}:${PATH}
27mkdir -p ${GOBIN}
28
29echo "remove existing generated files"
30# grpc_testingv3/testv3.pb.go is not re-generated because it was
31# intentionally generated by an older version of protoc-gen-go.
32rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testingv3/testv3.pb.go')
33
34echo "go install google.golang.org/protobuf/cmd/protoc-gen-go"
35(cd test/tools && go install google.golang.org/protobuf/cmd/protoc-gen-go)
36
37echo "go install cmd/protoc-gen-go-grpc"
38(cd cmd/protoc-gen-go-grpc && go install .)
39
40echo "git clone https://github.com/grpc/grpc-proto"
41git clone --quiet https://github.com/grpc/grpc-proto ${WORKDIR}/grpc-proto
42
43echo "git clone https://github.com/protocolbuffers/protobuf"
44git clone --quiet https://github.com/protocolbuffers/protobuf ${WORKDIR}/protobuf
45
46# Pull in code.proto as a proto dependency
47mkdir -p ${WORKDIR}/googleapis/google/rpc
48echo "curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto"
49curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > ${WORKDIR}/googleapis/google/rpc/code.proto
50
51mkdir -p ${WORKDIR}/out
52
53# Generates sources without the embed requirement
54LEGACY_SOURCES=(
55 ${WORKDIR}/grpc-proto/grpc/binlog/v1/binarylog.proto
56 ${WORKDIR}/grpc-proto/grpc/channelz/v1/channelz.proto
57 ${WORKDIR}/grpc-proto/grpc/health/v1/health.proto
58 ${WORKDIR}/grpc-proto/grpc/lb/v1/load_balancer.proto
59 profiling/proto/service.proto
60 reflection/grpc_reflection_v1alpha/reflection.proto
61)
62
63# Generates only the new gRPC Service symbols
64SOURCES=(
65 $(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^\(profiling/proto/service.proto\|reflection/grpc_reflection_v1alpha/reflection.proto\)$')
66 ${WORKDIR}/grpc-proto/grpc/gcp/altscontext.proto
67 ${WORKDIR}/grpc-proto/grpc/gcp/handshaker.proto
68 ${WORKDIR}/grpc-proto/grpc/gcp/transport_security_common.proto
69 ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls.proto
70 ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls_config.proto
71 ${WORKDIR}/grpc-proto/grpc/service_config/service_config.proto
72 ${WORKDIR}/grpc-proto/grpc/testing/*.proto
73 ${WORKDIR}/grpc-proto/grpc/core/*.proto
74)
75
76# These options of the form 'Mfoo.proto=bar' instruct the codegen to use an
77# import path of 'bar' in the generated code when 'foo.proto' is imported in
78# one of the sources.
khenaidoo257f3192021-12-15 16:46:37 -050079#
80# Note that the protos listed here are all for testing purposes. All protos to
81# be used externally should have a go_package option (and they don't need to be
82# listed here).
83OPTS=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config,\
84Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\
85Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\
86Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\
87Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\
88Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\
89Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\
90Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\
91Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\
92Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\
93Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing
khenaidoo5fc5cea2021-08-11 17:39:16 -040094
95for src in ${SOURCES[@]}; do
96 echo "protoc ${src}"
97 protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS}:${WORKDIR}/out \
98 -I"." \
99 -I${WORKDIR}/grpc-proto \
100 -I${WORKDIR}/googleapis \
101 -I${WORKDIR}/protobuf/src \
khenaidoo5fc5cea2021-08-11 17:39:16 -0400102 ${src}
103done
104
105for src in ${LEGACY_SOURCES[@]}; do
106 echo "protoc ${src}"
107 protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \
108 -I"." \
109 -I${WORKDIR}/grpc-proto \
110 -I${WORKDIR}/googleapis \
111 -I${WORKDIR}/protobuf/src \
khenaidoo5fc5cea2021-08-11 17:39:16 -0400112 ${src}
113done
114
115# The go_package option in grpc/lookup/v1/rls.proto doesn't match the
116# current location. Move it into the right place.
khenaidoo257f3192021-12-15 16:46:37 -0500117mkdir -p ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1
118mv ${WORKDIR}/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1
khenaidoo5fc5cea2021-08-11 17:39:16 -0400119
120# grpc_testingv3/testv3.pb.go is not re-generated because it was
121# intentionally generated by an older version of protoc-gen-go.
122rm ${WORKDIR}/out/google.golang.org/grpc/reflection/grpc_testingv3/*.pb.go
123
124# grpc/service_config/service_config.proto does not have a go_package option.
125mv ${WORKDIR}/out/grpc/service_config/service_config.pb.go internal/proto/grpc_service_config
126
127# grpc/testing does not have a go_package option.
128mv ${WORKDIR}/out/grpc/testing/*.pb.go interop/grpc_testing/
129mv ${WORKDIR}/out/grpc/core/*.pb.go interop/grpc_testing/core/
130
131cp -R ${WORKDIR}/out/google.golang.org/grpc/* .