google.golang.org/grpc@v1.72.2/scripts/regenerate.sh (about)

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