aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2008-12-02 05:59:15 +0000
committerGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2008-12-02 05:59:15 +0000
commit2f669cbe75c054851234b7789342a5650ef951a5 (patch)
tree942580b700e524a01ee01276af4f09c270676197
parenteb241fadf22bd9cafa3c2b2e91a914a12df07993 (diff)
* Avoid using pushd/popd in generate_descriptor_proto.sh because they are
bash-only features, and /bin/sh is not a symlink to bash on all systems. * If an input file is a Windows absolute path (e.g. "C:\foo\bar.proto") and the import path only contains "." (or contains "." but does not contain the file), protoc incorrectly thought that the file was under ".", because it thought that the path was relative (since it didn't start with a slash). This has been fixed.
-rw-r--r--CHANGES.txt7
-rwxr-xr-xgenerate_descriptor_proto.sh4
-rw-r--r--src/google/protobuf/compiler/command_line_interface.cc3
-rw-r--r--src/google/protobuf/compiler/importer.cc17
-rw-r--r--src/google/protobuf/compiler/importer_unittest.cc12
5 files changed, 39 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index c12bc61a..342b4bf9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,11 @@
had to explicitly import descriptor.proto.
* Adjacent string literals in .proto files will now be concatenated, like in
C.
+ * If an input file is a Windows absolute path (e.g. "C:\foo\bar.proto") and
+ the import path only contains "." (or contains "." but does not contain
+ the file), protoc incorrectly thought that the file was under ".", because
+ it thought that the path was relative (since it didn't start with a slash).
+ This has been fixed.
C++
* Generated message classes now have a Swap() method which efficiently swaps
@@ -47,6 +52,8 @@
* Corrected ListFields() signature in Message base class to match what
subclasses actually implement.
* Some minor refactoring.
+ * Don't pass self as first argument to superclass constructor (no longer
+ allowed in Python 2.6).
2008-09-29 version 2.0.2:
diff --git a/generate_descriptor_proto.sh b/generate_descriptor_proto.sh
index 5587db0c..548b2e8f 100755
--- a/generate_descriptor_proto.sh
+++ b/generate_descriptor_proto.sh
@@ -22,6 +22,6 @@ __EOF__
exit 1
fi
-pushd src
+cd src
make protoc && ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:. google/protobuf/descriptor.proto
-popd
+cd ..
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index ea8c4ab2..089844f4 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -93,7 +93,8 @@ static const char* kPathSeparator = ":";
#endif
// Returns true if the text looks like a Windows-style absolute path, starting
-// with a drive letter. Example: "C:\foo".
+// with a drive letter. Example: "C:\foo". TODO(kenton): Share this with
+// copy in importer.cc?
static bool IsWindowsAbsolutePath(const string& text) {
#if defined(_WIN32) || defined(__CYGWIN__)
return text.size() >= 3 && text[1] == ':' &&
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index a0d8164a..30e106e8 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -61,6 +61,20 @@ namespace compiler {
#endif
#endif
+// Returns true if the text looks like a Windows-style absolute path, starting
+// with a drive letter. Example: "C:\foo". TODO(kenton): Share this with
+// copy in command_line_interface.cc?
+static bool IsWindowsAbsolutePath(const string& text) {
+#if defined(_WIN32) || defined(__CYGWIN__)
+ return text.size() >= 3 && text[1] == ':' &&
+ isalpha(text[0]) &&
+ (text[2] == '/' || text[2] == '\\') &&
+ text.find_last_of(':') == 1;
+#else
+ return false;
+#endif
+}
+
MultiFileErrorCollector::~MultiFileErrorCollector() {}
// This class serves two purposes:
@@ -276,7 +290,8 @@ static bool ApplyMapping(const string& filename,
// We do not allow the file name to use "..".
return false;
}
- if (HasPrefixString(filename, "/")) {
+ if (HasPrefixString(filename, "/") ||
+ IsWindowsAbsolutePath(filename)) {
// This is an absolute path, so it isn't matched by the empty string.
return false;
}
diff --git a/src/google/protobuf/compiler/importer_unittest.cc b/src/google/protobuf/compiler/importer_unittest.cc
index 173a3373..51aeb90c 100644
--- a/src/google/protobuf/compiler/importer_unittest.cc
+++ b/src/google/protobuf/compiler/importer_unittest.cc
@@ -516,6 +516,18 @@ TEST_F(DiskSourceTreeTest, DiskFileToVirtualFileCanonicalization) {
source_tree_.DiskFileToVirtualFile(
"../../baz", &virtual_file, &shadowing_disk_file));
+ // "/foo" is not mapped (it should not be misintepreted as being under ".").
+ EXPECT_EQ(DiskSourceTree::NO_MAPPING,
+ source_tree_.DiskFileToVirtualFile(
+ "/foo", &virtual_file, &shadowing_disk_file));
+
+#ifdef WIN32
+ // "C:\foo" is not mapped (it should not be misintepreted as being under ".").
+ EXPECT_EQ(DiskSourceTree::NO_MAPPING,
+ source_tree_.DiskFileToVirtualFile(
+ "C:\\foo", &virtual_file, &shadowing_disk_file));
+#endif // WIN32
+
// But "../baz" should be.
EXPECT_EQ(DiskSourceTree::CANNOT_OPEN,
source_tree_.DiskFileToVirtualFile(