Added some edge case checks

pull/19733/head
Tony Lu 6 years ago
parent f9d9fbd36b
commit 8f3b487838
  1. 7
      src/compiler/objective_c_generator_helpers.h
  2. 5
      src/compiler/objective_c_plugin.cc

@ -50,10 +50,11 @@ inline ::grpc::string LocalImport(const ::grpc::string& import) {
inline ::grpc::string FrameworkImport(const ::grpc::string& import,
const ::grpc::string& framework) {
// Flattens the directory structure
// Flattens the directory structure: grab the file name only
std::size_t pos = import.rfind("/");
::grpc::string filename = import.substr(pos + 1, import.size() - pos);
cerr << filename << endl;
// If pos is npos, pos + 1 is 0, which gives us the entire string,
// so there's no need to check that
::grpc::string filename = import.substr(pos + 1, import.size() - (pos + 1));
return ::grpc::string("#import <" + framework + "/" + filename + ">\n");
}

@ -42,7 +42,6 @@ inline ::grpc::string ImportProtoHeaders(
const ::grpc::string& framework) {
::grpc::string header = grpc_objective_c_generator::MessageHeaderName(dep);
// cerr << header << endl;
if (!IsProtobufLibraryBundledProtoFile(dep)) {
if (framework.empty()) {
return indent + LocalImport(header);
@ -89,6 +88,10 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
std::vector<::grpc::string> param =
grpc_generator::tokenize(*param_str, "=");
if (param[0] == "generate_for_named_framework") {
if (param[1].empty()) {
*error = grpc::string("Name of framework cannot be empty for parameter: ") + param[0];
return false;
}
framework = param[1];
}
}

Loading…
Cancel
Save