Support import_prefix cmdline param
This commit is contained in:
@ -547,6 +547,7 @@ void PrintMessageImports(
|
|||||||
google::protobuf::io::Printer* printer,
|
google::protobuf::io::Printer* printer,
|
||||||
const google::protobuf::FileDescriptor* file,
|
const google::protobuf::FileDescriptor* file,
|
||||||
map<string, string>* vars,
|
map<string, string>* vars,
|
||||||
|
const string& import_prefix,
|
||||||
set<string>* imports,
|
set<string>* imports,
|
||||||
map<string, string>* import_alias) {
|
map<string, string>* import_alias) {
|
||||||
set<const google::protobuf::FileDescriptor*> descs;
|
set<const google::protobuf::FileDescriptor*> descs;
|
||||||
@ -581,14 +582,15 @@ void PrintMessageImports(
|
|||||||
if (import_alias->find(import) != import_alias->end()) {
|
if (import_alias->find(import) != import_alias->end()) {
|
||||||
import_path += (*import_alias)[import] + " ";
|
import_path += (*import_alias)[import] + " ";
|
||||||
}
|
}
|
||||||
import_path += "\"" + import + "\"";
|
import_path += "\"" + import_prefix + import + "\"";
|
||||||
printer->Print(import_path.c_str());
|
printer->Print(import_path.c_str());
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
}
|
}
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetServices(const google::protobuf::FileDescriptor* file) {
|
string GetServices(const google::protobuf::FileDescriptor* file,
|
||||||
|
vector<pair<string, string> >& options) {
|
||||||
string output;
|
string output;
|
||||||
google::protobuf::io::StringOutputStream output_stream(&output);
|
google::protobuf::io::StringOutputStream output_stream(&output);
|
||||||
google::protobuf::io::Printer printer(&output_stream, '$');
|
google::protobuf::io::Printer printer(&output_stream, '$');
|
||||||
@ -612,7 +614,15 @@ string GetServices(const google::protobuf::FileDescriptor* file) {
|
|||||||
"\tproto \"github.com/golang/protobuf/proto\"\n"
|
"\tproto \"github.com/golang/protobuf/proto\"\n"
|
||||||
")\n\n");
|
")\n\n");
|
||||||
|
|
||||||
PrintMessageImports(&printer, file, &vars, &imports, &import_alias);
|
// TODO(zhaoq): Support other command line parameters supported by
|
||||||
|
// the protoc-gen-go plugin.
|
||||||
|
string import_prefix = "";
|
||||||
|
for (auto& p : options) {
|
||||||
|
if (p.first == "import_prefix") {
|
||||||
|
import_prefix = p.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PrintMessageImports(&printer, file, &vars, import_prefix, &imports, &import_alias);
|
||||||
|
|
||||||
// $Package$ is used to fully qualify method names.
|
// $Package$ is used to fully qualify method names.
|
||||||
vars["Package"] = file->package();
|
vars["Package"] = file->package();
|
||||||
|
@ -35,6 +35,9 @@
|
|||||||
#define NET_GRPC_COMPILER_GO_GENERATOR_H_
|
#define NET_GRPC_COMPILER_GO_GENERATOR_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace protobuf {
|
namespace protobuf {
|
||||||
@ -44,7 +47,8 @@ class FileDescriptor;
|
|||||||
|
|
||||||
namespace grpc_go_generator {
|
namespace grpc_go_generator {
|
||||||
|
|
||||||
std::string GetServices(const google::protobuf::FileDescriptor* file);
|
string GetServices(const google::protobuf::FileDescriptor* file,
|
||||||
|
vector<std::pair<string, string> >& options);
|
||||||
|
|
||||||
} // namespace grpc_go_generator
|
} // namespace grpc_go_generator
|
||||||
|
|
||||||
|
BIN
rpc/compiler/go_generator.o
Normal file
BIN
rpc/compiler/go_generator.o
Normal file
Binary file not shown.
BIN
rpc/compiler/go_plugin
Executable file
BIN
rpc/compiler/go_plugin
Executable file
Binary file not shown.
@ -73,10 +73,12 @@ class GoGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<pair<string, string> > options;
|
||||||
|
google::protobuf::compiler::ParseGeneratorParameter(parameter, &options);
|
||||||
unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
|
unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
|
||||||
context->Open(file_name));
|
context->Open(file_name));
|
||||||
google::protobuf::io::CodedOutputStream coded_out(output.get());
|
google::protobuf::io::CodedOutputStream coded_out(output.get());
|
||||||
string code = grpc_go_generator::GetServices(file);
|
string code = grpc_go_generator::GetServices(file, options);
|
||||||
coded_out.WriteRaw(code.data(), code.size());
|
coded_out.WriteRaw(code.data(), code.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
BIN
rpc/compiler/go_plugin.o
Normal file
BIN
rpc/compiler/go_plugin.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user