Fix merge conflicts

pull/8063/head
Harsh Vardhan 8 years ago
parent 974f3d797a
commit abf9ce25d9
No known key found for this signature in database
GPG Key ID: 4A3BADA5BCFFEFD6
  1. 12
      src/compiler/protobuf_plugin.h
  2. 28
      src/compiler/python_generator.cc
  3. 15
      src/compiler/python_generator_helpers.h

@ -72,16 +72,20 @@ class ProtoBufMethod : public grpc_generator::Method {
bool get_module_and_message_path_input(grpc::string *str,
grpc::string generator_file_name,
bool generate_in_pb2_grpc) const {
bool generate_in_pb2_grpc,
grpc::string &import_prefix) const {
return grpc_python_generator::GetModuleAndMessagePath(
method_->input_type(), str, generator_file_name, generate_in_pb2_grpc);
method_->input_type(), str, generator_file_name, generate_in_pb2_grpc,
import_prefix);
}
bool get_module_and_message_path_output(grpc::string *str,
grpc::string generator_file_name,
bool generate_in_pb2_grpc) const {
bool generate_in_pb2_grpc,
grpc::string &import_prefix) const {
return grpc_python_generator::GetModuleAndMessagePath(
method_->output_type(), str, generator_file_name, generate_in_pb2_grpc);
method_->output_type(), str, generator_file_name, generate_in_pb2_grpc,
import_prefix);
}
bool NoStreaming() const {

@ -221,13 +221,13 @@ bool PrivateGenerator::PrintBetaServerFactory(
grpc::string input_message_module_and_class;
if (!method->get_module_and_message_path_input(
&input_message_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
grpc::string output_message_module_and_class;
if (!method->get_module_and_message_path_output(
&output_message_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
method_implementation_constructors.insert(
@ -327,13 +327,13 @@ bool PrivateGenerator::PrintBetaStubFactory(
grpc::string input_message_module_and_class;
if (!method->get_module_and_message_path_input(
&input_message_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
grpc::string output_message_module_and_class;
if (!method->get_module_and_message_path_output(
&output_message_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
method_cardinalities.insert(
@ -432,13 +432,13 @@ bool PrivateGenerator::PrintStub(
grpc::string request_module_and_class;
if (!method->get_module_and_message_path_input(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
grpc::string response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
StringMap method_dict;
@ -523,13 +523,13 @@ bool PrivateGenerator::PrintAddServicerToServer(
grpc::string request_module_and_class;
if (!method->get_module_and_message_path_input(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
grpc::string response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc)) {
generate_in_pb2_grpc, config.import_prefix)) {
return false;
}
StringMap method_dict;
@ -595,14 +595,18 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
auto method = service.get()->method(j);
grpc::string input_type_file_name = method->get_input_type_name();
grpc::string input_module_name = ModuleName(input_type_file_name);
grpc::string input_module_alias = ModuleAlias(input_type_file_name);
grpc::string input_module_name =
ModuleName(input_type_file_name, config.import_prefix);
grpc::string input_module_alias =
ModuleAlias(input_type_file_name, config.import_prefix);
imports_set.insert(
std::make_tuple(input_module_name, input_module_alias));
grpc::string output_type_file_name = method->get_output_type_name();
grpc::string output_module_name = ModuleName(output_type_file_name);
grpc::string output_module_alias = ModuleAlias(output_type_file_name);
grpc::string output_module_name =
ModuleName(output_type_file_name, config.import_prefix);
grpc::string output_module_alias =
ModuleAlias(output_type_file_name, config.import_prefix);
imports_set.insert(
std::make_tuple(output_module_name, output_module_alias));
}

@ -67,18 +67,20 @@ typedef vector<grpc::string> StringVector;
// TODO(https://github.com/google/protobuf/issues/888):
// Export `ModuleName` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
grpc::string ModuleName(const grpc::string& filename) {
grpc::string ModuleName(const grpc::string& filename,
const grpc::string& import_prefix) {
grpc::string basename = StripProto(filename);
basename = StringReplace(basename, "-", "_");
basename = StringReplace(basename, "/", ".");
return basename + "_pb2";
return import_prefix + basename + "_pb2";
}
// TODO(https://github.com/google/protobuf/issues/888):
// Export `ModuleAlias` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
grpc::string ModuleAlias(const grpc::string& filename) {
grpc::string module_name = ModuleName(filename);
grpc::string ModuleAlias(const grpc::string& filename,
const grpc::string& import_prefix) {
grpc::string module_name = ModuleName(filename, import_prefix);
// We can't have dots in the module name, so we replace each with _dot_.
// But that could lead to a collision between a.b and a_dot_b, so we also
// duplicate each underscore.
@ -89,7 +91,8 @@ grpc::string ModuleAlias(const grpc::string& filename) {
bool GetModuleAndMessagePath(const Descriptor* type, grpc::string* out,
grpc::string generator_file_name,
bool generate_in_pb2_grpc) {
bool generate_in_pb2_grpc,
grpc::string& import_prefix) {
const Descriptor* path_elem_type = type;
DescriptorVector message_path;
do {
@ -105,7 +108,7 @@ bool GetModuleAndMessagePath(const Descriptor* type, grpc::string* out,
grpc::string module;
if (generator_file_name != file_name || generate_in_pb2_grpc) {
module = ModuleAlias(file_name) + ".";
module = ModuleAlias(file_name, import_prefix) + ".";
} else {
module = "";
}

Loading…
Cancel
Save