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
diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h
index d6763af..7514fb1 100644
--- a/compiler/cpp/src/generate/t_generator.h
+++ b/compiler/cpp/src/generate/t_generator.h
@@ -178,6 +178,16 @@
}
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 2bf33f2..49dd8aa 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -204,10 +204,10 @@
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 @@
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 @@
const vector<t_program*>& 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 @@
* @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 @@
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 a834f7c..0306cf5 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 3362d26..a0e86cf 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 db52133..82f374b 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 bfcf0ea..23a701e 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 3b445c3..d979cfb 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