From 19f8d1febe7566bef5927423c9bf5080d6e09763 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Tue, 7 Apr 2009 19:09:28 +0000 Subject: [PATCH] Thrift-421. rb: Underscore output file names and require file statments Breaks compatiblity Author: Michael Stockton git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@762907 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_generator.h | 10 ++++++++++ compiler/cpp/src/generate/t_rb_generator.cc | 14 +++++++------- lib/rb/spec/binary_protocol_accelerated_spec.rb | 2 +- lib/rb/spec/nonblocking_server_spec.rb | 2 +- lib/rb/spec/serializer_spec.rb | 2 +- lib/rb/spec/struct_spec.rb | 2 +- lib/rb/spec/types_spec.rb | 2 +- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h index d6763af3..7514fb16 100644 --- a/compiler/cpp/src/generate/t_generator.h +++ b/compiler/cpp/src/generate/t_generator.h @@ -178,6 +178,16 @@ class t_generator { } return in; } + std::string underscore(std::string in) { + in[0] = tolower(in[0]); + for (size_t i = 1; i < in.size(); ++i) { + if (isupper(in[i])) { + in[i] = tolower(in[i]); + in.insert(i, "_"); + } + } + return in; + } /** * Get the true type behind a series of typedefs. diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc index 2bf33f2c..49dd8aa7 100644 --- a/compiler/cpp/src/generate/t_rb_generator.cc +++ b/compiler/cpp/src/generate/t_rb_generator.cc @@ -204,10 +204,10 @@ void t_rb_generator::init_generator() { MKDIR(get_out_dir().c_str()); // Make output file - string f_types_name = get_out_dir()+program_name_+"_types.rb"; + string f_types_name = get_out_dir()+underscore(program_name_)+"_types.rb"; f_types_.open(f_types_name.c_str()); - string f_consts_name = get_out_dir()+program_name_+"_constants.rb"; + string f_consts_name = get_out_dir()+underscore(program_name_)+"_constants.rb"; f_consts_.open(f_consts_name.c_str()); // Print header @@ -218,7 +218,7 @@ void t_rb_generator::init_generator() { f_consts_ << rb_autogen_comment() << endl << - "require File.dirname(__FILE__) + '/" << program_name_ << "_types'" << endl << + "require File.dirname(__FILE__) + '/" << underscore(program_name_) << "_types'" << endl << endl; begin_namespace(f_consts_, ruby_modules(program_)); @@ -231,7 +231,7 @@ string t_rb_generator::render_includes() { const vector& includes = program_->get_includes(); string result = ""; for (size_t i = 0; i < includes.size(); ++i) { - result += "require '" + includes[i]->get_name() + "_types'\n"; + result += "require '" + underscore(includes[i]->get_name()) + "_types'\n"; } if (includes.size() > 0) { result += "\n"; @@ -622,7 +622,7 @@ void t_rb_generator::end_namespace(std::ofstream& out, vector modul * @param tservice The service definition */ void t_rb_generator::generate_service(t_service* tservice) { - string f_service_name = get_out_dir()+service_name_+".rb"; + string f_service_name = get_out_dir()+underscore(service_name_)+".rb"; f_service_.open(f_service_name.c_str()); f_service_ << @@ -631,11 +631,11 @@ void t_rb_generator::generate_service(t_service* tservice) { if (tservice->get_extends() != NULL) { f_service_ << - "require '" << tservice->get_extends()->get_name() << "'" << endl; + "require '" << underscore(tservice->get_extends()->get_name()) << "'" << endl; } f_service_ << - "require File.dirname(__FILE__) + '/" << program_name_ << "_types'" << endl << + "require File.dirname(__FILE__) + '/" << underscore(program_name_) << "_types'" << endl << endl; begin_namespace(f_service_, ruby_modules(tservice->get_program())); diff --git a/lib/rb/spec/binary_protocol_accelerated_spec.rb b/lib/rb/spec/binary_protocol_accelerated_spec.rb index a834f7c8..0306cf5f 100644 --- a/lib/rb/spec/binary_protocol_accelerated_spec.rb +++ b/lib/rb/spec/binary_protocol_accelerated_spec.rb @@ -19,7 +19,7 @@ require File.dirname(__FILE__) + '/spec_helper' require File.dirname(__FILE__) + '/binary_protocol_spec_shared' -require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types' +require File.dirname(__FILE__) + '/gen-rb/thrift_spec_types' class ThriftBinaryProtocolAcceleratedSpec < Spec::ExampleGroup include Thrift diff --git a/lib/rb/spec/nonblocking_server_spec.rb b/lib/rb/spec/nonblocking_server_spec.rb index 3362d262..a0e86cf2 100644 --- a/lib/rb/spec/nonblocking_server_spec.rb +++ b/lib/rb/spec/nonblocking_server_spec.rb @@ -18,7 +18,7 @@ # require File.dirname(__FILE__) + '/spec_helper' -require File.dirname(__FILE__) + '/gen-rb/NonblockingService' +require File.dirname(__FILE__) + '/gen-rb/nonblocking_service' class ThriftNonblockingServerSpec < Spec::ExampleGroup include Thrift diff --git a/lib/rb/spec/serializer_spec.rb b/lib/rb/spec/serializer_spec.rb index db521338..82f374b1 100644 --- a/lib/rb/spec/serializer_spec.rb +++ b/lib/rb/spec/serializer_spec.rb @@ -18,7 +18,7 @@ # require File.dirname(__FILE__) + '/spec_helper' -require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types' +require File.dirname(__FILE__) + '/gen-rb/thrift_spec_types' class ThriftSerializerSpec < Spec::ExampleGroup include Thrift diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb index bfcf0ea5..23a701ec 100644 --- a/lib/rb/spec/struct_spec.rb +++ b/lib/rb/spec/struct_spec.rb @@ -18,7 +18,7 @@ # require File.dirname(__FILE__) + '/spec_helper' -require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types' +require File.dirname(__FILE__) + '/gen-rb/thrift_spec_types' class ThriftStructSpec < Spec::ExampleGroup include Thrift diff --git a/lib/rb/spec/types_spec.rb b/lib/rb/spec/types_spec.rb index 3b445c3d..d979cfb1 100644 --- a/lib/rb/spec/types_spec.rb +++ b/lib/rb/spec/types_spec.rb @@ -18,7 +18,7 @@ # require File.dirname(__FILE__) + '/spec_helper' -require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types' +require File.dirname(__FILE__) + '/gen-rb/thrift_spec_types' class ThriftTypesSpec < Spec::ExampleGroup include Thrift -- 2.17.1