1#!/bin/bash 2# Copyright 2015 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# Don't run this script standalone. Instead, run from the repository root: 17# ./tools/run_tests/run_tests.py -l objc 18 19set -ev 20 21cd $(dirname $0) 22 23# Run the tests server. 24 25ROOT_DIR=../../.. 26BAZEL=$ROOT_DIR/tools/bazel 27PROTOC=$ROOT_DIR/bazel-bin/external/com_google_protobuf/protoc 28PLUGIN=$ROOT_DIR/bazel-bin/src/compiler/grpc_objective_c_plugin 29RUNTIME_IMPORT_PREFIX=prefix/dir/ 30 31[ -f $PROTOC ] && [ -f $PLUGIN ] || { 32 BAZEL build @com_google_protobuf//:protoc //src/compiler:grpc_objective_c_plugin 33} 34 35rm -rf RemoteTestClient/*pb* 36 37$PROTOC \ 38 --plugin=protoc-gen-grpc=$PLUGIN \ 39 --objc_out=RemoteTestClient \ 40 --grpc_out=grpc_local_import_prefix=$RUNTIME_IMPORT_PREFIX,runtime_import_prefix=$RUNTIME_IMPORT_PREFIX:RemoteTestClient \ 41 -I $ROOT_DIR \ 42 -I ../../../third_party/protobuf/src \ 43 $ROOT_DIR/src/objective-c/examples/RemoteTestClient/*.proto 44 45# Verify the "runtime_import_prefix" option 46# Verify the output proto filename 47[ -e ./RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m ] || { 48 echo >&2 "protoc outputs wrong filename." 49 exit 1 50} 51 52# Verify paths of protobuf WKTs in generated code contain runtime import prefix. 53[ "`cat RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m | 54 egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'GPBEmpty\.pbobjc\.h'`" ] || { 55 echo >&2 "protoc generated import with wrong filename." 56 exit 1 57} 58 59# Verify paths of non WKTs protos in generated code don't contain runtime import prefix. 60[ "`cat RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m | 61 egrep '.*\Messages.pbobjc.h"$' | 62 egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"`" ] && { 63 echo >&2 "protoc generated import with wrong filename." 64 exit 1 65} 66 67# Verify the "grpc_local_import_directory" option 68# Verify system files are imported in a "local" way in header files. 69[ "`cat RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.h | 70 egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'/ProtoRPC/.*\.h'`"] || { 71 echo >&2 "grpc system files should be imported with full paths." 72} 73 74# Verify system files are imported in a "local" way in source files. 75[ "`cat RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m | 76 egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'/ProtoRPC/.*\.h'`"] || { 77 echo >&2 "grpc system files should be imported with full paths." 78} 79 80# Run one extra command to clear $? before exiting the script to prevent 81# failing even when tests pass. 82echo "Plugin option tests passed." 83