...

Text file src/google.golang.org/grpc/regenerate.sh

Documentation: google.golang.org/grpc

     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
    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_testing_not_regenerate/*.pb.go is not re-generated,
    31# see grpc_testing_not_regenerate/README.md for details.
    32rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerate')
    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  ${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
    65SOURCES=(
    66  $(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^profiling/proto/service.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).
    83OPTS=Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\
    84Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\
    85Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\
    86Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\
    87Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\
    88Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\
    89Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\
    90Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\
    91Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\
    92Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing
    93
    94for src in ${SOURCES[@]}; do
    95  echo "protoc ${src}"
    96  protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},use_generic_streams_experimental=true:${WORKDIR}/out \
    97    -I"." \
    98    -I${WORKDIR}/grpc-proto \
    99    -I${WORKDIR}/googleapis \
   100    -I${WORKDIR}/protobuf/src \
   101    ${src}
   102done
   103
   104for 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}
   112done
   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.
   116mkdir -p ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1
   117mv ${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.
   121rm ${WORKDIR}/out/google.golang.org/grpc/reflection/test/grpc_testing_not_regenerate/*.pb.go
   122
   123cp -R ${WORKDIR}/out/google.golang.org/grpc/* .

View as plain text