aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler/ruby_generator.cc
diff options
context:
space:
mode:
authorGravatar temiola <temiola@google.com>2015-01-07 11:43:05 -0800
committerGravatar Tim Emiola <temiola@google.com>2015-01-08 12:44:01 -0800
commite5206aace91f9d833cd3a5cc0ef38accc2d78425 (patch)
tree1c2751fe603477f61590a3997a42665d744ef7a4 /src/compiler/ruby_generator.cc
parent03df7f653a15468ff11ed77206e443e81cc1d4d4 (diff)
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
Diffstat (limited to 'src/compiler/ruby_generator.cc')
-rw-r--r--src/compiler/ruby_generator.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/compiler/ruby_generator.cc b/src/compiler/ruby_generator.cc
index e8d3c25e0b..c5c5884736 100644
--- a/src/compiler/ruby_generator.cc
+++ b/src/compiler/ruby_generator.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");