Skip to content
Snippets Groups Projects
Commit 4d7b0e13 authored by Masood Malekghassemi's avatar Masood Malekghassemi Committed by GitHub
Browse files

Merge pull request #8920 from...

Merge pull request #8920 from soltanmm-google/fracking-is-not-inherently-horrible-it-just-does-not-have-enough-oversight

Switch to command-arg for Python split-codegen
parents 8ef6de08 561dce45
No related branches found
No related tags found
No related merge requests found
...@@ -760,6 +760,32 @@ PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config) ...@@ -760,6 +760,32 @@ PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config)
PythonGrpcGenerator::~PythonGrpcGenerator() {} PythonGrpcGenerator::~PythonGrpcGenerator() {}
static bool GenerateGrpc(GeneratorContext* context, PrivateGenerator& generator,
grpc::string file_name, bool generate_in_pb2_grpc) {
bool success;
std::unique_ptr<ZeroCopyOutputStream> output;
std::unique_ptr<CodedOutputStream> coded_output;
grpc::string grpc_code;
if (generate_in_pb2_grpc) {
output.reset(context->Open(file_name));
generator.generate_in_pb2_grpc = true;
} else {
output.reset(context->OpenForInsert(file_name, "module_scope"));
generator.generate_in_pb2_grpc = false;
}
coded_output.reset(new CodedOutputStream(output.get()));
tie(success, grpc_code) = generator.GetGrpcServices();
if (success) {
coded_output->WriteRaw(grpc_code.data(), grpc_code.size());
return true;
} else {
return false;
}
}
bool PythonGrpcGenerator::Generate(const FileDescriptor* file, bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
const grpc::string& parameter, const grpc::string& parameter,
GeneratorContext* context, GeneratorContext* context,
...@@ -780,28 +806,15 @@ bool PythonGrpcGenerator::Generate(const FileDescriptor* file, ...@@ -780,28 +806,15 @@ bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
} }
PrivateGenerator generator(config_, file); PrivateGenerator generator(config_, file);
if (parameter == "grpc_2_0") {
std::unique_ptr<ZeroCopyOutputStream> pb2_output( return GenerateGrpc(context, generator, pb2_grpc_file_name, true);
context->OpenForAppend(pb2_file_name)); } else if (parameter == "") {
std::unique_ptr<ZeroCopyOutputStream> grpc_output( return GenerateGrpc(context, generator, pb2_grpc_file_name, true) &&
context->Open(pb2_grpc_file_name)); GenerateGrpc(context, generator, pb2_file_name, false);
CodedOutputStream pb2_coded_out(pb2_output.get()); } else {
CodedOutputStream grpc_coded_out(grpc_output.get()); *error = "Invalid parameter '" + parameter + "'.";
bool success = false; return false;
grpc::string pb2_code;
grpc::string grpc_code;
generator.generate_in_pb2_grpc = false;
tie(success, pb2_code) = generator.GetGrpcServices();
if (success) {
generator.generate_in_pb2_grpc = true;
tie(success, grpc_code) = generator.GetGrpcServices();
if (success) {
pb2_coded_out.WriteRaw(pb2_code.data(), pb2_code.size());
grpc_coded_out.WriteRaw(grpc_code.data(), grpc_code.size());
return true;
}
} }
return false;
} }
} // namespace grpc_python_generator } // namespace grpc_python_generator
...@@ -167,7 +167,7 @@ class SameSeparateTest(unittest.TestCase, SeparateTestMixin): ...@@ -167,7 +167,7 @@ class SameSeparateTest(unittest.TestCase, SeparateTestMixin):
'', '',
'--proto_path={}'.format(self.proto_directory), '--proto_path={}'.format(self.proto_directory),
'--python_out={}'.format(self.python_out_directory), '--python_out={}'.format(self.python_out_directory),
'--grpc_python_out={}'.format(self.grpc_python_out_directory), '--grpc_python_out=grpc_2_0:{}'.format(self.grpc_python_out_directory),
same_proto_file, same_proto_file,
]) ])
if protoc_result != 0: if protoc_result != 0:
...@@ -241,7 +241,7 @@ class SplitCommonTest(unittest.TestCase, CommonTestMixin): ...@@ -241,7 +241,7 @@ class SplitCommonTest(unittest.TestCase, CommonTestMixin):
'', '',
'--proto_path={}'.format(self.proto_directory), '--proto_path={}'.format(self.proto_directory),
'--python_out={}'.format(self.python_out_directory), '--python_out={}'.format(self.python_out_directory),
'--grpc_python_out={}'.format(self.python_out_directory), '--grpc_python_out={}'.format(self.grpc_python_out_directory),
services_proto_file, services_proto_file,
messages_proto_file, messages_proto_file,
]) ])
...@@ -285,7 +285,7 @@ class SplitSeparateTest(unittest.TestCase, SeparateTestMixin): ...@@ -285,7 +285,7 @@ class SplitSeparateTest(unittest.TestCase, SeparateTestMixin):
'', '',
'--proto_path={}'.format(self.proto_directory), '--proto_path={}'.format(self.proto_directory),
'--python_out={}'.format(self.python_out_directory), '--python_out={}'.format(self.python_out_directory),
'--grpc_python_out={}'.format(self.grpc_python_out_directory), '--grpc_python_out=grpc_2_0:{}'.format(self.grpc_python_out_directory),
services_proto_file, services_proto_file,
messages_proto_file, messages_proto_file,
]) ])
......
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