| 1 |
#!/bin/bash |
| 2 |
# Copyright 2022 The 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 |
|
| 16 |
# Run this script via bazel test |
| 17 |
# It expects that protoc and grpc_objective_c_plugin have already been built. |
| 18 |
|
| 19 |
set -ev |
| 20 |
|
| 21 |
# protoc and grpc_objective_c_plugin binaries are supplied as "data" in bazel |
| 22 |
PROTOC=./external/com_google_protobuf/protoc |
| 23 |
PLUGIN=./src/compiler/grpc_objective_c_plugin |
| 24 |
WELL_KNOWN_PROTOS_PATH=external/com_google_protobuf/src |
| 25 |
RUNTIME_IMPORT_PREFIX=prefix/dir/ |
| 26 |
|
| 27 |
PROTO_OUT=./proto_out |
| 28 |
rm -rf ${PROTO_OUT} |
| 29 |
mkdir -p ${PROTO_OUT} |
| 30 |
|
| 31 |
$PROTOC \ |
| 32 |
--plugin=protoc-gen-grpc=$PLUGIN \ |
| 33 |
--objc_out=${PROTO_OUT} \ |
| 34 |
--grpc_out=grpc_local_import_prefix=$RUNTIME_IMPORT_PREFIX,runtime_import_prefix=$RUNTIME_IMPORT_PREFIX:${PROTO_OUT} \ |
| 35 |
-I . \ |
| 36 |
-I ${WELL_KNOWN_PROTOS_PATH} \ |
| 37 |
src/objective-c/tests/RemoteTestClient/*.proto |
| 38 |
|
| 39 |
# TODO(jtattermusch): rewrite the tests to make them more readable. |
| 40 |
# Also, the way they are written, they need one extra command to run in order to |
| 41 |
# clear $? after they run (see end of this script) |
| 42 |
|
| 43 |
# Verify the "runtime_import_prefix" option |
| 44 |
# Verify the output proto filename |
| 45 |
[ -e ${PROTO_OUT}/src/objective-c/tests/RemoteTestClient/Test.pbrpc.m ] || { |
| 46 |
echo >&2 "protoc outputs wrong filename." |
| 47 |
exit 1 |
| 48 |
} |
| 49 |
|
| 50 |
# Verify paths of protobuf WKTs in generated code contain runtime import prefix. |
| 51 |
[ "`cat ${PROTO_OUT}/src/objective-c/tests/RemoteTestClient/Test.pbrpc.m | |
| 52 |
egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'GPBEmpty\.pbobjc\.h'`" ] || { |
| 53 |
echo >&2 "protoc generated import with wrong filename." |
| 54 |
exit 1 |
| 55 |
} |
| 56 |
|
| 57 |
# Verify paths of non WKTs protos in generated code don't contain runtime import prefix. |
| 58 |
[ "`cat ${PROTO_OUT}/src/objective-c/tests/RemoteTestClient/Test.pbrpc.m | |
| 59 |
egrep '.*\Messages.pbobjc.h"$' | |
| 60 |
egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"`" ] && { |
| 61 |
echo >&2 "protoc generated import with wrong filename." |
| 62 |
exit 1 |
| 63 |
} |
| 64 |
|
| 65 |
# Verify the "grpc_local_import_directory" option |
| 66 |
# Verify system files are imported in a "local" way in header files. |
| 67 |
[ "`cat ${PROTO_OUT}/src/objective-c/tests/RemoteTestClient/Test.pbrpc.h | |
| 68 |
egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'/ProtoRPC/.*\.h'`"] || { |
| 69 |
echo >&2 "grpc system files should be imported with full paths." |
| 70 |
} |
| 71 |
|
| 72 |
# Verify system files are imported in a "local" way in source files. |
| 73 |
[ "`cat ${PROTO_OUT}/src/objective-c/tests/RemoteTestClient/Test.pbrpc.m | |
| 74 |
egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'/ProtoRPC/.*\.h'`"] || { |
| 75 |
echo >&2 "grpc system files should be imported with full paths." |
| 76 |
} |
| 77 |
|
| 78 |
# Run one extra command to clear $? before exiting the script to prevent |
| 79 |
# failing even when tests pass. |
| 80 |
echo "Plugin option tests passed." |