소스 검색

Merge pull request #879 from mathstuf/support-equals-in-proto-path

protoc: support '=' in --proto_path arguments
Feng Xiao 9 년 전
부모
커밋
fba7976f5d
2개의 변경된 파일22개의 추가작업 그리고 2개의 파일을 삭제
  1. 7 2
      src/google/protobuf/compiler/command_line_interface.cc
  2. 15 0
      src/google/protobuf/compiler/command_line_interface_unittest.cc

+ 7 - 2
src/google/protobuf/compiler/command_line_interface.cc

@@ -1136,8 +1136,13 @@ CommandLineInterface::InterpretArgument(const string& name,
 
 
       // Make sure disk path exists, warn otherwise.
       // Make sure disk path exists, warn otherwise.
       if (access(disk_path.c_str(), F_OK) < 0) {
       if (access(disk_path.c_str(), F_OK) < 0) {
-        std::cerr << disk_path << ": warning: directory does not exist."
-                  << std::endl;
+        // Try the original path; it may have just happed to have a '=' in it.
+        if (access(parts[i].c_str(), F_OK) < 0) {
+          cerr << disk_path << ": warning: directory does not exist." << endl;
+        } else {
+          virtual_path = "";
+          disk_path = parts[i];
+        }
       }
       }
 
 
       // Don't use make_pair as the old/default standard library on Solaris
       // Don't use make_pair as the old/default standard library on Solaris

+ 15 - 0
src/google/protobuf/compiler/command_line_interface_unittest.cc

@@ -786,6 +786,21 @@ TEST_F(CommandLineInterfaceTest, NonRootMapping) {
   ExpectGenerated("test_generator", "", "bar/foo.proto", "Foo");
   ExpectGenerated("test_generator", "", "bar/foo.proto", "Foo");
 }
 }
 
 
+TEST_F(CommandLineInterfaceTest, PathWithEqualsSign) {
+  // Test setting up a search path which happens to have '=' in it.
+
+  CreateTempDir("with=sign");
+  CreateTempFile("with=sign/foo.proto",
+    "syntax = \"proto2\";\n"
+    "message Foo {}\n");
+
+  Run("protocol_compiler --test_out=$tmpdir "
+      "--proto_path=$tmpdir/with=sign foo.proto");
+
+  ExpectNoErrors();
+  ExpectGenerated("test_generator", "", "foo.proto", "Foo");
+}
+
 TEST_F(CommandLineInterfaceTest, MultipleGenerators) {
 TEST_F(CommandLineInterfaceTest, MultipleGenerators) {
   // Test that we can have multiple generators and use both in one invocation,
   // Test that we can have multiple generators and use both in one invocation,
   // each with a different output directory.
   // each with a different output directory.