Merge pull request #23475 from yulin-liang/local_import_prefix

Objc support grpc files import override
pull/23555/head
yulin liang 4 years ago committed by GitHub
commit f87e635d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      src/compiler/objective_c_plugin.cc
  2. 16
      src/objective-c/tests/run_plugin_option_tests.sh

@ -90,8 +90,10 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
return true; return true;
} }
bool grpc_local_import;
::std::string framework; ::std::string framework;
::std::string pb_runtime_import_prefix; ::std::string pb_runtime_import_prefix;
::std::string grpc_local_import_prefix;
std::vector<::std::string> params_list = std::vector<::std::string> params_list =
grpc_generator::tokenize(parameter, ","); grpc_generator::tokenize(parameter, ",");
for (auto param_str = params_list.begin(); param_str != params_list.end(); for (auto param_str = params_list.begin(); param_str != params_list.end();
@ -117,6 +119,13 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
} }
pb_runtime_import_prefix = param[1]; pb_runtime_import_prefix = param[1];
grpc_generator::StripSuffix(&pb_runtime_import_prefix, "/"); grpc_generator::StripSuffix(&pb_runtime_import_prefix, "/");
} else if (param[0] == "grpc_local_import_prefix") {
grpc_local_import = true;
if (param.size() != 2) {
*error = grpc::string("Format: grpc_local_import_prefix=dir/");
return false;
}
grpc_local_import_prefix = param[1];
} }
} }
@ -161,14 +170,30 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
imports = FrameworkImport(file_name + ".pbobjc.h", framework); imports = FrameworkImport(file_name + ".pbobjc.h", framework);
} }
::std::string system_imports = ::std::string system_imports;
SystemImport("ProtoRPC/ProtoService.h") + if (grpc_local_import) {
(generator_params.no_v1_compatibility system_imports =
? SystemImport("ProtoRPC/ProtoRPC.h") LocalImport(grpc_local_import_prefix + "ProtoRPC/ProtoService.h");
: SystemImport("ProtoRPC/ProtoRPCLegacy.h")); if (generator_params.no_v1_compatibility) {
if (!generator_params.no_v1_compatibility) { system_imports +=
system_imports += SystemImport("RxLibrary/GRXWriteable.h") + LocalImport(grpc_local_import_prefix + "ProtoRPC/ProtoRPC.h");
SystemImport("RxLibrary/GRXWriter.h"); } else {
system_imports += LocalImport(grpc_local_import_prefix +
"ProtoRPC/ProtoRPCLegacy.h");
system_imports += LocalImport(grpc_local_import_prefix +
"RxLibrary/GRXWriteable.h");
system_imports +=
LocalImport(grpc_local_import_prefix + "RxLibrary/GRXWriter.h");
}
} else {
system_imports = SystemImport("ProtoRPC/ProtoService.h");
if (generator_params.no_v1_compatibility) {
system_imports += SystemImport("ProtoRPC/ProtoRPC.h");
} else {
system_imports += SystemImport("ProtoRPC/ProtoRPCLegacy.h");
system_imports += SystemImport("RxLibrary/GRXWriteable.h");
system_imports += SystemImport("RxLibrary/GRXWriter.h");
}
} }
::std::string forward_declarations = ::std::string forward_declarations =
@ -232,11 +257,24 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
imports = FrameworkImport(file_name + ".pbrpc.h", framework) + imports = FrameworkImport(file_name + ".pbrpc.h", framework) +
FrameworkImport(file_name + ".pbobjc.h", framework); FrameworkImport(file_name + ".pbobjc.h", framework);
} }
imports += (generator_params.no_v1_compatibility
? SystemImport("ProtoRPC/ProtoRPC.h") if (grpc_local_import) {
: SystemImport("ProtoRPC/ProtoRPCLegacy.h")); if (generator_params.no_v1_compatibility) {
if (!generator_params.no_v1_compatibility) { imports +=
imports += SystemImport("RxLibrary/GRXWriter+Immediate.h"); LocalImport(grpc_local_import_prefix + "ProtoRPC/ProtoRPC.h");
} else {
imports += LocalImport(grpc_local_import_prefix +
"ProtoRPC/ProtoRPCLegacy.h");
imports += LocalImport(grpc_local_import_prefix +
"RxLibrary/GRXWriter+Immediate.h");
}
} else {
if (generator_params.no_v1_compatibility) {
imports += SystemImport("ProtoRPC/ProtoRPC.h");
} else {
imports += SystemImport("ProtoRPC/ProtoRPCLegacy.h");
imports += SystemImport("RxLibrary/GRXWriter+Immediate.h");
}
} }
::std::string class_imports; ::std::string class_imports;

@ -37,11 +37,12 @@ rm -rf RemoteTestClient/*pb*
$PROTOC \ $PROTOC \
--plugin=protoc-gen-grpc=$PLUGIN \ --plugin=protoc-gen-grpc=$PLUGIN \
--objc_out=RemoteTestClient \ --objc_out=RemoteTestClient \
--grpc_out=runtime_import_prefix=$RUNTIME_IMPORT_PREFIX:RemoteTestClient \ --grpc_out=grpc_local_import_prefix=$RUNTIME_IMPORT_PREFIX,runtime_import_prefix=$RUNTIME_IMPORT_PREFIX:RemoteTestClient \
-I $ROOT_DIR \ -I $ROOT_DIR \
-I ../../../third_party/protobuf/src \ -I ../../../third_party/protobuf/src \
$ROOT_DIR/src/objective-c/examples/RemoteTestClient/*.proto $ROOT_DIR/src/objective-c/examples/RemoteTestClient/*.proto
# Verify the "runtime_import_prefix" option
# Verify the output proto filename # Verify the output proto filename
[ -e ./RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m ] || { [ -e ./RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m ] || {
echo >&2 "protoc outputs wrong filename." echo >&2 "protoc outputs wrong filename."
@ -63,6 +64,19 @@ $PROTOC \
exit 1 exit 1
} }
# Verify the "grpc_local_import_directory" option
# Verify system files are imported in a "local" way in header files.
[ "`cat RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.h |
egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'/ProtoRPC/.*\.h'`"] || {
echo >&2 "grpc system files should be imported with full paths."
}
# Verify system files are imported in a "local" way in source files.
[ "`cat RemoteTestClient/src/objective-c/examples/RemoteTestClient/Test.pbrpc.m |
egrep '#import "'"${RUNTIME_IMPORT_PREFIX}"'/ProtoRPC/.*\.h'`"] || {
echo >&2 "grpc system files should be imported with full paths."
}
# Run one extra command to clear $? before exiting the script to prevent # Run one extra command to clear $? before exiting the script to prevent
# failing even when tests pass. # failing even when tests pass.
echo "Plugin option tests passed." echo "Plugin option tests passed."

Loading…
Cancel
Save