Skip to content
Snippets Groups Projects
Commit c549a3e3 authored by Bryan Blanchard's avatar Bryan Blanchard
Browse files

don't print multiple imports to protobuf modules

parent 7b1b2cc2
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <set>
#include <sstream> #include <sstream>
#include <tuple> #include <tuple>
#include <vector> #include <vector>
...@@ -64,7 +65,9 @@ using std::make_pair; ...@@ -64,7 +65,9 @@ using std::make_pair;
using std::map; using std::map;
using std::pair; using std::pair;
using std::replace; using std::replace;
using std::tuple;
using std::vector; using std::vector;
using std::set;
namespace grpc_python_generator { namespace grpc_python_generator {
...@@ -73,6 +76,8 @@ namespace { ...@@ -73,6 +76,8 @@ namespace {
typedef vector<const Descriptor*> DescriptorVector; typedef vector<const Descriptor*> DescriptorVector;
typedef map<grpc::string, grpc::string> StringMap; typedef map<grpc::string, grpc::string> StringMap;
typedef vector<grpc::string> StringVector; typedef vector<grpc::string> StringVector;
typedef tuple<grpc::string, grpc::string> StringPair;
typedef set<StringPair> StringPairSet;
// Provides RAII indentation handling. Use as: // Provides RAII indentation handling. Use as:
// { // {
...@@ -651,6 +656,7 @@ bool PrivateGenerator::PrintPreamble() { ...@@ -651,6 +656,7 @@ bool PrivateGenerator::PrintPreamble() {
"face_utilities\n"); "face_utilities\n");
if (generate_in_pb2_grpc) { if (generate_in_pb2_grpc) {
out->Print("\n"); out->Print("\n");
StringPairSet imports_set;
for (int i = 0; i < file->service_count(); ++i) { for (int i = 0; i < file->service_count(); ++i) {
const ServiceDescriptor* service = file->service(i); const ServiceDescriptor* service = file->service(i);
for (int j = 0; j < service->method_count(); ++j) { for (int j = 0; j < service->method_count(); ++j) {
...@@ -662,11 +668,15 @@ bool PrivateGenerator::PrintPreamble() { ...@@ -662,11 +668,15 @@ bool PrivateGenerator::PrintPreamble() {
grpc::string type_file_name = type->file()->name(); grpc::string type_file_name = type->file()->name();
grpc::string module_name = ModuleName(type_file_name); grpc::string module_name = ModuleName(type_file_name);
grpc::string module_alias = ModuleAlias(type_file_name); grpc::string module_alias = ModuleAlias(type_file_name);
out->Print("import $ModuleName$ as $ModuleAlias$\n", "ModuleName", imports_set.insert(std::make_tuple(module_name, module_alias));
module_name, "ModuleAlias", 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; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment