Commit b1cecb67 authored by Joshua Haberman's avatar Joshua Haberman Committed by GitHub

Merge pull request #1837 from haberman/rubygencodename

Ruby: generated foo.proto -> foo_pb.rb instead of foo.rb.
parents 868ea592 4f19797b
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'conformance' require 'conformance_pb'
$test_count = 0 $test_count = 0
$verbose = false $verbose = false
......
...@@ -31,7 +31,7 @@ genproto_output = [] ...@@ -31,7 +31,7 @@ genproto_output = []
unless ENV['IN_DOCKER'] == 'true' unless ENV['IN_DOCKER'] == 'true'
well_known_protos.each do |proto_file| well_known_protos.each do |proto_file|
input_file = "../src/" + proto_file input_file = "../src/" + proto_file
output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb") output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
genproto_output << output_file genproto_output << output_file
file output_file => input_file do |file_task| file output_file => input_file do |file_task|
sh "../src/protoc -I../src --ruby_out=lib #{input_file}" sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# generated_code.rb is in the same directory as this test. # generated_code.rb is in the same directory as this test.
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
require 'generated_code' require 'generated_code_pb'
require 'test/unit' require 'test/unit'
class GeneratedCodeTest < Test::Unit::TestCase class GeneratedCodeTest < Test::Unit::TestCase
......
...@@ -48,7 +48,7 @@ namespace ruby { ...@@ -48,7 +48,7 @@ namespace ruby {
// Forward decls. // Forward decls.
std::string IntToString(int32 value); std::string IntToString(int32 value);
std::string StripDotProto(const std::string& proto_file); std::string GetRequireName(const std::string& proto_file);
std::string LabelForField(google::protobuf::FieldDescriptor* field); std::string LabelForField(google::protobuf::FieldDescriptor* field);
std::string TypeName(google::protobuf::FieldDescriptor* field); std::string TypeName(google::protobuf::FieldDescriptor* field);
void GenerateMessage(const google::protobuf::Descriptor* message, void GenerateMessage(const google::protobuf::Descriptor* message,
...@@ -70,13 +70,13 @@ std::string IntToString(int32 value) { ...@@ -70,13 +70,13 @@ std::string IntToString(int32 value) {
return os.str(); return os.str();
} }
std::string StripDotProto(const std::string& proto_file) { std::string GetRequireName(const std::string& proto_file) {
int lastindex = proto_file.find_last_of("."); int lastindex = proto_file.find_last_of(".");
return proto_file.substr(0, lastindex); return proto_file.substr(0, lastindex) + "_pb";
} }
std::string GetOutputFilename(const std::string& proto_file) { std::string GetOutputFilename(const std::string& proto_file) {
return StripDotProto(proto_file) + ".rb"; return GetRequireName(proto_file) + ".rb";
} }
std::string LabelForField(const google::protobuf::FieldDescriptor* field) { std::string LabelForField(const google::protobuf::FieldDescriptor* field) {
...@@ -391,7 +391,7 @@ bool MaybeEmitDependency(const FileDescriptor* import, ...@@ -391,7 +391,7 @@ bool MaybeEmitDependency(const FileDescriptor* import,
return true; return true;
} else { } else {
printer->Print( printer->Print(
"require '$name$'\n", "name", StripDotProto(import->name())); "require '$name$'\n", "name", GetRequireName(import->name()));
return true; return true;
} }
} }
......
...@@ -91,12 +91,12 @@ TEST(RubyGeneratorTest, GeneratorTest) { ...@@ -91,12 +91,12 @@ TEST(RubyGeneratorTest, GeneratorTest) {
// Load the generated output and compare to the expected result. // Load the generated output and compare to the expected result.
string output; string output;
GOOGLE_CHECK_OK(File::GetContents( GOOGLE_CHECK_OK(File::GetContents(
TestTempDir() + "/ruby_generated_code.rb", TestTempDir() + "/ruby_generated_code_pb.rb",
&output, &output,
true)); true));
string expected_output; string expected_output;
GOOGLE_CHECK_OK(File::GetContents( GOOGLE_CHECK_OK(File::GetContents(
ruby_tests + "/ruby_generated_code.rb", ruby_tests + "/ruby_generated_code_pb.rb",
&expected_output, &expected_output,
true)); true));
EXPECT_EQ(expected_output, output); EXPECT_EQ(expected_output, output);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment