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
pull/1/merge
temiola 10 years ago committed by Tim Emiola
parent 03df7f653a
commit e5206aace9
  1. 11
      src/compiler/ruby_generator.cc
  2. 7
      src/compiler/ruby_plugin.cc

@ -126,7 +126,13 @@ string GetServices(const FileDescriptor* file) {
StringOutputStream output_stream(&output);
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({
"file.name", file->name(),
"file.package", file->package(),
@ -134,9 +140,6 @@ string GetServices(const FileDescriptor* file) {
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars,
"# Source: $file.name$ for package '$file.package$'\n");
if (file->service_count() == 0) {
return output;
}
out.Print("\n");
out.Print("require 'grpc'\n");

@ -55,16 +55,19 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
const string& parameter,
google::protobuf::compiler::GeneratorContext* context,
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.
string file_name;
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
return false;
}
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->Open(file_name));
google::protobuf::io::CodedOutputStream coded_out(output.get());
string code = grpc_ruby_generator::GetServices(file);
coded_out.WriteRaw(code.data(), code.size());
return true;
}

Loading…
Cancel
Save