Modified objc plugin to add two types of import statements for well
known protos.
Deleted unnecessary empty.proto as we'll be using wellknown empty.proto
Modified test to use the well known empty.proto.
pull/7288/head
Makarand Dharmapurikar 9 years ago
parent 5a412cf891
commit 2b220f8be7
  1. 16
      src/compiler/objective_c_plugin.cc
  2. 12
      src/objective-c/tests/InteropTests.m
  3. 4
      src/objective-c/tests/RemoteTestClient/RemoteTest.podspec
  4. 44
      src/objective-c/tests/RemoteTestClient/empty.proto
  5. 4
      src/objective-c/tests/RemoteTestClient/test.proto

@ -39,6 +39,8 @@
#include "src/compiler/objective_c_generator.h" #include "src/compiler/objective_c_generator.h"
#include "src/compiler/objective_c_generator_helpers.h" #include "src/compiler/objective_c_generator_helpers.h"
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
public: public:
ObjectiveCGrpcGenerator() {} ObjectiveCGrpcGenerator() {}
@ -72,8 +74,22 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
for (int i = 0; i < file->dependency_count(); i++) { for (int i = 0; i < file->dependency_count(); i++) {
::grpc::string header = grpc_objective_c_generator::MessageHeaderName( ::grpc::string header = grpc_objective_c_generator::MessageHeaderName(
file->dependency(i)); file->dependency(i));
const grpc::protobuf::FileDescriptor *dependency = file->dependency(i);
if (::google::protobuf::compiler::objectivec::IsProtobufLibraryBundledProtoFile(dependency)) {
::grpc::string base_name = header;
grpc_generator::StripPrefix(&base_name, "google/protobuf/");
proto_imports +=
::grpc::string("#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS\n") +
::grpc::string(" #import <") +
::google::protobuf::compiler::objectivec::ProtobufLibraryFrameworkName +
("/") + base_name + ">\n" +
::grpc::string("#else\n") +
::grpc::string(" #import \"") + header + "\"\n" +
::grpc::string("#endif\n");
} else {
proto_imports += ::grpc::string("#import \"") + header + "\"\n"; proto_imports += ::grpc::string("#import \"") + header + "\"\n";
} }
}
::grpc::string declarations; ::grpc::string declarations;
for (int i = 0; i < file->service_count(); i++) { for (int i = 0; i < file->service_count(); i++) {

@ -110,12 +110,12 @@ static cronet_engine *cronetEngine = NULL;
XCTAssertNotNil(self.class.host); XCTAssertNotNil(self.class.host);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"];
RMTEmpty *request = [RMTEmpty message]; GPBEmpty *request = [GPBEmpty message];
[_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) { [_service emptyCallWithRequest:request handler:^(GPBEmpty *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
id expectedResponse = [RMTEmpty message]; id expectedResponse = [GPBEmpty message];
XCTAssertEqualObjects(response, expectedResponse); XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill]; [expectation fulfill];
@ -343,9 +343,9 @@ static cronet_engine *cronetEngine = NULL;
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"RPC after closing connection"]; [self expectationWithDescription:@"RPC after closing connection"];
RMTEmpty *request = [RMTEmpty message]; GPBEmpty *request = [GPBEmpty message];
[_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) { [_service emptyCallWithRequest:request handler:^(GPBEmpty *response, NSError *error) {
XCTAssertNil(error, @"First RPC finished with unexpected error: %@", error); XCTAssertNil(error, @"First RPC finished with unexpected error: %@", error);
#pragma clang diagnostic push #pragma clang diagnostic push
@ -353,7 +353,7 @@ static cronet_engine *cronetEngine = NULL;
[GRPCCall closeOpenConnections]; [GRPCCall closeOpenConnections];
#pragma clang diagnostic pop #pragma clang diagnostic pop
[_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) { [_service emptyCallWithRequest:request handler:^(GPBEmpty *response, NSError *error) {
XCTAssertNil(error, @"Second RPC finished with unexpected error: %@", error); XCTAssertNil(error, @"Second RPC finished with unexpected error: %@", error);
[expectation fulfill]; [expectation fulfill];
}]; }];

@ -15,7 +15,9 @@ Pod::Spec.new do |s|
BINDIR=../../../../bins/$CONFIG BINDIR=../../../../bins/$CONFIG
PROTOC=$BINDIR/protobuf/protoc PROTOC=$BINDIR/protobuf/protoc
PLUGIN=$BINDIR/grpc_objective_c_plugin PLUGIN=$BINDIR/grpc_objective_c_plugin
$PROTOC --plugin=protoc-gen-grpc=$PLUGIN --objc_out=. --grpc_out=. *.proto # we use this path to locate well-known proto files
PROTO_SRC=../../../../third_party/protobuf/src
$PROTOC --plugin=protoc-gen-grpc=$PLUGIN --objc_out=. --grpc_out=. *.proto -I $PROTO_SRC -I .
CMD CMD
s.subspec "Messages" do |ms| s.subspec "Messages" do |ms|

@ -1,44 +0,0 @@
// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";
package grpc.testing;
option objc_class_prefix = "RMT";
// An empty message that you can re-use to avoid defining duplicated empty
// messages in your project. A typical example is to use it as argument or the
// return value of a service API. For instance:
//
// service Foo {
// rpc Bar (grpc.testing.Empty) returns (grpc.testing.Empty) { };
// };
//
message Empty {}

@ -31,7 +31,7 @@
// of unary/streaming requests/responses. // of unary/streaming requests/responses.
syntax = "proto3"; syntax = "proto3";
import "empty.proto"; import "google/protobuf/empty.proto";
import "messages.proto"; import "messages.proto";
package grpc.testing; package grpc.testing;
@ -42,7 +42,7 @@ option objc_class_prefix = "RMT";
// performance with various types of payload. // performance with various types of payload.
service TestService { service TestService {
// One empty request followed by one empty response. // One empty request followed by one empty response.
rpc EmptyCall(grpc.testing.Empty) returns (grpc.testing.Empty); rpc EmptyCall(google.protobuf.Empty) returns (google.protobuf.Empty);
// One request followed by one response. // One request followed by one response.
rpc UnaryCall(SimpleRequest) returns (SimpleResponse); rpc UnaryCall(SimpleRequest) returns (SimpleResponse);

Loading…
Cancel
Save