regenerate.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. set -eu -o pipefail
  16. WORKDIR=$(mktemp -d)
  17. function finish {
  18. rm -rf "$WORKDIR"
  19. }
  20. trap finish EXIT
  21. export GOBIN=${WORKDIR}/bin
  22. export PATH=${GOBIN}:${PATH}
  23. mkdir -p ${GOBIN}
  24. echo "go install github.com/golang/protobuf/protoc-gen-go"
  25. (cd test/tools && go install github.com/golang/protobuf/protoc-gen-go)
  26. echo "go install cmd/protoc-gen-go-grpc"
  27. (cd cmd/protoc-gen-go-grpc && go install .)
  28. echo "git clone https://github.com/grpc/grpc-proto"
  29. git clone --quiet https://github.com/grpc/grpc-proto ${WORKDIR}/grpc-proto
  30. mkdir -p ${WORKDIR}/googleapis/google/rpc
  31. echo "curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto"
  32. curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > ${WORKDIR}/googleapis/google/rpc/code.proto
  33. mkdir -p ${WORKDIR}/out
  34. SOURCES=(
  35. ${WORKDIR}/googleapis/google/rpc/code.proto
  36. ${WORKDIR}/grpc-proto/grpc/binlog/v1/binarylog.proto
  37. ${WORKDIR}/grpc-proto/grpc/channelz/v1/channelz.proto
  38. ${WORKDIR}/grpc-proto/grpc/gcp/altscontext.proto
  39. ${WORKDIR}/grpc-proto/grpc/gcp/handshaker.proto
  40. ${WORKDIR}/grpc-proto/grpc/gcp/transport_security_common.proto
  41. ${WORKDIR}/grpc-proto/grpc/health/v1/health.proto
  42. ${WORKDIR}/grpc-proto/grpc/lb/v1/load_balancer.proto
  43. ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls.proto
  44. ${WORKDIR}/grpc-proto/grpc/service_config/service_config.proto
  45. $(git ls-files --exclude-standard --cached --others "*.proto")
  46. )
  47. OPTS=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config
  48. for src in ${SOURCES[@]}; do
  49. echo "protoc ${src}"
  50. protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},requireUnimplementedServers=false:${WORKDIR}/out \
  51. -I"." \
  52. -I${WORKDIR}/grpc-proto \
  53. -I${WORKDIR}/googleapis \
  54. ${src}
  55. done
  56. # The go_package option in grpc/lookup/v1/rls.proto doesn't match the
  57. # current location. Move it into the right place.
  58. mkdir -p ${WORKDIR}/out/google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1
  59. mv ${WORKDIR}/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* ${WORKDIR}/out/google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1
  60. # grpc_testingv3/testv3.pb.go is not re-generated because it was
  61. # intentionally generated by an older version of protoc-gen-go.
  62. rm ${WORKDIR}/out/google.golang.org/grpc/reflection/grpc_testingv3/*.pb.go
  63. # grpc/service_config/service_config.proto does not have a go_package option.
  64. cp ${WORKDIR}/out/grpc/service_config/service_config.pb.go internal/proto/grpc_service_config
  65. cp -R ${WORKDIR}/out/google.golang.org/grpc/* .