diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-10-05 13:55:20 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-10-05 13:55:20 +0000 |
commit | 5b1864da9ca2054e158efa4042f448be057438ec (patch) | |
tree | 0a3d7a12ebc56bc5ec876d3807d975fb31e17d5d /include/clang/Basic/VirtualFileSystem.h | |
parent | 9414f34c578b4fa0a2755b727c65aa4d03c951a0 (diff) | |
download | clang-5b1864da9ca2054e158efa4042f448be057438ec.tar.gz |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/VirtualFileSystem.h')
-rw-r--r-- | include/clang/Basic/VirtualFileSystem.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h index d263e15c91..52bcce2cd1 100644 --- a/include/clang/Basic/VirtualFileSystem.h +++ b/include/clang/Basic/VirtualFileSystem.h @@ -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. |