generate.sh 2.9 KB

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