Skip to content
Snippets Groups Projects
Commit e5206aac authored by temiola's avatar temiola Committed by Tim Emiola
Browse files

Updates the ruby generator so that it does not create files for empty protos.

Previously, this alway generated a service file with a header.

However, this does not work well, it means whenver the ruby service plugin is
used, every proto file ends up with a service file.
	Change on 2015/01/07 by temiola <temiola@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83448951
parent 03df7f65
No related branches found
No related tags found
No related merge requests found
...@@ -126,7 +126,13 @@ string GetServices(const FileDescriptor* file) { ...@@ -126,7 +126,13 @@ string GetServices(const FileDescriptor* file) {
StringOutputStream output_stream(&output); StringOutputStream output_stream(&output);
Printer out(&output_stream, '$'); Printer out(&output_stream, '$');
// Always write out a file header. // Don't write out any output if there no services, to avoid empty service
// files being generated for proto files that don't declare any.
if (file->service_count() == 0) {
return output;
}
// Write out a file header.
map<string, string> header_comment_vars = ListToDict({ map<string, string> header_comment_vars = ListToDict({
"file.name", file->name(), "file.name", file->name(),
"file.package", file->package(), "file.package", file->package(),
...@@ -134,9 +140,6 @@ string GetServices(const FileDescriptor* file) { ...@@ -134,9 +140,6 @@ string GetServices(const FileDescriptor* file) {
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars, out.Print(header_comment_vars,
"# Source: $file.name$ for package '$file.package$'\n"); "# Source: $file.name$ for package '$file.package$'\n");
if (file->service_count() == 0) {
return output;
}
out.Print("\n"); out.Print("\n");
out.Print("require 'grpc'\n"); out.Print("require 'grpc'\n");
......
...@@ -55,16 +55,19 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator { ...@@ -55,16 +55,19 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
const string& parameter, const string& parameter,
google::protobuf::compiler::GeneratorContext* context, google::protobuf::compiler::GeneratorContext* context,
string* error) const override { string* error) const override {
string code = grpc_ruby_generator::GetServices(file);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}
// Get output file name. // Get output file name.
string file_name; string file_name;
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) { if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
return false; return false;
} }
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( std::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_ruby_generator::GetServices(file);
coded_out.WriteRaw(code.data(), code.size()); coded_out.WriteRaw(code.data(), code.size());
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