regenerate.sh (5136B)
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_testing_not_regenerate/*.pb.go is not re-generated, 31 # see grpc_testing_not_regenerate/README.md for details. 32 rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerate') 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 ${WORKDIR}/grpc-proto/grpc/reflection/v1alpha/reflection.proto 61 ${WORKDIR}/grpc-proto/grpc/reflection/v1/reflection.proto 62 ) 63 64 # Generates only the new gRPC Service symbols 65 SOURCES=( 66 $(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^\(profiling/proto/service.proto\|reflection/grpc_reflection_v1alpha/reflection.proto\)$') 67 ${WORKDIR}/grpc-proto/grpc/gcp/altscontext.proto 68 ${WORKDIR}/grpc-proto/grpc/gcp/handshaker.proto 69 ${WORKDIR}/grpc-proto/grpc/gcp/transport_security_common.proto 70 ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls.proto 71 ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls_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. 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/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\ 84 Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\ 85 Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\ 86 Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\ 87 Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\ 88 Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\ 89 Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\ 90 Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\ 91 Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\ 92 Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing 93 94 for src in ${SOURCES[@]}; do 95 echo "protoc ${src}" 96 protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS}:${WORKDIR}/out \ 97 -I"." \ 98 -I${WORKDIR}/grpc-proto \ 99 -I${WORKDIR}/googleapis \ 100 -I${WORKDIR}/protobuf/src \ 101 ${src} 102 done 103 104 for src in ${LEGACY_SOURCES[@]}; do 105 echo "protoc ${src}" 106 protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \ 107 -I"." \ 108 -I${WORKDIR}/grpc-proto \ 109 -I${WORKDIR}/googleapis \ 110 -I${WORKDIR}/protobuf/src \ 111 ${src} 112 done 113 114 # The go_package option in grpc/lookup/v1/rls.proto doesn't match the 115 # current location. Move it into the right place. 116 mkdir -p ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1 117 mv ${WORKDIR}/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1 118 119 # grpc_testing_not_regenerate/*.pb.go are not re-generated, 120 # see grpc_testing_not_regenerate/README.md for details. 121 rm ${WORKDIR}/out/google.golang.org/grpc/reflection/grpc_testing_not_regenerate/*.pb.go 122 123 cp -R ${WORKDIR}/out/google.golang.org/grpc/* .