From eb2ce0293138532680fdd3647c01db7587b9367b Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 9 Feb 2015 11:57:41 -0800 Subject: Fix absolute/relative path in output --- .../protobuf/compiler/command_line_interface.cc | 6 +++++- .../compiler/command_line_interface_unittest.cc | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/google') diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index ddd58e2d..4095b3c9 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -1344,7 +1344,11 @@ bool CommandLineInterface::GenerateDependencyManifestFile( vector relative_output_filenames; directory->GetOutputFilenames(&relative_output_filenames); for (int i = 0; i < relative_output_filenames.size(); i++) { - output_filenames.push_back(location + relative_output_filenames[i]); + string output_filename = location + relative_output_filenames[i]; + if (output_filename.compare(0, 2, "./") == 0) { + output_filename = output_filename.substr(2); + } + output_filenames.push_back(output_filename); } } diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 9e02f729..2aba68b9 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -988,17 +988,22 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFile) { " optional Foo foo = 1;\n" "}\n"); - Run("protocol_compiler --dependency_out=$tmpdir/manifest " - "--test_out=$tmpdir --proto_path=$tmpdir bar.proto"); + string current_working_directory = get_current_dir_name(); + SwitchToTempDirectory(); + + Run("protocol_compiler --dependency_out=manifest --test_out=. " + "bar.proto"); ExpectNoErrors(); ExpectFileContent("manifest", - "$tmpdir/bar.proto.MockCodeGenerator.test_generator: " - "$tmpdir/foo.proto\\\n $tmpdir/bar.proto"); + "bar.proto.MockCodeGenerator.test_generator: " + "foo.proto\\\n bar.proto"); + + File::ChangeWorkingDirectory(current_working_directory); } -TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForRelativePath) { +TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForAbsolutePath) { CreateTempFile("foo.proto", "syntax = \"proto2\";\n" "message Foo {}\n"); @@ -1009,10 +1014,7 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForRelativePath) { " optional Foo foo = 1;\n" "}\n"); - string current_working_directory = get_current_dir_name(); - SwitchToTempDirectory(); - - Run("protocol_compiler --dependency_out=manifest " + Run("protocol_compiler --dependency_out=$tmpdir/manifest " "--test_out=$tmpdir --proto_path=$tmpdir bar.proto"); ExpectNoErrors(); @@ -1020,8 +1022,6 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForRelativePath) { ExpectFileContent("manifest", "$tmpdir/bar.proto.MockCodeGenerator.test_generator: " "$tmpdir/foo.proto\\\n $tmpdir/bar.proto"); - - File::ChangeWorkingDirectory(current_working_directory); } // ------------------------------------------------------------------- -- cgit v1.2.3