[llvm] r346453 - [VFS] Add "expand tilde" argument to getRealPath.

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 16:26:10 PST 2018


Author: jdevlieghere
Date: Thu Nov  8 16:26:10 2018
New Revision: 346453

URL: http://llvm.org/viewvc/llvm-project?rev=346453&view=rev
Log:
[VFS] Add "expand tilde" argument to getRealPath.

Add an optional argument to expand tildes in the path to mirror llvm's
implementation of the corresponding function.

Modified:
    llvm/trunk/include/llvm/Support/VirtualFileSystem.h
    llvm/trunk/lib/Support/VirtualFileSystem.cpp
    llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp

Modified: llvm/trunk/include/llvm/Support/VirtualFileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/VirtualFileSystem.h?rev=346453&r1=346452&r2=346453&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/VirtualFileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/VirtualFileSystem.h Thu Nov  8 16:26:10 2018
@@ -274,7 +274,8 @@ public:
   /// symlinks. For real file system, this uses `llvm::sys::fs::real_path`.
   /// This returns errc::operation_not_permitted if not implemented by subclass.
   virtual std::error_code getRealPath(const Twine &Path,
-                                      SmallVectorImpl<char> &Output) const;
+                                      SmallVectorImpl<char> &Output,
+                                      bool ExpandTilde = false) const;
 
   /// Check whether a file exists. Provided for convenience.
   bool exists(const Twine &Path);
@@ -330,8 +331,8 @@ public:
   llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
   std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
   std::error_code isLocal(const Twine &Path, bool &Result) override;
-  std::error_code getRealPath(const Twine &Path,
-                              SmallVectorImpl<char> &Output) const override;
+  std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
+                              bool ExpandTilde = false) const override;
 
   using iterator = FileSystemList::reverse_iterator;
   using const_iterator = FileSystemList::const_reverse_iterator;
@@ -370,9 +371,9 @@ public:
   std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
     return FS->setCurrentWorkingDirectory(Path);
   }
-  std::error_code getRealPath(const Twine &Path,
-                              SmallVectorImpl<char> &Output) const override {
-    return FS->getRealPath(Path, Output);
+  std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
+                              bool ExpandTilde = false) const override {
+    return FS->getRealPath(Path, Output, ExpandTilde);
   }
 
 protected:
@@ -465,8 +466,8 @@ public:
   ///
   /// This doesn't resolve symlinks as they are not supported in in-memory file
   /// system.
-  std::error_code getRealPath(const Twine &Path,
-                              SmallVectorImpl<char> &Output) const override;
+  std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
+                              bool ExpandTilde = false) const override;
   std::error_code isLocal(const Twine &Path, bool &Result) override;
   std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
 };

Modified: llvm/trunk/lib/Support/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/VirtualFileSystem.cpp?rev=346453&r1=346452&r2=346453&view=diff
==============================================================================
--- llvm/trunk/lib/Support/VirtualFileSystem.cpp (original)
+++ llvm/trunk/lib/Support/VirtualFileSystem.cpp Thu Nov  8 16:26:10 2018
@@ -132,7 +132,8 @@ std::error_code FileSystem::makeAbsolute
 }
 
 std::error_code FileSystem::getRealPath(const Twine &Path,
-                                        SmallVectorImpl<char> &Output) const {
+                                        SmallVectorImpl<char> &Output,
+                                        bool ExpandTilde) const {
   return errc::operation_not_permitted;
 }
 
@@ -238,8 +239,8 @@ public:
   llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
   std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
   std::error_code isLocal(const Twine &Path, bool &Result) override;
-  std::error_code getRealPath(const Twine &Path,
-                              SmallVectorImpl<char> &Output) const override;
+  std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
+                              bool ExpandTilde = false) const override;
 
 private:
   mutable std::mutex CWDMutex;
@@ -297,9 +298,9 @@ std::error_code RealFileSystem::isLocal(
   return llvm::sys::fs::is_local(Path, Result);
 }
 
-std::error_code
-RealFileSystem::getRealPath(const Twine &Path,
-                            SmallVectorImpl<char> &Output) const {
+std::error_code RealFileSystem::getRealPath(const Twine &Path,
+                                            SmallVectorImpl<char> &Output,
+                                            bool ExpandTilde) const {
   return llvm::sys::fs::real_path(Path, Output);
 }
 
@@ -393,12 +394,12 @@ std::error_code OverlayFileSystem::isLoc
   return errc::no_such_file_or_directory;
 }
 
-std::error_code
-OverlayFileSystem::getRealPath(const Twine &Path,
-                               SmallVectorImpl<char> &Output) const {
+std::error_code OverlayFileSystem::getRealPath(const Twine &Path,
+                                               SmallVectorImpl<char> &Output,
+                                               bool ExpandTilde) const {
   for (auto &FS : FSList)
     if (FS->exists(Path))
-      return FS->getRealPath(Path, Output);
+      return FS->getRealPath(Path, Output, ExpandTilde);
   return errc::no_such_file_or_directory;
 }
 
@@ -916,9 +917,9 @@ std::error_code InMemoryFileSystem::setC
   return {};
 }
 
-std::error_code
-InMemoryFileSystem::getRealPath(const Twine &Path,
-                                SmallVectorImpl<char> &Output) const {
+std::error_code InMemoryFileSystem::getRealPath(const Twine &Path,
+                                                SmallVectorImpl<char> &Output,
+                                                bool ExpandTilde) const {
   auto CWD = getCurrentWorkingDirectory();
   if (!CWD || CWD->empty())
     return errc::operation_not_permitted;

Modified: llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp?rev=346453&r1=346452&r2=346453&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp (original)
+++ llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp Thu Nov  8 16:26:10 2018
@@ -73,8 +73,8 @@ public:
     return std::error_code();
   }
   // Map any symlink to "/symlink".
-  std::error_code getRealPath(const Twine &Path,
-                              SmallVectorImpl<char> &Output) const override {
+  std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
+                              bool ExpandTilde) const override {
     auto I = FilesAndDirs.find(Path.str());
     if (I == FilesAndDirs.end())
       return make_error_code(llvm::errc::no_such_file_or_directory);




More information about the llvm-commits mailing list