regenerate.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "remove existing generated files"
  25. # grpc_testing_not_regenerate/*.pb.go is not re-generated,
  26. # see grpc_testing_not_regenerate/README.md for details.
  27. rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerate')
  28. echo "go install google.golang.org/protobuf/cmd/protoc-gen-go"
  29. (cd test/tools && go install google.golang.org/protobuf/cmd/protoc-gen-go)
  30. echo "go install cmd/protoc-gen-go-grpc"
  31. (cd cmd/protoc-gen-go-grpc && go install .)
  32. echo "git clone https://github.com/grpc/grpc-proto"
  33. git clone --quiet https://github.com/grpc/grpc-proto ${WORKDIR}/grpc-proto
  34. echo "git clone https://github.com/protocolbuffers/protobuf"
  35. git clone --quiet https://github.com/protocolbuffers/protobuf ${WORKDIR}/protobuf
  36. # Pull in code.proto as a proto dependency
  37. mkdir -p ${WORKDIR}/googleapis/google/rpc
  38. echo "curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto"
  39. curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > ${WORKDIR}/googleapis/google/rpc/code.proto
  40. mkdir -p ${WORKDIR}/out
  41. # Generates sources without the embed requirement
  42. LEGACY_SOURCES=(
  43. ${WORKDIR}/grpc-proto/grpc/binlog/v1/binarylog.proto
  44. ${WORKDIR}/grpc-proto/grpc/channelz/v1/channelz.proto
  45. ${WORKDIR}/grpc-proto/grpc/health/v1/health.proto
  46. ${WORKDIR}/grpc-proto/grpc/lb/v1/load_balancer.proto
  47. profiling/proto/service.proto
  48. ${WORKDIR}/grpc-proto/grpc/reflection/v1alpha/reflection.proto
  49. ${WORKDIR}/grpc-proto/grpc/reflection/v1/reflection.proto
  50. )
  51. # Generates only the new gRPC Service symbols
  52. SOURCES=(
  53. $(git ls-files --exclude-standard --cached --others "*.proto" | grep -v '^\(profiling/proto/service.proto\|reflection/grpc_reflection_v1alpha/reflection.proto\)$')
  54. ${WORKDIR}/grpc-proto/grpc/gcp/altscontext.proto
  55. ${WORKDIR}/grpc-proto/grpc/gcp/handshaker.proto
  56. ${WORKDIR}/grpc-proto/grpc/gcp/transport_security_common.proto
  57. ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls.proto
  58. ${WORKDIR}/grpc-proto/grpc/lookup/v1/rls_config.proto
  59. ${WORKDIR}/grpc-proto/grpc/testing/*.proto
  60. ${WORKDIR}/grpc-proto/grpc/core/*.proto
  61. )
  62. # These options of the form 'Mfoo.proto=bar' instruct the codegen to use an
  63. # import path of 'bar' in the generated code when 'foo.proto' is imported in
  64. # one of the sources.
  65. #
  66. # Note that the protos listed here are all for testing purposes. All protos to
  67. # be used externally should have a go_package option (and they don't need to be
  68. # listed here).
  69. OPTS=Mgrpc/core/stats.proto=google.golang.org/grpc/interop/grpc_testing/core,\
  70. Mgrpc/testing/benchmark_service.proto=google.golang.org/grpc/interop/grpc_testing,\
  71. Mgrpc/testing/stats.proto=google.golang.org/grpc/interop/grpc_testing,\
  72. Mgrpc/testing/report_qps_scenario_service.proto=google.golang.org/grpc/interop/grpc_testing,\
  73. Mgrpc/testing/messages.proto=google.golang.org/grpc/interop/grpc_testing,\
  74. Mgrpc/testing/worker_service.proto=google.golang.org/grpc/interop/grpc_testing,\
  75. Mgrpc/testing/control.proto=google.golang.org/grpc/interop/grpc_testing,\
  76. Mgrpc/testing/test.proto=google.golang.org/grpc/interop/grpc_testing,\
  77. Mgrpc/testing/payloads.proto=google.golang.org/grpc/interop/grpc_testing,\
  78. Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing
  79. for src in ${SOURCES[@]}; do
  80. echo "protoc ${src}"
  81. protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS}:${WORKDIR}/out \
  82. -I"." \
  83. -I${WORKDIR}/grpc-proto \
  84. -I${WORKDIR}/googleapis \
  85. -I${WORKDIR}/protobuf/src \
  86. ${src}
  87. done
  88. for src in ${LEGACY_SOURCES[@]}; do
  89. echo "protoc ${src}"
  90. protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \
  91. -I"." \
  92. -I${WORKDIR}/grpc-proto \
  93. -I${WORKDIR}/googleapis \
  94. -I${WORKDIR}/protobuf/src \
  95. ${src}
  96. done
  97. # The go_package option in grpc/lookup/v1/rls.proto doesn't match the
  98. # current location. Move it into the right place.
  99. mkdir -p ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1
  100. mv ${WORKDIR}/out/google.golang.org/grpc/lookup/grpc_lookup_v1/* ${WORKDIR}/out/google.golang.org/grpc/internal/proto/grpc_lookup_v1
  101. # grpc_testing_not_regenerate/*.pb.go are not re-generated,
  102. # see grpc_testing_not_regenerate/README.md for details.
  103. rm ${WORKDIR}/out/google.golang.org/grpc/reflection/grpc_testing_not_regenerate/*.pb.go
  104. cp -R ${WORKDIR}/out/google.golang.org/grpc/* .