aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler
diff options
context:
space:
mode:
authorGravatar Masood Malekghassemi <atash@google.com>2016-12-16 12:40:35 -0800
committerGravatar GitHub <noreply@github.com>2016-12-16 12:40:35 -0800
commit3fab5651dad9fd59319212b65addb8b3f1efb24a (patch)
treeac8360b744b33b54a4d9727112ff224986645021 /src/compiler
parentb229094678502e2606164a3240dbc8375ad403b5 (diff)
parentc549a3e37b21e0aee90acc21fce2d3c0cf4e57b5 (diff)
Merge pull request #9100 from bblancha/protobuf_compiler_tweak
don't print multiple imports to protobuf modules
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/python_generator.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc
index b0a60092ab..0fac1b88cd 100644
--- a/src/compiler/python_generator.cc
+++ b/src/compiler/python_generator.cc
@@ -40,6 +40,7 @@
#include <map>
#include <memory>
#include <ostream>
+#include <set>
#include <sstream>
#include <tuple>
#include <vector>
@@ -64,7 +65,9 @@ using std::make_pair;
using std::map;
using std::pair;
using std::replace;
+using std::tuple;
using std::vector;
+using std::set;
namespace grpc_python_generator {
@@ -73,6 +76,8 @@ namespace {
typedef vector<const Descriptor*> DescriptorVector;
typedef map<grpc::string, grpc::string> StringMap;
typedef vector<grpc::string> StringVector;
+typedef tuple<grpc::string, grpc::string> StringPair;
+typedef set<StringPair> StringPairSet;
// Provides RAII indentation handling. Use as:
// {
@@ -651,6 +656,7 @@ bool PrivateGenerator::PrintPreamble() {
"face_utilities\n");
if (generate_in_pb2_grpc) {
out->Print("\n");
+ StringPairSet imports_set;
for (int i = 0; i < file->service_count(); ++i) {
const ServiceDescriptor* service = file->service(i);
for (int j = 0; j < service->method_count(); ++j) {
@@ -662,11 +668,15 @@ bool PrivateGenerator::PrintPreamble() {
grpc::string type_file_name = type->file()->name();
grpc::string module_name = ModuleName(type_file_name);
grpc::string module_alias = ModuleAlias(type_file_name);
- out->Print("import $ModuleName$ as $ModuleAlias$\n", "ModuleName",
- module_name, "ModuleAlias", module_alias);
+ imports_set.insert(std::make_tuple(module_name, module_alias));
}
}
}
+ for (StringPairSet::iterator it = imports_set.begin();
+ it != imports_set.end(); ++it) {
+ out->Print("import $ModuleName$ as $ModuleAlias$\n", "ModuleName",
+ std::get<0>(*it), "ModuleAlias", std::get<1>(*it));
+ }
}
return true;
}