|
| 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 | + |
| 17 | +set -eu |
| 18 | + |
| 19 | +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 20 | +root="$here/../.." |
| 21 | +protoc=$(which protoc) |
| 22 | + |
| 23 | +# Build the protoc plugins. |
| 24 | +swift build -c release --product protoc-gen-swift |
| 25 | +swift build -c release --product protoc-gen-grpc-swift |
| 26 | + |
| 27 | +# Grab the plugin paths. |
| 28 | +bin_path=$(swift build -c release --show-bin-path) |
| 29 | +protoc_gen_swift="$bin_path/protoc-gen-swift" |
| 30 | +protoc_generate_grpc_swift="$bin_path/protoc-gen-grpc-swift" |
| 31 | + |
| 32 | +# Generates gRPC by invoking protoc with the gRPC Swift plugin. |
| 33 | +# Parameters: |
| 34 | +# - $1: .proto file |
| 35 | +# - $2: proto path |
| 36 | +# - $3: output path |
| 37 | +# - $4 onwards: options to forward to the plugin |
| 38 | +function generate_grpc { |
| 39 | + local proto=$1 |
| 40 | + local args=("--plugin=$protoc_generate_grpc_swift" "--proto_path=${2}" "--grpc-swift_out=${3}") |
| 41 | + |
| 42 | + for option in "${@:4}"; do |
| 43 | + args+=("--grpc-swift_opt=$option") |
| 44 | + done |
| 45 | + |
| 46 | + invoke_protoc "${args[@]}" "$proto" |
| 47 | +} |
| 48 | + |
| 49 | +# Generates messages by invoking protoc with the Swift plugin. |
| 50 | +# Parameters: |
| 51 | +# - $1: .proto file |
| 52 | +# - $2: proto path |
| 53 | +# - $3: output path |
| 54 | +# - $4 onwards: options to forward to the plugin |
| 55 | +function generate_message { |
| 56 | + local proto=$1 |
| 57 | + local args=("--plugin=$protoc_gen_swift" "--proto_path=$2" "--swift_out=$3") |
| 58 | + |
| 59 | + for option in "${@:4}"; do |
| 60 | + args+=("--swift_opt=$option") |
| 61 | + done |
| 62 | + |
| 63 | + invoke_protoc "${args[@]}" "$proto" |
| 64 | +} |
| 65 | + |
| 66 | +function invoke_protoc { |
| 67 | + # Setting -x when running the script produces a lot of output, instead boil |
| 68 | + # just echo out the protoc invocations. |
| 69 | + echo "$protoc" "$@" |
| 70 | + "$protoc" "$@" |
| 71 | +} |
| 72 | + |
| 73 | +#------------------------------------------------------------------------------ |
| 74 | + |
| 75 | +function generate_interop_test_service { |
| 76 | + local protos=( |
| 77 | + "$here/tests/interoperability/src/proto/grpc/testing/empty_service.proto" |
| 78 | + "$here/tests/interoperability/src/proto/grpc/testing/empty.proto" |
| 79 | + "$here/tests/interoperability/src/proto/grpc/testing/messages.proto" |
| 80 | + "$here/tests/interoperability/src/proto/grpc/testing/test.proto" |
| 81 | + ) |
| 82 | + local output="$root/Sources/GRPCInteropTests/Generated" |
| 83 | + |
| 84 | + for proto in "${protos[@]}"; do |
| 85 | + generate_message "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "FileNaming=DropPath" "UseAccessLevelOnImports=true" |
| 86 | + generate_grpc "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "Server=true" "FileNaming=DropPath" "UseAccessLevelOnImports=true" |
| 87 | + done |
| 88 | +} |
| 89 | + |
| 90 | +function generate_health_service { |
| 91 | + local proto="$here/upstream/grpc/health/v1/health.proto" |
| 92 | + local output="$root/Sources/GRPCHealthService/Generated" |
| 93 | + |
| 94 | + generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true" |
| 95 | + generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "UseAccessLevelOnImports=true" |
| 96 | +} |
| 97 | + |
| 98 | +#------------------------------------------------------------------------------ |
| 99 | + |
| 100 | +# Interoperability tests |
| 101 | +generate_interop_test_service |
| 102 | + |
| 103 | +# Health service |
| 104 | +generate_health_service |
0 commit comments