khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 1 | #!/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 | |
| 16 | set -eu -o pipefail |
| 17 | |
| 18 | WORKDIR=$(mktemp -d) |
| 19 | |
| 20 | function finish { |
| 21 | rm -rf "$WORKDIR" |
| 22 | } |
| 23 | trap finish EXIT |
| 24 | |
| 25 | export GOBIN=${WORKDIR}/bin |
| 26 | export PATH=${GOBIN}:${PATH} |
| 27 | mkdir -p ${GOBIN} |
| 28 | |
| 29 | echo "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. |
| 32 | rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testingv3/testv3.pb.go') |
| 33 | |
| 34 | echo "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 | |
| 37 | echo "go install cmd/protoc-gen-go-grpc" |
| 38 | (cd cmd/protoc-gen-go-grpc && go install .) |
| 39 | |
| 40 | echo "git clone https://github.com/grpc/grpc-proto" |
| 41 | git clone --quiet https://github.com/grpc/grpc-proto ${WORKDIR}/grpc-proto |
| 42 | |
| 43 | echo "git clone https://github.com/protocolbuffers/protobuf" |
| 44 | git clone --quiet https://github.com/protocolbuffers/protobuf ${WORKDIR}/protobuf |
| 45 | |
| 46 | # Pull in code.proto as a proto dependency |
| 47 | mkdir -p ${WORKDIR}/googleapis/google/rpc |
| 48 | echo "curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto" |
| 49 | curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > ${WORKDIR}/googleapis/google/rpc/code.proto |
| 50 | |
| 51 | mkdir -p ${WORKDIR}/out |
| 52 | |
| 53 | # Generates sources without the embed requirement |
| 54 | LEGACY_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 |
| 64 | SOURCES=( |
| 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. |
khenaidoo | 257f319 | 2021-12-15 16:46:37 -0500 | [diff] [blame] | 79 | # |
| 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). |
| 83 | OPTS=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config,\ |
| 84 | Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\ |
| 85 | Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 86 | Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 87 | Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 88 | Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 89 | Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 90 | Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 91 | Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 92 | Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\ |
| 93 | Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 94 | |
| 95 | for 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 \ |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 102 | ${src} |
| 103 | done |
| 104 | |
| 105 | for 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 \ |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 112 | ${src} |
| 113 | done |
| 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. |
khenaidoo | 257f319 | 2021-12-15 16:46:37 -0500 | [diff] [blame] | 117 | mkdir -p ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1 |
| 118 | mv ${WORKDIR}/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1 |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 119 | |
| 120 | # grpc_testingv3/testv3.pb.go is not re-generated because it was |
| 121 | # intentionally generated by an older version of protoc-gen-go. |
| 122 | rm ${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. |
| 125 | mv ${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. |
| 128 | mv ${WORKDIR}/out/grpc/testing/*.pb.go interop/grpc_testing/ |
| 129 | mv ${WORKDIR}/out/grpc/core/*.pb.go interop/grpc_testing/core/ |
| 130 | |
| 131 | cp -R ${WORKDIR}/out/google.golang.org/grpc/* . |