]> granicus.if.org Git - clang/commitdiff
Support relative paths in VFSFromYAML
authorBen Langmuir <blangmuir@apple.com>
Tue, 4 Mar 2014 22:34:50 +0000 (22:34 +0000)
committerBen Langmuir <blangmuir@apple.com>
Tue, 4 Mar 2014 22:34:50 +0000 (22:34 +0000)
Use llvm::sys::fs::make_absolute to get an absolute path before
matching. Also, allow "." directories to enable testing.  ".." is still
not supported, and will require crossing file system boundaries to
implement correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202903 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp
test/VFS/relative-path.c [new file with mode: 0644]

index 43b203a334efbf6a49e56c03f286bbd165b45998..dc0f52f72b4356b61972d007db628066c24445b8 100644 (file)
@@ -733,8 +733,12 @@ VFSFromYAML *VFSFromYAML::create(MemoryBuffer *Buffer,
 }
 
 ErrorOr<Entry *> VFSFromYAML::lookupPath(const Twine &Path_) {
-  SmallVector<char, 256> Storage;
-  StringRef Path = Path_.toNullTerminatedStringRef(Storage);
+  SmallString<256> Path;
+  Path_.toVector(Path);
+
+  // Handle relative paths
+  if (error_code EC = sys::fs::make_absolute(Path))
+    return EC;
 
   if (Path.empty())
     return error_code(errc::invalid_argument, system_category());
@@ -753,7 +757,10 @@ ErrorOr<Entry *> VFSFromYAML::lookupPath(const Twine &Path_) {
 ErrorOr<Entry *> VFSFromYAML::lookupPath(sys::path::const_iterator Start,
                                          sys::path::const_iterator End,
                                          Entry *From) {
-  // FIXME: handle . and ..
+  if (Start->equals("."))
+    ++Start;
+
+  // FIXME: handle ..
   if (CaseSensitive ? !Start->equals(From->getName())
                     : !Start->equals_lower(From->getName()))
     // failure to match
diff --git a/test/VFS/relative-path.c b/test/VFS/relative-path.c
new file mode 100644 (file)
index 0000000..e7101fb
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: mkdir -p %t
+// RUN: cd %t
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -I . -ivfsoverlay %t.yaml -fsyntax-only %s
+// REQUIRES: shell
+
+#include "not_real.h"
+
+void foo() {
+  bar();
+}