r202903 - Support relative paths in VFSFromYAML

Ben Langmuir blangmuir at apple.com
Tue Mar 4 14:34:51 PST 2014


Author: benlangmuir
Date: Tue Mar  4 16:34:50 2014
New Revision: 202903

URL: http://llvm.org/viewvc/llvm-project?rev=202903&view=rev
Log:
Support relative paths in VFSFromYAML

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.

Added:
    cfe/trunk/test/VFS/relative-path.c
Modified:
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=202903&r1=202902&r2=202903&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Mar  4 16:34:50 2014
@@ -733,8 +733,12 @@ VFSFromYAML *VFSFromYAML::create(MemoryB
 }
 
 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
 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

Added: cfe/trunk/test/VFS/relative-path.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/relative-path.c?rev=202903&view=auto
==============================================================================
--- cfe/trunk/test/VFS/relative-path.c (added)
+++ cfe/trunk/test/VFS/relative-path.c Tue Mar  4 16:34:50 2014
@@ -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();
+}





More information about the cfe-commits mailing list