VirtualFileSystem.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- VirtualFileSystem.h - Virtual File System Layer ----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// Defines the virtual file system interface vfs::FileSystem.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_VIRTUALFILESYSTEM_H
  19. #define LLVM_SUPPORT_VIRTUALFILESYSTEM_H
  20. #include "llvm/ADT/IntrusiveRefCntPtr.h"
  21. #include "llvm/ADT/SmallVector.h"
  22. #include "llvm/ADT/StringRef.h"
  23. #include "llvm/ADT/StringMap.h"
  24. #include "llvm/ADT/STLFunctionalExtras.h"
  25. #include "llvm/Support/Chrono.h"
  26. #include "llvm/Support/ErrorOr.h"
  27. #include "llvm/Support/Errc.h"
  28. #include "llvm/Support/FileSystem.h"
  29. #include "llvm/Support/Path.h"
  30. #include "llvm/Support/SourceMgr.h"
  31. #include <cassert>
  32. #include <cstdint>
  33. #include <ctime>
  34. #include <memory>
  35. #include <optional>
  36. #include <stack>
  37. #include <string>
  38. #include <system_error>
  39. #include <utility>
  40. #include <vector>
  41. namespace llvm {
  42. class MemoryBuffer;
  43. class MemoryBufferRef;
  44. class Twine;
  45. namespace vfs {
  46. /// The result of a \p status operation.
  47. class Status {
  48. std::string Name;
  49. llvm::sys::fs::UniqueID UID;
  50. llvm::sys::TimePoint<> MTime;
  51. uint32_t User;
  52. uint32_t Group;
  53. uint64_t Size;
  54. llvm::sys::fs::file_type Type = llvm::sys::fs::file_type::status_error;
  55. llvm::sys::fs::perms Perms;
  56. public:
  57. // FIXME: remove when files support multiple names
  58. bool IsVFSMapped = false;
  59. /// Whether this entity has an external path different from the virtual path,
  60. /// and the external path is exposed by leaking it through the abstraction.
  61. /// For example, a RedirectingFileSystem will set this for paths where
  62. /// UseExternalName is true.
  63. ///
  64. /// FIXME: Currently the external path is exposed by replacing the virtual
  65. /// path in this Status object. Instead, we should leave the path in the
  66. /// Status intact (matching the requested virtual path) - see
  67. /// FileManager::getFileRef for how how we plan to fix this.
  68. bool ExposesExternalVFSPath = false;
  69. Status() = default;
  70. Status(const llvm::sys::fs::file_status &Status);
  71. Status(const Twine &Name, llvm::sys::fs::UniqueID UID,
  72. llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group,
  73. uint64_t Size, llvm::sys::fs::file_type Type,
  74. llvm::sys::fs::perms Perms);
  75. /// Get a copy of a Status with a different size.
  76. static Status copyWithNewSize(const Status &In, uint64_t NewSize);
  77. /// Get a copy of a Status with a different name.
  78. static Status copyWithNewName(const Status &In, const Twine &NewName);
  79. static Status copyWithNewName(const llvm::sys::fs::file_status &In,
  80. const Twine &NewName);
  81. /// Returns the name that should be used for this file or directory.
  82. StringRef getName() const { return Name; }
  83. /// @name Status interface from llvm::sys::fs
  84. /// @{
  85. llvm::sys::fs::file_type getType() const { return Type; }
  86. llvm::sys::fs::perms getPermissions() const { return Perms; }
  87. llvm::sys::TimePoint<> getLastModificationTime() const { return MTime; }
  88. llvm::sys::fs::UniqueID getUniqueID() const { return UID; }
  89. uint32_t getUser() const { return User; }
  90. uint32_t getGroup() const { return Group; }
  91. uint64_t getSize() const { return Size; }
  92. /// @}
  93. /// @name Status queries
  94. /// These are static queries in llvm::sys::fs.
  95. /// @{
  96. bool equivalent(const Status &Other) const;
  97. bool isDirectory() const;
  98. bool isRegularFile() const;
  99. bool isOther() const;
  100. bool isSymlink() const;
  101. bool isStatusKnown() const;
  102. bool exists() const;
  103. /// @}
  104. };
  105. /// Represents an open file.
  106. class File {
  107. public:
  108. /// Destroy the file after closing it (if open).
  109. /// Sub-classes should generally call close() inside their destructors. We
  110. /// cannot do that from the base class, since close is virtual.
  111. virtual ~File();
  112. /// Get the status of the file.
  113. virtual llvm::ErrorOr<Status> status() = 0;
  114. /// Get the name of the file
  115. virtual llvm::ErrorOr<std::string> getName() {
  116. if (auto Status = status())
  117. return Status->getName().str();
  118. else
  119. return Status.getError();
  120. }
  121. /// Get the contents of the file as a \p MemoryBuffer.
  122. virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  123. getBuffer(const Twine &Name, int64_t FileSize = -1,
  124. bool RequiresNullTerminator = true, bool IsVolatile = false) = 0;
  125. /// Closes the file.
  126. virtual std::error_code close() = 0;
  127. // Get the same file with a different path.
  128. static ErrorOr<std::unique_ptr<File>>
  129. getWithPath(ErrorOr<std::unique_ptr<File>> Result, const Twine &P);
  130. protected:
  131. // Set the file's underlying path.
  132. virtual void setPath(const Twine &Path) {}
  133. };
  134. /// A member of a directory, yielded by a directory_iterator.
  135. /// Only information available on most platforms is included.
  136. class directory_entry {
  137. std::string Path;
  138. llvm::sys::fs::file_type Type = llvm::sys::fs::file_type::type_unknown;
  139. public:
  140. directory_entry() = default;
  141. directory_entry(std::string Path, llvm::sys::fs::file_type Type)
  142. : Path(std::move(Path)), Type(Type) {}
  143. llvm::StringRef path() const { return Path; }
  144. llvm::sys::fs::file_type type() const { return Type; }
  145. };
  146. namespace detail {
  147. /// An interface for virtual file systems to provide an iterator over the
  148. /// (non-recursive) contents of a directory.
  149. struct DirIterImpl {
  150. virtual ~DirIterImpl();
  151. /// Sets \c CurrentEntry to the next entry in the directory on success,
  152. /// to directory_entry() at end, or returns a system-defined \c error_code.
  153. virtual std::error_code increment() = 0;
  154. directory_entry CurrentEntry;
  155. };
  156. } // namespace detail
  157. /// An input iterator over the entries in a virtual path, similar to
  158. /// llvm::sys::fs::directory_iterator.
  159. class directory_iterator {
  160. std::shared_ptr<detail::DirIterImpl> Impl; // Input iterator semantics on copy
  161. public:
  162. directory_iterator(std::shared_ptr<detail::DirIterImpl> I)
  163. : Impl(std::move(I)) {
  164. assert(Impl.get() != nullptr && "requires non-null implementation");
  165. if (Impl->CurrentEntry.path().empty())
  166. Impl.reset(); // Normalize the end iterator to Impl == nullptr.
  167. }
  168. /// Construct an 'end' iterator.
  169. directory_iterator() = default;
  170. /// Equivalent to operator++, with an error code.
  171. directory_iterator &increment(std::error_code &EC) {
  172. assert(Impl && "attempting to increment past end");
  173. EC = Impl->increment();
  174. if (Impl->CurrentEntry.path().empty())
  175. Impl.reset(); // Normalize the end iterator to Impl == nullptr.
  176. return *this;
  177. }
  178. const directory_entry &operator*() const { return Impl->CurrentEntry; }
  179. const directory_entry *operator->() const { return &Impl->CurrentEntry; }
  180. bool operator==(const directory_iterator &RHS) const {
  181. if (Impl && RHS.Impl)
  182. return Impl->CurrentEntry.path() == RHS.Impl->CurrentEntry.path();
  183. return !Impl && !RHS.Impl;
  184. }
  185. bool operator!=(const directory_iterator &RHS) const {
  186. return !(*this == RHS);
  187. }
  188. };
  189. class FileSystem;
  190. namespace detail {
  191. /// Keeps state for the recursive_directory_iterator.
  192. struct RecDirIterState {
  193. std::stack<directory_iterator, std::vector<directory_iterator>> Stack;
  194. bool HasNoPushRequest = false;
  195. };
  196. } // end namespace detail
  197. /// An input iterator over the recursive contents of a virtual path,
  198. /// similar to llvm::sys::fs::recursive_directory_iterator.
  199. class recursive_directory_iterator {
  200. FileSystem *FS;
  201. std::shared_ptr<detail::RecDirIterState>
  202. State; // Input iterator semantics on copy.
  203. public:
  204. recursive_directory_iterator(FileSystem &FS, const Twine &Path,
  205. std::error_code &EC);
  206. /// Construct an 'end' iterator.
  207. recursive_directory_iterator() = default;
  208. /// Equivalent to operator++, with an error code.
  209. recursive_directory_iterator &increment(std::error_code &EC);
  210. const directory_entry &operator*() const { return *State->Stack.top(); }
  211. const directory_entry *operator->() const { return &*State->Stack.top(); }
  212. bool operator==(const recursive_directory_iterator &Other) const {
  213. return State == Other.State; // identity
  214. }
  215. bool operator!=(const recursive_directory_iterator &RHS) const {
  216. return !(*this == RHS);
  217. }
  218. /// Gets the current level. Starting path is at level 0.
  219. int level() const {
  220. assert(!State->Stack.empty() &&
  221. "Cannot get level without any iteration state");
  222. return State->Stack.size() - 1;
  223. }
  224. void no_push() { State->HasNoPushRequest = true; }
  225. };
  226. /// The virtual file system interface.
  227. class FileSystem : public llvm::ThreadSafeRefCountedBase<FileSystem> {
  228. public:
  229. virtual ~FileSystem();
  230. /// Get the status of the entry at \p Path, if one exists.
  231. virtual llvm::ErrorOr<Status> status(const Twine &Path) = 0;
  232. /// Get a \p File object for the file at \p Path, if one exists.
  233. virtual llvm::ErrorOr<std::unique_ptr<File>>
  234. openFileForRead(const Twine &Path) = 0;
  235. /// This is a convenience method that opens a file, gets its content and then
  236. /// closes the file.
  237. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  238. getBufferForFile(const Twine &Name, int64_t FileSize = -1,
  239. bool RequiresNullTerminator = true, bool IsVolatile = false);
  240. /// Get a directory_iterator for \p Dir.
  241. /// \note The 'end' iterator is directory_iterator().
  242. virtual directory_iterator dir_begin(const Twine &Dir,
  243. std::error_code &EC) = 0;
  244. /// Set the working directory. This will affect all following operations on
  245. /// this file system and may propagate down for nested file systems.
  246. virtual std::error_code setCurrentWorkingDirectory(const Twine &Path) = 0;
  247. /// Get the working directory of this file system.
  248. virtual llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const = 0;
  249. /// Gets real path of \p Path e.g. collapse all . and .. patterns, resolve
  250. /// symlinks. For real file system, this uses `llvm::sys::fs::real_path`.
  251. /// This returns errc::operation_not_permitted if not implemented by subclass.
  252. virtual std::error_code getRealPath(const Twine &Path,
  253. SmallVectorImpl<char> &Output) const;
  254. /// Check whether a file exists. Provided for convenience.
  255. bool exists(const Twine &Path);
  256. /// Is the file mounted on a local filesystem?
  257. virtual std::error_code isLocal(const Twine &Path, bool &Result);
  258. /// Make \a Path an absolute path.
  259. ///
  260. /// Makes \a Path absolute using the current directory if it is not already.
  261. /// An empty \a Path will result in the current directory.
  262. ///
  263. /// /absolute/path => /absolute/path
  264. /// relative/../path => <current-directory>/relative/../path
  265. ///
  266. /// \param Path A path that is modified to be an absolute path.
  267. /// \returns success if \a path has been made absolute, otherwise a
  268. /// platform-specific error_code.
  269. virtual std::error_code makeAbsolute(SmallVectorImpl<char> &Path) const;
  270. enum class PrintType { Summary, Contents, RecursiveContents };
  271. void print(raw_ostream &OS, PrintType Type = PrintType::Contents,
  272. unsigned IndentLevel = 0) const {
  273. printImpl(OS, Type, IndentLevel);
  274. }
  275. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  276. LLVM_DUMP_METHOD void dump() const;
  277. #endif
  278. protected:
  279. virtual void printImpl(raw_ostream &OS, PrintType Type,
  280. unsigned IndentLevel) const {
  281. printIndent(OS, IndentLevel);
  282. OS << "FileSystem\n";
  283. }
  284. void printIndent(raw_ostream &OS, unsigned IndentLevel) const {
  285. for (unsigned i = 0; i < IndentLevel; ++i)
  286. OS << " ";
  287. }
  288. };
  289. /// Gets an \p vfs::FileSystem for the 'real' file system, as seen by
  290. /// the operating system.
  291. /// The working directory is linked to the process's working directory.
  292. /// (This is usually thread-hostile).
  293. IntrusiveRefCntPtr<FileSystem> getRealFileSystem();
  294. /// Create an \p vfs::FileSystem for the 'real' file system, as seen by
  295. /// the operating system.
  296. /// It has its own working directory, independent of (but initially equal to)
  297. /// that of the process.
  298. std::unique_ptr<FileSystem> createPhysicalFileSystem();
  299. /// A file system that allows overlaying one \p AbstractFileSystem on top
  300. /// of another.
  301. ///
  302. /// Consists of a stack of >=1 \p FileSystem objects, which are treated as being
  303. /// one merged file system. When there is a directory that exists in more than
  304. /// one file system, the \p OverlayFileSystem contains a directory containing
  305. /// the union of their contents. The attributes (permissions, etc.) of the
  306. /// top-most (most recently added) directory are used. When there is a file
  307. /// that exists in more than one file system, the file in the top-most file
  308. /// system overrides the other(s).
  309. class OverlayFileSystem : public FileSystem {
  310. using FileSystemList = SmallVector<IntrusiveRefCntPtr<FileSystem>, 1>;
  311. /// The stack of file systems, implemented as a list in order of
  312. /// their addition.
  313. FileSystemList FSList;
  314. public:
  315. OverlayFileSystem(IntrusiveRefCntPtr<FileSystem> Base);
  316. /// Pushes a file system on top of the stack.
  317. void pushOverlay(IntrusiveRefCntPtr<FileSystem> FS);
  318. llvm::ErrorOr<Status> status(const Twine &Path) override;
  319. llvm::ErrorOr<std::unique_ptr<File>>
  320. openFileForRead(const Twine &Path) override;
  321. directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
  322. llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
  323. std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
  324. std::error_code isLocal(const Twine &Path, bool &Result) override;
  325. std::error_code getRealPath(const Twine &Path,
  326. SmallVectorImpl<char> &Output) const override;
  327. using iterator = FileSystemList::reverse_iterator;
  328. using const_iterator = FileSystemList::const_reverse_iterator;
  329. using reverse_iterator = FileSystemList::iterator;
  330. using const_reverse_iterator = FileSystemList::const_iterator;
  331. using range = iterator_range<iterator>;
  332. using const_range = iterator_range<const_iterator>;
  333. /// Get an iterator pointing to the most recently added file system.
  334. iterator overlays_begin() { return FSList.rbegin(); }
  335. const_iterator overlays_begin() const { return FSList.rbegin(); }
  336. /// Get an iterator pointing one-past the least recently added file system.
  337. iterator overlays_end() { return FSList.rend(); }
  338. const_iterator overlays_end() const { return FSList.rend(); }
  339. /// Get an iterator pointing to the least recently added file system.
  340. reverse_iterator overlays_rbegin() { return FSList.begin(); }
  341. const_reverse_iterator overlays_rbegin() const { return FSList.begin(); }
  342. /// Get an iterator pointing one-past the most recently added file system.
  343. reverse_iterator overlays_rend() { return FSList.end(); }
  344. const_reverse_iterator overlays_rend() const { return FSList.end(); }
  345. range overlays_range() { return llvm::reverse(FSList); }
  346. const_range overlays_range() const { return llvm::reverse(FSList); }
  347. protected:
  348. void printImpl(raw_ostream &OS, PrintType Type,
  349. unsigned IndentLevel) const override;
  350. };
  351. class CaseInsensitiveFileSystem : public FileSystem {
  352. IntrusiveRefCntPtr<FileSystem> Base;
  353. /// Try to find Path by means of case-insensitive lookup. Stores the result in
  354. /// FoundPath on success, or returns an error code otherwise.
  355. std::error_code findCaseInsensitivePath(StringRef Path,
  356. SmallVectorImpl<char> &FoundPath);
  357. /// Attempt to exclude the possibility that File exists in Dir based on
  358. /// previous information.
  359. bool exclude(StringRef Dir, StringRef File);
  360. /// Map from directory to map from lowercase to real-case filename.
  361. llvm::StringMap<llvm::StringMap<std::string>> Maps;
  362. public:
  363. CaseInsensitiveFileSystem(IntrusiveRefCntPtr<FileSystem> Base) : Base(Base) {}
  364. llvm::ErrorOr<Status> status(const Twine &Path) override;
  365. llvm::ErrorOr<std::unique_ptr<File>>
  366. openFileForRead(const Twine &Path) override;
  367. directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
  368. llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
  369. return Base->getCurrentWorkingDirectory();
  370. }
  371. std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
  372. Maps.clear();
  373. return Base->setCurrentWorkingDirectory(Path);
  374. }
  375. };
  376. /// By default, this delegates all calls to the underlying file system. This
  377. /// is useful when derived file systems want to override some calls and still
  378. /// proxy other calls.
  379. class ProxyFileSystem : public FileSystem {
  380. public:
  381. explicit ProxyFileSystem(IntrusiveRefCntPtr<FileSystem> FS)
  382. : FS(std::move(FS)) {}
  383. llvm::ErrorOr<Status> status(const Twine &Path) override {
  384. return FS->status(Path);
  385. }
  386. llvm::ErrorOr<std::unique_ptr<File>>
  387. openFileForRead(const Twine &Path) override {
  388. return FS->openFileForRead(Path);
  389. }
  390. directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override {
  391. return FS->dir_begin(Dir, EC);
  392. }
  393. llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
  394. return FS->getCurrentWorkingDirectory();
  395. }
  396. std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
  397. return FS->setCurrentWorkingDirectory(Path);
  398. }
  399. std::error_code getRealPath(const Twine &Path,
  400. SmallVectorImpl<char> &Output) const override {
  401. return FS->getRealPath(Path, Output);
  402. }
  403. std::error_code isLocal(const Twine &Path, bool &Result) override {
  404. return FS->isLocal(Path, Result);
  405. }
  406. protected:
  407. FileSystem &getUnderlyingFS() const { return *FS; }
  408. private:
  409. IntrusiveRefCntPtr<FileSystem> FS;
  410. virtual void anchor();
  411. };
  412. namespace detail {
  413. class InMemoryDirectory;
  414. class InMemoryNode;
  415. struct NewInMemoryNodeInfo {
  416. llvm::sys::fs::UniqueID DirUID;
  417. StringRef Path;
  418. StringRef Name;
  419. time_t ModificationTime;
  420. std::unique_ptr<llvm::MemoryBuffer> Buffer;
  421. uint32_t User;
  422. uint32_t Group;
  423. llvm::sys::fs::file_type Type;
  424. llvm::sys::fs::perms Perms;
  425. Status makeStatus() const;
  426. };
  427. class NamedNodeOrError {
  428. ErrorOr<std::pair<llvm::SmallString<128>, const detail::InMemoryNode *>>
  429. Value;
  430. public:
  431. NamedNodeOrError(llvm::SmallString<128> Name,
  432. const detail::InMemoryNode *Node)
  433. : Value(std::make_pair(Name, Node)) {}
  434. NamedNodeOrError(std::error_code EC) : Value(EC) {}
  435. NamedNodeOrError(llvm::errc EC) : Value(EC) {}
  436. StringRef getName() const { return (*Value).first; }
  437. explicit operator bool() const { return static_cast<bool>(Value); }
  438. operator std::error_code() const { return Value.getError(); }
  439. std::error_code getError() const { return Value.getError(); }
  440. const detail::InMemoryNode *operator*() const { return (*Value).second; }
  441. };
  442. } // namespace detail
  443. /// An in-memory file system.
  444. class InMemoryFileSystem : public FileSystem {
  445. std::unique_ptr<detail::InMemoryDirectory> Root;
  446. std::string WorkingDirectory;
  447. bool UseNormalizedPaths = true;
  448. using MakeNodeFn = llvm::function_ref<std::unique_ptr<detail::InMemoryNode>(
  449. detail::NewInMemoryNodeInfo)>;
  450. /// Create node with \p MakeNode and add it into this filesystem at \p Path.
  451. bool addFile(const Twine &Path, time_t ModificationTime,
  452. std::unique_ptr<llvm::MemoryBuffer> Buffer,
  453. std::optional<uint32_t> User, std::optional<uint32_t> Group,
  454. std::optional<llvm::sys::fs::file_type> Type,
  455. std::optional<llvm::sys::fs::perms> Perms, MakeNodeFn MakeNode);
  456. /// Looks up the in-memory node for the path \p P.
  457. /// If \p FollowFinalSymlink is true, the returned node is guaranteed to
  458. /// not be a symlink and its path may differ from \p P.
  459. detail::NamedNodeOrError lookupNode(const Twine &P, bool FollowFinalSymlink,
  460. size_t SymlinkDepth = 0) const;
  461. class DirIterator;
  462. public:
  463. explicit InMemoryFileSystem(bool UseNormalizedPaths = true);
  464. ~InMemoryFileSystem() override;
  465. /// Add a file containing a buffer or a directory to the VFS with a
  466. /// path. The VFS owns the buffer. If present, User, Group, Type
  467. /// and Perms apply to the newly-created file or directory.
  468. /// \return true if the file or directory was successfully added,
  469. /// false if the file or directory already exists in the file system with
  470. /// different contents.
  471. bool addFile(const Twine &Path, time_t ModificationTime,
  472. std::unique_ptr<llvm::MemoryBuffer> Buffer,
  473. std::optional<uint32_t> User = std::nullopt,
  474. std::optional<uint32_t> Group = std::nullopt,
  475. std::optional<llvm::sys::fs::file_type> Type = std::nullopt,
  476. std::optional<llvm::sys::fs::perms> Perms = std::nullopt);
  477. /// Add a hard link to a file.
  478. ///
  479. /// Here hard links are not intended to be fully equivalent to the classical
  480. /// filesystem. Both the hard link and the file share the same buffer and
  481. /// status (and thus have the same UniqueID). Because of this there is no way
  482. /// to distinguish between the link and the file after the link has been
  483. /// added.
  484. ///
  485. /// The \p Target path must be an existing file or a hardlink. The
  486. /// \p NewLink file must not have been added before. The \p Target
  487. /// path must not be a directory. The \p NewLink node is added as a hard
  488. /// link which points to the resolved file of \p Target node.
  489. /// \return true if the above condition is satisfied and hardlink was
  490. /// successfully created, false otherwise.
  491. bool addHardLink(const Twine &NewLink, const Twine &Target);
  492. /// Arbitrary max depth to search through symlinks. We can get into problems
  493. /// if a link links to a link that links back to the link, for example.
  494. static constexpr size_t MaxSymlinkDepth = 16;
  495. /// Add a symbolic link. Unlike a HardLink, because \p Target doesn't need
  496. /// to refer to a file (or refer to anything, as it happens). Also, an
  497. /// in-memory directory for \p Target isn't automatically created.
  498. bool
  499. addSymbolicLink(const Twine &NewLink, const Twine &Target,
  500. time_t ModificationTime,
  501. std::optional<uint32_t> User = std::nullopt,
  502. std::optional<uint32_t> Group = std::nullopt,
  503. std::optional<llvm::sys::fs::perms> Perms = std::nullopt);
  504. /// Add a buffer to the VFS with a path. The VFS does not own the buffer.
  505. /// If present, User, Group, Type and Perms apply to the newly-created file
  506. /// or directory.
  507. /// \return true if the file or directory was successfully added,
  508. /// false if the file or directory already exists in the file system with
  509. /// different contents.
  510. bool addFileNoOwn(const Twine &Path, time_t ModificationTime,
  511. const llvm::MemoryBufferRef &Buffer,
  512. std::optional<uint32_t> User = std::nullopt,
  513. std::optional<uint32_t> Group = std::nullopt,
  514. std::optional<llvm::sys::fs::file_type> Type = std::nullopt,
  515. std::optional<llvm::sys::fs::perms> Perms = std::nullopt);
  516. std::string toString() const;
  517. /// Return true if this file system normalizes . and .. in paths.
  518. bool useNormalizedPaths() const { return UseNormalizedPaths; }
  519. llvm::ErrorOr<Status> status(const Twine &Path) override;
  520. llvm::ErrorOr<std::unique_ptr<File>>
  521. openFileForRead(const Twine &Path) override;
  522. directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
  523. llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
  524. return WorkingDirectory;
  525. }
  526. /// Canonicalizes \p Path by combining with the current working
  527. /// directory and normalizing the path (e.g. remove dots). If the current
  528. /// working directory is not set, this returns errc::operation_not_permitted.
  529. ///
  530. /// This doesn't resolve symlinks as they are not supported in in-memory file
  531. /// system.
  532. std::error_code getRealPath(const Twine &Path,
  533. SmallVectorImpl<char> &Output) const override;
  534. std::error_code isLocal(const Twine &Path, bool &Result) override;
  535. std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
  536. protected:
  537. void printImpl(raw_ostream &OS, PrintType Type,
  538. unsigned IndentLevel) const override;
  539. };
  540. /// Get a globally unique ID for a virtual file or directory.
  541. llvm::sys::fs::UniqueID getNextVirtualUniqueID();
  542. /// Gets a \p FileSystem for a virtual file system described in YAML
  543. /// format.
  544. std::unique_ptr<FileSystem>
  545. getVFSFromYAML(std::unique_ptr<llvm::MemoryBuffer> Buffer,
  546. llvm::SourceMgr::DiagHandlerTy DiagHandler,
  547. StringRef YAMLFilePath, void *DiagContext = nullptr,
  548. IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem());
  549. struct YAMLVFSEntry {
  550. template <typename T1, typename T2>
  551. YAMLVFSEntry(T1 &&VPath, T2 &&RPath, bool IsDirectory = false)
  552. : VPath(std::forward<T1>(VPath)), RPath(std::forward<T2>(RPath)),
  553. IsDirectory(IsDirectory) {}
  554. std::string VPath;
  555. std::string RPath;
  556. bool IsDirectory = false;
  557. };
  558. class RedirectingFSDirIterImpl;
  559. class RedirectingFileSystemParser;
  560. /// A virtual file system parsed from a YAML file.
  561. ///
  562. /// Currently, this class allows creating virtual files and directories. Virtual
  563. /// files map to existing external files in \c ExternalFS, and virtual
  564. /// directories may either map to existing directories in \c ExternalFS or list
  565. /// their contents in the form of other virtual directories and/or files.
  566. ///
  567. /// The basic structure of the parsed file is:
  568. /// \verbatim
  569. /// {
  570. /// 'version': <version number>,
  571. /// <optional configuration>
  572. /// 'roots': [
  573. /// <directory entries>
  574. /// ]
  575. /// }
  576. /// \endverbatim
  577. ///
  578. /// The roots may be absolute or relative. If relative they will be made
  579. /// absolute against either current working directory or the directory where
  580. /// the Overlay YAML file is located, depending on the 'root-relative'
  581. /// configuration.
  582. ///
  583. /// All configuration options are optional.
  584. /// 'case-sensitive': <boolean, default=(true for Posix, false for Windows)>
  585. /// 'use-external-names': <boolean, default=true>
  586. /// 'root-relative': <string, one of 'cwd' or 'overlay-dir', default='cwd'>
  587. /// 'overlay-relative': <boolean, default=false>
  588. /// 'fallthrough': <boolean, default=true, deprecated - use 'redirecting-with'
  589. /// instead>
  590. /// 'redirecting-with': <string, one of 'fallthrough', 'fallback', or
  591. /// 'redirect-only', default='fallthrough'>
  592. ///
  593. /// To clarify, 'root-relative' option will prepend the current working
  594. /// directory, or the overlay directory to the 'roots->name' field only if
  595. /// 'roots->name' is a relative path. On the other hand, when 'overlay-relative'
  596. /// is set to 'true', external paths will always be prepended with the overlay
  597. /// directory, even if external paths are not relative paths. The
  598. /// 'root-relative' option has no interaction with the 'overlay-relative'
  599. /// option.
  600. ///
  601. /// Virtual directories that list their contents are represented as
  602. /// \verbatim
  603. /// {
  604. /// 'type': 'directory',
  605. /// 'name': <string>,
  606. /// 'contents': [ <file or directory entries> ]
  607. /// }
  608. /// \endverbatim
  609. ///
  610. /// The default attributes for such virtual directories are:
  611. /// \verbatim
  612. /// MTime = now() when created
  613. /// Perms = 0777
  614. /// User = Group = 0
  615. /// Size = 0
  616. /// UniqueID = unspecified unique value
  617. /// \endverbatim
  618. ///
  619. /// When a path prefix matches such a directory, the next component in the path
  620. /// is matched against the entries in the 'contents' array.
  621. ///
  622. /// Re-mapped directories, on the other hand, are represented as
  623. /// /// \verbatim
  624. /// {
  625. /// 'type': 'directory-remap',
  626. /// 'name': <string>,
  627. /// 'use-external-name': <boolean>, # Optional
  628. /// 'external-contents': <path to external directory>
  629. /// }
  630. /// \endverbatim
  631. ///
  632. /// and inherit their attributes from the external directory. When a path
  633. /// prefix matches such an entry, the unmatched components are appended to the
  634. /// 'external-contents' path, and the resulting path is looked up in the
  635. /// external file system instead.
  636. ///
  637. /// Re-mapped files are represented as
  638. /// \verbatim
  639. /// {
  640. /// 'type': 'file',
  641. /// 'name': <string>,
  642. /// 'use-external-name': <boolean>, # Optional
  643. /// 'external-contents': <path to external file>
  644. /// }
  645. /// \endverbatim
  646. ///
  647. /// Their attributes and file contents are determined by looking up the file at
  648. /// their 'external-contents' path in the external file system.
  649. ///
  650. /// For 'file', 'directory' and 'directory-remap' entries the 'name' field may
  651. /// contain multiple path components (e.g. /path/to/file). However, any
  652. /// directory in such a path that contains more than one child must be uniquely
  653. /// represented by a 'directory' entry.
  654. ///
  655. /// When the 'use-external-name' field is set, calls to \a vfs::File::status()
  656. /// give the external (remapped) filesystem name instead of the name the file
  657. /// was accessed by. This is an intentional leak through the \a
  658. /// RedirectingFileSystem abstraction layer. It enables clients to discover
  659. /// (and use) the external file location when communicating with users or tools
  660. /// that don't use the same VFS overlay.
  661. ///
  662. /// FIXME: 'use-external-name' causes behaviour that's inconsistent with how
  663. /// "real" filesystems behave. Maybe there should be a separate channel for
  664. /// this information.
  665. class RedirectingFileSystem : public vfs::FileSystem {
  666. public:
  667. enum EntryKind { EK_Directory, EK_DirectoryRemap, EK_File };
  668. enum NameKind { NK_NotSet, NK_External, NK_Virtual };
  669. /// The type of redirection to perform.
  670. enum class RedirectKind {
  671. /// Lookup the redirected path first (ie. the one specified in
  672. /// 'external-contents') and if that fails "fallthrough" to a lookup of the
  673. /// originally provided path.
  674. Fallthrough,
  675. /// Lookup the provided path first and if that fails, "fallback" to a
  676. /// lookup of the redirected path.
  677. Fallback,
  678. /// Only lookup the redirected path, do not lookup the originally provided
  679. /// path.
  680. RedirectOnly
  681. };
  682. /// The type of relative path used by Roots.
  683. enum class RootRelativeKind {
  684. /// The roots are relative to the current working directory.
  685. CWD,
  686. /// The roots are relative to the directory where the Overlay YAML file
  687. // locates.
  688. OverlayDir
  689. };
  690. /// A single file or directory in the VFS.
  691. class Entry {
  692. EntryKind Kind;
  693. std::string Name;
  694. public:
  695. Entry(EntryKind K, StringRef Name) : Kind(K), Name(Name) {}
  696. virtual ~Entry() = default;
  697. StringRef getName() const { return Name; }
  698. EntryKind getKind() const { return Kind; }
  699. };
  700. /// A directory in the vfs with explicitly specified contents.
  701. class DirectoryEntry : public Entry {
  702. std::vector<std::unique_ptr<Entry>> Contents;
  703. Status S;
  704. public:
  705. /// Constructs a directory entry with explicitly specified contents.
  706. DirectoryEntry(StringRef Name, std::vector<std::unique_ptr<Entry>> Contents,
  707. Status S)
  708. : Entry(EK_Directory, Name), Contents(std::move(Contents)),
  709. S(std::move(S)) {}
  710. /// Constructs an empty directory entry.
  711. DirectoryEntry(StringRef Name, Status S)
  712. : Entry(EK_Directory, Name), S(std::move(S)) {}
  713. Status getStatus() { return S; }
  714. void addContent(std::unique_ptr<Entry> Content) {
  715. Contents.push_back(std::move(Content));
  716. }
  717. Entry *getLastContent() const { return Contents.back().get(); }
  718. using iterator = decltype(Contents)::iterator;
  719. iterator contents_begin() { return Contents.begin(); }
  720. iterator contents_end() { return Contents.end(); }
  721. static bool classof(const Entry *E) { return E->getKind() == EK_Directory; }
  722. };
  723. /// A file or directory in the vfs that is mapped to a file or directory in
  724. /// the external filesystem.
  725. class RemapEntry : public Entry {
  726. std::string ExternalContentsPath;
  727. NameKind UseName;
  728. protected:
  729. RemapEntry(EntryKind K, StringRef Name, StringRef ExternalContentsPath,
  730. NameKind UseName)
  731. : Entry(K, Name), ExternalContentsPath(ExternalContentsPath),
  732. UseName(UseName) {}
  733. public:
  734. StringRef getExternalContentsPath() const { return ExternalContentsPath; }
  735. /// Whether to use the external path as the name for this file or directory.
  736. bool useExternalName(bool GlobalUseExternalName) const {
  737. return UseName == NK_NotSet ? GlobalUseExternalName
  738. : (UseName == NK_External);
  739. }
  740. NameKind getUseName() const { return UseName; }
  741. static bool classof(const Entry *E) {
  742. switch (E->getKind()) {
  743. case EK_DirectoryRemap:
  744. [[fallthrough]];
  745. case EK_File:
  746. return true;
  747. case EK_Directory:
  748. return false;
  749. }
  750. llvm_unreachable("invalid entry kind");
  751. }
  752. };
  753. /// A directory in the vfs that maps to a directory in the external file
  754. /// system.
  755. class DirectoryRemapEntry : public RemapEntry {
  756. public:
  757. DirectoryRemapEntry(StringRef Name, StringRef ExternalContentsPath,
  758. NameKind UseName)
  759. : RemapEntry(EK_DirectoryRemap, Name, ExternalContentsPath, UseName) {}
  760. static bool classof(const Entry *E) {
  761. return E->getKind() == EK_DirectoryRemap;
  762. }
  763. };
  764. /// A file in the vfs that maps to a file in the external file system.
  765. class FileEntry : public RemapEntry {
  766. public:
  767. FileEntry(StringRef Name, StringRef ExternalContentsPath, NameKind UseName)
  768. : RemapEntry(EK_File, Name, ExternalContentsPath, UseName) {}
  769. static bool classof(const Entry *E) { return E->getKind() == EK_File; }
  770. };
  771. /// Represents the result of a path lookup into the RedirectingFileSystem.
  772. struct LookupResult {
  773. /// The entry the looked-up path corresponds to.
  774. Entry *E;
  775. private:
  776. /// When the found Entry is a DirectoryRemapEntry, stores the path in the
  777. /// external file system that the looked-up path in the virtual file system
  778. // corresponds to.
  779. std::optional<std::string> ExternalRedirect;
  780. public:
  781. LookupResult(Entry *E, sys::path::const_iterator Start,
  782. sys::path::const_iterator End);
  783. /// If the found Entry maps the the input path to a path in the external
  784. /// file system (i.e. it is a FileEntry or DirectoryRemapEntry), returns
  785. /// that path.
  786. std::optional<StringRef> getExternalRedirect() const {
  787. if (isa<DirectoryRemapEntry>(E))
  788. return StringRef(*ExternalRedirect);
  789. if (auto *FE = dyn_cast<FileEntry>(E))
  790. return FE->getExternalContentsPath();
  791. return std::nullopt;
  792. }
  793. };
  794. private:
  795. friend class RedirectingFSDirIterImpl;
  796. friend class RedirectingFileSystemParser;
  797. /// Canonicalize path by removing ".", "..", "./", components. This is
  798. /// a VFS request, do not bother about symlinks in the path components
  799. /// but canonicalize in order to perform the correct entry search.
  800. std::error_code makeCanonical(SmallVectorImpl<char> &Path) const;
  801. /// Get the File status, or error, from the underlying external file system.
  802. /// This returns the status with the originally requested name, while looking
  803. /// up the entry using the canonical path.
  804. ErrorOr<Status> getExternalStatus(const Twine &CanonicalPath,
  805. const Twine &OriginalPath) const;
  806. /// Make \a Path an absolute path.
  807. ///
  808. /// Makes \a Path absolute using the \a WorkingDir if it is not already.
  809. ///
  810. /// /absolute/path => /absolute/path
  811. /// relative/../path => <WorkingDir>/relative/../path
  812. ///
  813. /// \param WorkingDir A path that will be used as the base Dir if \a Path
  814. /// is not already absolute.
  815. /// \param Path A path that is modified to be an absolute path.
  816. /// \returns success if \a path has been made absolute, otherwise a
  817. /// platform-specific error_code.
  818. std::error_code makeAbsolute(StringRef WorkingDir,
  819. SmallVectorImpl<char> &Path) const;
  820. // In a RedirectingFileSystem, keys can be specified in Posix or Windows
  821. // style (or even a mixture of both), so this comparison helper allows
  822. // slashes (representing a root) to match backslashes (and vice versa). Note
  823. // that, other than the root, path components should not contain slashes or
  824. // backslashes.
  825. bool pathComponentMatches(llvm::StringRef lhs, llvm::StringRef rhs) const {
  826. if ((CaseSensitive ? lhs.equals(rhs) : lhs.equals_insensitive(rhs)))
  827. return true;
  828. return (lhs == "/" && rhs == "\\") || (lhs == "\\" && rhs == "/");
  829. }
  830. /// The root(s) of the virtual file system.
  831. std::vector<std::unique_ptr<Entry>> Roots;
  832. /// The current working directory of the file system.
  833. std::string WorkingDirectory;
  834. /// The file system to use for external references.
  835. IntrusiveRefCntPtr<FileSystem> ExternalFS;
  836. /// This represents the directory path that the YAML file is located.
  837. /// This will be prefixed to each 'external-contents' if IsRelativeOverlay
  838. /// is set. This will also be prefixed to each 'roots->name' if RootRelative
  839. /// is set to RootRelativeKind::OverlayDir and the path is relative.
  840. std::string OverlayFileDir;
  841. /// @name Configuration
  842. /// @{
  843. /// Whether to perform case-sensitive comparisons.
  844. ///
  845. /// Currently, case-insensitive matching only works correctly with ASCII.
  846. bool CaseSensitive = is_style_posix(sys::path::Style::native);
  847. /// IsRelativeOverlay marks whether a OverlayFileDir path must
  848. /// be prefixed in every 'external-contents' when reading from YAML files.
  849. bool IsRelativeOverlay = false;
  850. /// Whether to use to use the value of 'external-contents' for the
  851. /// names of files. This global value is overridable on a per-file basis.
  852. bool UseExternalNames = true;
  853. /// Determines the lookups to perform, as well as their order. See
  854. /// \c RedirectKind for details.
  855. RedirectKind Redirection = RedirectKind::Fallthrough;
  856. /// Determine the prefix directory if the roots are relative paths. See
  857. /// \c RootRelativeKind for details.
  858. RootRelativeKind RootRelative = RootRelativeKind::CWD;
  859. /// @}
  860. RedirectingFileSystem(IntrusiveRefCntPtr<FileSystem> ExternalFS);
  861. /// Looks up the path <tt>[Start, End)</tt> in \p From, possibly recursing
  862. /// into the contents of \p From if it is a directory. Returns a LookupResult
  863. /// giving the matched entry and, if that entry is a FileEntry or
  864. /// DirectoryRemapEntry, the path it redirects to in the external file system.
  865. ErrorOr<LookupResult> lookupPathImpl(llvm::sys::path::const_iterator Start,
  866. llvm::sys::path::const_iterator End,
  867. Entry *From) const;
  868. /// Get the status for a path with the provided \c LookupResult.
  869. ErrorOr<Status> status(const Twine &CanonicalPath, const Twine &OriginalPath,
  870. const LookupResult &Result);
  871. public:
  872. /// Looks up \p Path in \c Roots and returns a LookupResult giving the
  873. /// matched entry and, if the entry was a FileEntry or DirectoryRemapEntry,
  874. /// the path it redirects to in the external file system.
  875. ErrorOr<LookupResult> lookupPath(StringRef Path) const;
  876. /// Parses \p Buffer, which is expected to be in YAML format and
  877. /// returns a virtual file system representing its contents.
  878. static std::unique_ptr<RedirectingFileSystem>
  879. create(std::unique_ptr<MemoryBuffer> Buffer,
  880. SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
  881. void *DiagContext, IntrusiveRefCntPtr<FileSystem> ExternalFS);
  882. /// Redirect each of the remapped files from first to second.
  883. static std::unique_ptr<RedirectingFileSystem>
  884. create(ArrayRef<std::pair<std::string, std::string>> RemappedFiles,
  885. bool UseExternalNames, FileSystem &ExternalFS);
  886. ErrorOr<Status> status(const Twine &Path) override;
  887. ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override;
  888. std::error_code getRealPath(const Twine &Path,
  889. SmallVectorImpl<char> &Output) const override;
  890. llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
  891. std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
  892. std::error_code isLocal(const Twine &Path, bool &Result) override;
  893. std::error_code makeAbsolute(SmallVectorImpl<char> &Path) const override;
  894. directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
  895. void setOverlayFileDir(StringRef PrefixDir);
  896. StringRef getOverlayFileDir() const;
  897. /// Sets the redirection kind to \c Fallthrough if true or \c RedirectOnly
  898. /// otherwise. Will removed in the future, use \c setRedirection instead.
  899. void setFallthrough(bool Fallthrough);
  900. void setRedirection(RedirectingFileSystem::RedirectKind Kind);
  901. std::vector<llvm::StringRef> getRoots() const;
  902. void printEntry(raw_ostream &OS, Entry *E, unsigned IndentLevel = 0) const;
  903. protected:
  904. void printImpl(raw_ostream &OS, PrintType Type,
  905. unsigned IndentLevel) const override;
  906. };
  907. /// Collect all pairs of <virtual path, real path> entries from the
  908. /// \p YAMLFilePath. This is used by the module dependency collector to forward
  909. /// the entries into the reproducer output VFS YAML file.
  910. void collectVFSFromYAML(
  911. std::unique_ptr<llvm::MemoryBuffer> Buffer,
  912. llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
  913. SmallVectorImpl<YAMLVFSEntry> &CollectedEntries,
  914. void *DiagContext = nullptr,
  915. IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem());
  916. class YAMLVFSWriter {
  917. std::vector<YAMLVFSEntry> Mappings;
  918. std::optional<bool> IsCaseSensitive;
  919. std::optional<bool> IsOverlayRelative;
  920. std::optional<bool> UseExternalNames;
  921. std::string OverlayDir;
  922. void addEntry(StringRef VirtualPath, StringRef RealPath, bool IsDirectory);
  923. public:
  924. YAMLVFSWriter() = default;
  925. void addFileMapping(StringRef VirtualPath, StringRef RealPath);
  926. void addDirectoryMapping(StringRef VirtualPath, StringRef RealPath);
  927. void setCaseSensitivity(bool CaseSensitive) {
  928. IsCaseSensitive = CaseSensitive;
  929. }
  930. void setUseExternalNames(bool UseExtNames) { UseExternalNames = UseExtNames; }
  931. void setOverlayDir(StringRef OverlayDirectory) {
  932. IsOverlayRelative = true;
  933. OverlayDir.assign(OverlayDirectory.str());
  934. }
  935. const std::vector<YAMLVFSEntry> &getMappings() const { return Mappings; }
  936. void write(llvm::raw_ostream &OS);
  937. };
  938. } // namespace vfs
  939. } // namespace llvm
  940. #endif // LLVM_SUPPORT_VIRTUALFILESYSTEM_H
  941. #ifdef __GNUC__
  942. #pragma GCC diagnostic pop
  943. #endif