generate.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. #
  3. # Copyright 2024, gRPC Authors All rights reserved.
  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. set -eu
  17. here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  18. root="$here/../.."
  19. protoc=$(which protoc)
  20. # Checkout and build the plugins.
  21. build_dir=$(mktemp -d)
  22. git clone https://github.com/grpc/grpc-swift-protobuf --depth 1 "$build_dir"
  23. swift build --package-path "$build_dir" --product protoc-gen-swift
  24. swift build --package-path "$build_dir" --product protoc-gen-grpc-swift
  25. # Grab the plugin paths.
  26. bin_path=$(swift build --package-path "$build_dir" --show-bin-path)
  27. protoc_gen_swift="$bin_path/protoc-gen-swift"
  28. protoc_gen_grpc_swift="$bin_path/protoc-gen-grpc-swift"
  29. # Generates gRPC by invoking protoc with the gRPC Swift plugin.
  30. # Parameters:
  31. # - $1: .proto file
  32. # - $2: proto path
  33. # - $3: output path
  34. # - $4 onwards: options to forward to the plugin
  35. function generate_grpc {
  36. local proto=$1
  37. local args=("--plugin=$protoc_gen_grpc_swift" "--proto_path=${2}" "--grpc-swift_out=${3}")
  38. for option in "${@:4}"; do
  39. args+=("--grpc-swift_opt=$option")
  40. done
  41. invoke_protoc "${args[@]}" "$proto"
  42. }
  43. # Generates messages by invoking protoc with the Swift plugin.
  44. # Parameters:
  45. # - $1: .proto file
  46. # - $2: proto path
  47. # - $3: output path
  48. # - $4 onwards: options to forward to the plugin
  49. function generate_message {
  50. local proto=$1
  51. local args=("--plugin=$protoc_gen_swift" "--proto_path=$2" "--swift_out=$3")
  52. for option in "${@:4}"; do
  53. args+=("--swift_opt=$option")
  54. done
  55. invoke_protoc "${args[@]}" "$proto"
  56. }
  57. function invoke_protoc {
  58. # Setting -x when running the script produces a lot of output, instead boil
  59. # just echo out the protoc invocations.
  60. echo "$protoc" "$@"
  61. "$protoc" "$@"
  62. }
  63. #- TESTS ----------------------------------------------------------------------
  64. function generate_perf_test_services {
  65. local protos=(
  66. "$here/upstream/grpc/testing/payloads.proto"
  67. "$here/upstream/grpc/testing/control.proto"
  68. "$here/upstream/grpc/testing/messages.proto"
  69. "$here/upstream/grpc/testing/stats.proto"
  70. "$here/upstream/grpc/testing/benchmark_service.proto"
  71. "$here/upstream/grpc/testing/worker_service.proto"
  72. )
  73. local output="$root/IntegrationTests/grpc-performance-tests/Sources/Generated"
  74. generate_message "$here/upstream/grpc/core/stats.proto" "$here/upstream" "$output" "Visibility=Internal" "FileNaming=PathToUnderscores"
  75. for proto in "${protos[@]}"; do
  76. generate_message "$proto" "$here/upstream" "$output" "Visibility=Internal" "FileNaming=PathToUnderscores"
  77. if [ "$proto" == "$here/upstream/grpc/testing/worker_service.proto" ]; then
  78. generate_grpc "$proto" "$here/upstream" "$output" "Visibility=Internal" "Client=false" "FileNaming=PathToUnderscores"
  79. else
  80. generate_grpc "$proto" "$here/upstream" "$output" "Visibility=Internal" "FileNaming=PathToUnderscores"
  81. fi
  82. done
  83. }
  84. #------------------------------------------------------------------------------
  85. # Tests
  86. generate_perf_test_services