blob: dfd3226a1d966d09a5ce34d3b77d763b6187f44d [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.
79OPTS=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config,Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core
80
81for src in ${SOURCES[@]}; do
82 echo "protoc ${src}"
83 protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS}:${WORKDIR}/out \
84 -I"." \
85 -I${WORKDIR}/grpc-proto \
86 -I${WORKDIR}/googleapis \
87 -I${WORKDIR}/protobuf/src \
88 -I${WORKDIR}/istio \
89 ${src}
90done
91
92for src in ${LEGACY_SOURCES[@]}; do
93 echo "protoc ${src}"
94 protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \
95 -I"." \
96 -I${WORKDIR}/grpc-proto \
97 -I${WORKDIR}/googleapis \
98 -I${WORKDIR}/protobuf/src \
99 -I${WORKDIR}/istio \
100 ${src}
101done
102
103# The go_package option in grpc/lookup/v1/rls.proto doesn't match the
104# current location. Move it into the right place.
105mkdir -p ${WORKDIR}/out/google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1
106mv ${WORKDIR}/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* ${WORKDIR}/out/google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1
107
108# grpc_testingv3/testv3.pb.go is not re-generated because it was
109# intentionally generated by an older version of protoc-gen-go.
110rm ${WORKDIR}/out/google.golang.org/grpc/reflection/grpc_testingv3/*.pb.go
111
112# grpc/service_config/service_config.proto does not have a go_package option.
113mv ${WORKDIR}/out/grpc/service_config/service_config.pb.go internal/proto/grpc_service_config
114
115# grpc/testing does not have a go_package option.
116mv ${WORKDIR}/out/grpc/testing/*.pb.go interop/grpc_testing/
117mv ${WORKDIR}/out/grpc/core/*.pb.go interop/grpc_testing/core/
118
119cp -R ${WORKDIR}/out/google.golang.org/grpc/* .