r249316 - [VFS] Add working directories to every virtual file system.

Diego Novillo via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 08:15:23 PDT 2015


On Mon, Oct 5, 2015 at 9:55 AM, Benjamin Kramer via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: d0k
> Date: Mon Oct  5 08:55:20 2015
> New Revision: 249316
>
> URL: http://llvm.org/viewvc/llvm-project?rev=249316&view=rev
> Log:
> [VFS] Add working directories to every virtual file system.
>
> For RealFileSystem this is getcwd()/chdir(), the synthetic file systems can
> make up one for themselves. OverlayFileSystem now synchronizes the working
> directories when a new FS is added to the overlay or the overlay working
> directory is set. This allows purely artificial file systems that have zero
> ties to the underlying disks.
>
> Differential Revision: http://reviews.llvm.org/D13430
>
> Modified:
>     cfe/trunk/include/clang/Basic/VirtualFileSystem.h
>     cfe/trunk/lib/Basic/VirtualFileSystem.cpp
>     cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
>
> Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=249316&r1=249315&r2=249316&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
> +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Mon Oct  5 08:55:20
> 2015
> @@ -199,6 +199,25 @@ public:
>    /// \note The 'end' iterator is directory_iterator().
>    virtual directory_iterator dir_begin(const Twine &Dir,
>                                         std::error_code &EC) = 0;
> +
> +  /// Set the working directory. This will affect all following
> operations on
> +  /// this file system and may propagate down for nested file systems.
> +  virtual std::error_code setCurrentWorkingDirectory(const Twine &Path) =
> 0;
> +  /// Get the working directory of this file system.
> +  virtual llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const =
> 0;
> +
> +  /// Make \a Path an absolute path.
> +  ///
> +  /// Makes \a Path absolute using the current directory if it is not
> already.
> +  /// An empty \a Path will result in the current directory.
> +  ///
> +  /// /absolute/path   => /absolute/path
> +  /// relative/../path => <current-directory>/relative/../path
> +  ///
> +  /// \param Path A path that is modified to be an absolute path.
> +  /// \returns success if \a path has been made absolute, otherwise a
> +  ///          platform-specific error_code.
> +  std::error_code makeAbsolute(SmallVectorImpl<char> &Path) const;
>  };
>
>  /// \brief Gets an \p vfs::FileSystem for the 'real' file system, as seen
> by
> @@ -230,6 +249,8 @@ public:
>    llvm::ErrorOr<std::unique_ptr<File>>
>    openFileForRead(const Twine &Path) override;
>    directory_iterator dir_begin(const Twine &Dir, std::error_code &EC)
> override;
> +  llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
> +  std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
>
>    typedef FileSystemList::reverse_iterator iterator;
>
> @@ -248,6 +269,7 @@ class InMemoryDirectory;
>  /// An in-memory file system.
>  class InMemoryFileSystem : public FileSystem {
>    std::unique_ptr<detail::InMemoryDirectory> Root;
> +  std::string WorkingDirectory;
>
>  public:
>    InMemoryFileSystem();
> @@ -260,6 +282,13 @@ public:
>    llvm::ErrorOr<std::unique_ptr<File>>
>    openFileForRead(const Twine &Path) override;
>    directory_iterator dir_begin(const Twine &Dir, std::error_code &EC)
> override;
> +  llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
> +    return WorkingDirectory;
> +  }
> +  std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
> +    WorkingDirectory = Path.str();
> +    return std::error_code();
> +  }
>  };
>
>  /// \brief Get a globally unique ID for a virtual file or directory.
>
> Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=249316&r1=249315&r2=249316&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
> +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Oct  5 08:55:20 2015
> @@ -89,6 +89,14 @@ FileSystem::getBufferForFile(const llvm:
>    return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator,
> IsVolatile);
>  }
>
> +std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path)
> const {
> +  auto WorkingDir = getCurrentWorkingDirectory();
> +  if (!WorkingDir)
> +    return WorkingDir.getError();
> +
> +  return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
> +}
>

Ben,

This is causing:

tools/clang/lib/Basic/VirtualFileSystem.cpp:105:57: error: too many
arguments to function call, expected single argument 'path', have 2
arguments
  return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~                   ^~~~
[...]/llvm/llvm/include/llvm/Support/FileSystem.h:280:1: note:
'make_absolute' declared here
std::error_code make_absolute(SmallVectorImpl<char> &path);
^
1 error generated.

Not sure which of the two parameters needs to be taken out.


Thanks.  Diego.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151005/d37a4eec/attachment.html>


More information about the cfe-commits mailing list