<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 5, 2015 at 9:55 AM, Benjamin Kramer via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="cremed">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: d0k<br>
Date: Mon Oct  5 08:55:20 2015<br>
New Revision: 249316<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249316&view=rev" rel="noreferrer" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=249316&view=rev</a><br>
Log:<br>
[VFS] Add working directories to every virtual file system.<br>
<br>
For RealFileSystem this is getcwd()/chdir(), the synthetic file systems can<br>
make up one for themselves. OverlayFileSystem now synchronizes the working<br>
directories when a new FS is added to the overlay or the overlay working<br>
directory is set. This allows purely artificial file systems that have zero<br>
ties to the underlying disks.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D13430" rel="noreferrer" target="_blank" class="cremed">http://reviews.llvm.org/D13430</a><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/VirtualFileSystem.h<br>
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp<br>
    cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=249316&r1=249315&r2=249316&view=diff" rel="noreferrer" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=249316&r1=249315&r2=249316&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)<br>
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Mon Oct  5 08:55:20 2015<br>
@@ -199,6 +199,25 @@ public:<br>
   /// \note The 'end' iterator is directory_iterator().<br>
   virtual directory_iterator dir_begin(const Twine &Dir,<br>
                                        std::error_code &EC) = 0;<br>
+<br>
+  /// Set the working directory. This will affect all following operations on<br>
+  /// this file system and may propagate down for nested file systems.<br>
+  virtual std::error_code setCurrentWorkingDirectory(const Twine &Path) = 0;<br>
+  /// Get the working directory of this file system.<br>
+  virtual llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const = 0;<br>
+<br>
+  /// Make \a Path an absolute path.<br>
+  ///<br>
+  /// Makes \a Path absolute using the current directory if it is not already.<br>
+  /// An empty \a Path will result in the current directory.<br>
+  ///<br>
+  /// /absolute/path   => /absolute/path<br>
+  /// relative/../path => <current-directory>/relative/../path<br>
+  ///<br>
+  /// \param Path A path that is modified to be an absolute path.<br>
+  /// \returns success if \a path has been made absolute, otherwise a<br>
+  ///          platform-specific error_code.<br>
+  std::error_code makeAbsolute(SmallVectorImpl<char> &Path) const;<br>
 };<br>
<br>
 /// \brief Gets an \p vfs::FileSystem for the 'real' file system, as seen by<br>
@@ -230,6 +249,8 @@ public:<br>
   llvm::ErrorOr<std::unique_ptr<File>><br>
   openFileForRead(const Twine &Path) override;<br>
   directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;<br>
+  llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;<br>
+  std::error_code setCurrentWorkingDirectory(const Twine &Path) override;<br>
<br>
   typedef FileSystemList::reverse_iterator iterator;<br>
<br>
@@ -248,6 +269,7 @@ class InMemoryDirectory;<br>
 /// An in-memory file system.<br>
 class InMemoryFileSystem : public FileSystem {<br>
   std::unique_ptr<detail::InMemoryDirectory> Root;<br>
+  std::string WorkingDirectory;<br>
<br>
 public:<br>
   InMemoryFileSystem();<br>
@@ -260,6 +282,13 @@ public:<br>
   llvm::ErrorOr<std::unique_ptr<File>><br>
   openFileForRead(const Twine &Path) override;<br>
   directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;<br>
+  llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {<br>
+    return WorkingDirectory;<br>
+  }<br>
+  std::error_code setCurrentWorkingDirectory(const Twine &Path) override {<br>
+    WorkingDirectory = Path.str();<br>
+    return std::error_code();<br>
+  }<br>
 };<br>
<br>
 /// \brief Get a globally unique ID for a virtual file or directory.<br>
<br>
Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=249316&r1=249315&r2=249316&view=diff" rel="noreferrer" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=249316&r1=249315&r2=249316&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)<br>
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Oct  5 08:55:20 2015<br>
@@ -89,6 +89,14 @@ FileSystem::getBufferForFile(const llvm:<br>
   return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);<br>
 }<br>
<br>
+std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const {<br>
+  auto WorkingDir = getCurrentWorkingDirectory();<br>
+  if (!WorkingDir)<br>
+    return WorkingDir.getError();<br>
+<br>
+  return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);<br>
+}<br></blockquote><div><br></div><div>Ben,</div><div><br></div><div>This is causing:</div><div><br></div><div><font face="monospace, monospace">tools/clang/lib/Basic/VirtualFileSystem.cpp:105:57: error: too many arguments to function call, expected single argument 'path', have 2 arguments</font></div><div><font face="monospace, monospace">  return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);</font></div><div><font face="monospace, monospace">         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~                   ^~~~</font></div><div><font face="monospace, monospace">[...]/llvm/llvm/include/llvm/Support/FileSystem.h:280:1: note: 'make_absolute' declared here</font></div><div><font face="monospace, monospace">std::error_code make_absolute(SmallVectorImpl<char> &path);</font></div><div><font face="monospace, monospace">^</font></div><div><font face="monospace, monospace">1 error generated. </font></div><div><br></div><div>Not sure which of the two parameters needs to be taken out.</div><div><br></div><div><br></div><div>Thanks.  Diego. </div></div></div></div>