1 //===- VirtualFileSystem.h - Virtual File System Layer ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines the virtual file system interface vfs::FileSystem.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_VIRTUALFILESYSTEM_H
16 #define LLVM_SUPPORT_VIRTUALFILESYSTEM_H
18 #include "llvm/ADT/IntrusiveRefCntPtr.h"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Twine.h"
24 #include "llvm/Support/Chrono.h"
25 #include "llvm/Support/ErrorOr.h"
26 #include "llvm/Support/FileSystem.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/SourceMgr.h"
35 #include <system_error>
45 /// The result of a \p status operation.
48 llvm::sys::fs::UniqueID UID;
49 llvm::sys::TimePoint<> MTime;
53 llvm::sys::fs::file_type Type = llvm::sys::fs::file_type::status_error;
54 llvm::sys::fs::perms Perms;
57 // FIXME: remove when files support multiple names
58 bool IsVFSMapped = false;
61 Status(const llvm::sys::fs::file_status &Status);
62 Status(StringRef Name, llvm::sys::fs::UniqueID UID,
63 llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group,
64 uint64_t Size, llvm::sys::fs::file_type Type,
65 llvm::sys::fs::perms Perms);
67 /// Get a copy of a Status with a different name.
68 static Status copyWithNewName(const Status &In, StringRef NewName);
69 static Status copyWithNewName(const llvm::sys::fs::file_status &In,
72 /// Returns the name that should be used for this file or directory.
73 StringRef getName() const { return Name; }
75 /// @name Status interface from llvm::sys::fs
77 llvm::sys::fs::file_type getType() const { return Type; }
78 llvm::sys::fs::perms getPermissions() const { return Perms; }
79 llvm::sys::TimePoint<> getLastModificationTime() const { return MTime; }
80 llvm::sys::fs::UniqueID getUniqueID() const { return UID; }
81 uint32_t getUser() const { return User; }
82 uint32_t getGroup() const { return Group; }
83 uint64_t getSize() const { return Size; }
85 /// @name Status queries
86 /// These are static queries in llvm::sys::fs.
88 bool equivalent(const Status &Other) const;
89 bool isDirectory() const;
90 bool isRegularFile() const;
92 bool isSymlink() const;
93 bool isStatusKnown() const;
98 /// Represents an open file.
101 /// Destroy the file after closing it (if open).
102 /// Sub-classes should generally call close() inside their destructors. We
103 /// cannot do that from the base class, since close is virtual.
106 /// Get the status of the file.
107 virtual llvm::ErrorOr<Status> status() = 0;
109 /// Get the name of the file
110 virtual llvm::ErrorOr<std::string> getName() {
111 if (auto Status = status())
112 return Status->getName().str();
114 return Status.getError();
117 /// Get the contents of the file as a \p MemoryBuffer.
118 virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
119 getBuffer(const Twine &Name, int64_t FileSize = -1,
120 bool RequiresNullTerminator = true, bool IsVolatile = false) = 0;
123 virtual std::error_code close() = 0;
126 /// A member of a directory, yielded by a directory_iterator.
127 /// Only information available on most platforms is included.
128 class directory_entry {
130 llvm::sys::fs::file_type Type;
133 directory_entry() = default;
134 directory_entry(std::string Path, llvm::sys::fs::file_type Type)
135 : Path(std::move(Path)), Type(Type) {}
137 llvm::StringRef path() const { return Path; }
138 llvm::sys::fs::file_type type() const { return Type; }
143 /// An interface for virtual file systems to provide an iterator over the
144 /// (non-recursive) contents of a directory.
146 virtual ~DirIterImpl();
148 /// Sets \c CurrentEntry to the next entry in the directory on success,
149 /// to directory_entry() at end, or returns a system-defined \c error_code.
150 virtual std::error_code increment() = 0;
152 directory_entry CurrentEntry;
155 } // 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
163 directory_iterator(std::shared_ptr<detail::DirIterImpl> I)
164 : Impl(std::move(I)) {
165 assert(Impl.get() != nullptr && "requires non-null implementation");
166 if (Impl->CurrentEntry.path().empty())
167 Impl.reset(); // Normalize the end iterator to Impl == nullptr.
170 /// Construct an 'end' iterator.
171 directory_iterator() = default;
173 /// Equivalent to operator++, with an error code.
174 directory_iterator &increment(std::error_code &EC) {
175 assert(Impl && "attempting to increment past end");
176 EC = Impl->increment();
177 if (Impl->CurrentEntry.path().empty())
178 Impl.reset(); // Normalize the end iterator to Impl == nullptr.
182 const directory_entry &operator*() const { return Impl->CurrentEntry; }
183 const directory_entry *operator->() const { return &Impl->CurrentEntry; }
185 bool operator==(const directory_iterator &RHS) const {
186 if (Impl && RHS.Impl)
187 return Impl->CurrentEntry.path() == RHS.Impl->CurrentEntry.path();
188 return !Impl && !RHS.Impl;
190 bool operator!=(const directory_iterator &RHS) const {
191 return !(*this == RHS);
199 /// Keeps state for the recursive_directory_iterator.
200 struct RecDirIterState {
201 std::stack<directory_iterator, std::vector<directory_iterator>> Stack;
202 bool HasNoPushRequest = false;
205 } // end namespace detail
207 /// An input iterator over the recursive contents of a virtual path,
208 /// similar to llvm::sys::fs::recursive_directory_iterator.
209 class recursive_directory_iterator {
211 std::shared_ptr<detail::RecDirIterState>
212 State; // Input iterator semantics on copy.
215 recursive_directory_iterator(FileSystem &FS, const Twine &Path,
216 std::error_code &EC);
218 /// Construct an 'end' iterator.
219 recursive_directory_iterator() = default;
221 /// Equivalent to operator++, with an error code.
222 recursive_directory_iterator &increment(std::error_code &EC);
224 const directory_entry &operator*() const { return *State->Stack.top(); }
225 const directory_entry *operator->() const { return &*State->Stack.top(); }
227 bool operator==(const recursive_directory_iterator &Other) const {
228 return State == Other.State; // identity
230 bool operator!=(const recursive_directory_iterator &RHS) const {
231 return !(*this == RHS);
234 /// Gets the current level. Starting path is at level 0.
236 assert(!State->Stack.empty() &&
237 "Cannot get level without any iteration state");
238 return State->Stack.size() - 1;
241 void no_push() { State->HasNoPushRequest = true; }
244 /// The virtual file system interface.
245 class FileSystem : public llvm::ThreadSafeRefCountedBase<FileSystem> {
247 virtual ~FileSystem();
249 /// Get the status of the entry at \p Path, if one exists.
250 virtual llvm::ErrorOr<Status> status(const Twine &Path) = 0;
252 /// Get a \p File object for the file at \p Path, if one exists.
253 virtual llvm::ErrorOr<std::unique_ptr<File>>
254 openFileForRead(const Twine &Path) = 0;
256 /// This is a convenience method that opens a file, gets its content and then
258 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
259 getBufferForFile(const Twine &Name, int64_t FileSize = -1,
260 bool RequiresNullTerminator = true, bool IsVolatile = false);
262 /// Get a directory_iterator for \p Dir.
263 /// \note The 'end' iterator is directory_iterator().
264 virtual directory_iterator dir_begin(const Twine &Dir,
265 std::error_code &EC) = 0;
267 /// Set the working directory. This will affect all following operations on
268 /// this file system and may propagate down for nested file systems.
269 virtual std::error_code setCurrentWorkingDirectory(const Twine &Path) = 0;
271 /// Get the working directory of this file system.
272 virtual llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const = 0;
274 /// Gets real path of \p Path e.g. collapse all . and .. patterns, resolve
275 /// symlinks. For real file system, this uses `llvm::sys::fs::real_path`.
276 /// This returns errc::operation_not_permitted if not implemented by subclass.
277 virtual std::error_code getRealPath(const Twine &Path,
278 SmallVectorImpl<char> &Output) const;
280 /// Check whether a file exists. Provided for convenience.
281 bool exists(const Twine &Path);
283 /// Is the file mounted on a local filesystem?
284 virtual std::error_code isLocal(const Twine &Path, bool &Result);
286 /// Make \a Path an absolute path.
288 /// Makes \a Path absolute using the current directory if it is not already.
289 /// An empty \a Path will result in the current directory.
291 /// /absolute/path => /absolute/path
292 /// relative/../path => <current-directory>/relative/../path
294 /// \param Path A path that is modified to be an absolute path.
295 /// \returns success if \a path has been made absolute, otherwise a
296 /// platform-specific error_code.
297 std::error_code makeAbsolute(SmallVectorImpl<char> &Path) const;
300 /// Gets an \p vfs::FileSystem for the 'real' file system, as seen by
301 /// the operating system.
302 IntrusiveRefCntPtr<FileSystem> getRealFileSystem();
304 /// A file system that allows overlaying one \p AbstractFileSystem on top
307 /// Consists of a stack of >=1 \p FileSystem objects, which are treated as being
308 /// one merged file system. When there is a directory that exists in more than
309 /// one file system, the \p OverlayFileSystem contains a directory containing
310 /// the union of their contents. The attributes (permissions, etc.) of the
311 /// top-most (most recently added) directory are used. When there is a file
312 /// that exists in more than one file system, the file in the top-most file
313 /// system overrides the other(s).
314 class OverlayFileSystem : public FileSystem {
315 using FileSystemList = SmallVector<IntrusiveRefCntPtr<FileSystem>, 1>;
317 /// The stack of file systems, implemented as a list in order of
319 FileSystemList FSList;
322 OverlayFileSystem(IntrusiveRefCntPtr<FileSystem> Base);
324 /// Pushes a file system on top of the stack.
325 void pushOverlay(IntrusiveRefCntPtr<FileSystem> FS);
327 llvm::ErrorOr<Status> status(const Twine &Path) override;
328 llvm::ErrorOr<std::unique_ptr<File>>
329 openFileForRead(const Twine &Path) override;
330 directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
331 llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
332 std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
333 std::error_code isLocal(const Twine &Path, bool &Result) override;
334 std::error_code getRealPath(const Twine &Path,
335 SmallVectorImpl<char> &Output) const override;
337 using iterator = FileSystemList::reverse_iterator;
338 using const_iterator = FileSystemList::const_reverse_iterator;
340 /// Get an iterator pointing to the most recently added file system.
341 iterator overlays_begin() { return FSList.rbegin(); }
342 const_iterator overlays_begin() const { return FSList.rbegin(); }
344 /// Get an iterator pointing one-past the least recently added file
346 iterator overlays_end() { return FSList.rend(); }
347 const_iterator overlays_end() const { return FSList.rend(); }
350 /// By default, this delegates all calls to the underlying file system. This
351 /// is useful when derived file systems want to override some calls and still
352 /// proxy other calls.
353 class ProxyFileSystem : public FileSystem {
355 explicit ProxyFileSystem(IntrusiveRefCntPtr<FileSystem> FS)
356 : FS(std::move(FS)) {}
358 llvm::ErrorOr<Status> status(const Twine &Path) override {
359 return FS->status(Path);
361 llvm::ErrorOr<std::unique_ptr<File>>
362 openFileForRead(const Twine &Path) override {
363 return FS->openFileForRead(Path);
365 directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override {
366 return FS->dir_begin(Dir, EC);
368 llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
369 return FS->getCurrentWorkingDirectory();
371 std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
372 return FS->setCurrentWorkingDirectory(Path);
374 std::error_code getRealPath(const Twine &Path,
375 SmallVectorImpl<char> &Output) const override {
376 return FS->getRealPath(Path, Output);
378 std::error_code isLocal(const Twine &Path, bool &Result) override {
379 return FS->isLocal(Path, Result);
383 FileSystem &getUnderlyingFS() { return *FS; }
386 IntrusiveRefCntPtr<FileSystem> FS;
388 virtual void anchor();
393 class InMemoryDirectory;
396 } // namespace detail
398 /// An in-memory file system.
399 class InMemoryFileSystem : public FileSystem {
400 std::unique_ptr<detail::InMemoryDirectory> Root;
401 std::string WorkingDirectory;
402 bool UseNormalizedPaths = true;
404 /// If HardLinkTarget is non-null, a hardlink is created to the To path which
405 /// must be a file. If it is null then it adds the file as the public addFile.
406 bool addFile(const Twine &Path, time_t ModificationTime,
407 std::unique_ptr<llvm::MemoryBuffer> Buffer,
408 Optional<uint32_t> User, Optional<uint32_t> Group,
409 Optional<llvm::sys::fs::file_type> Type,
410 Optional<llvm::sys::fs::perms> Perms,
411 const detail::InMemoryFile *HardLinkTarget);
414 explicit InMemoryFileSystem(bool UseNormalizedPaths = true);
415 ~InMemoryFileSystem() override;
417 /// Add a file containing a buffer or a directory to the VFS with a
418 /// path. The VFS owns the buffer. If present, User, Group, Type
419 /// and Perms apply to the newly-created file or directory.
420 /// \return true if the file or directory was successfully added,
421 /// false if the file or directory already exists in the file system with
422 /// different contents.
423 bool addFile(const Twine &Path, time_t ModificationTime,
424 std::unique_ptr<llvm::MemoryBuffer> Buffer,
425 Optional<uint32_t> User = None, Optional<uint32_t> Group = None,
426 Optional<llvm::sys::fs::file_type> Type = None,
427 Optional<llvm::sys::fs::perms> Perms = None);
429 /// Add a hard link to a file.
430 /// Here hard links are not intended to be fully equivalent to the classical
431 /// filesystem. Both the hard link and the file share the same buffer and
432 /// status (and thus have the same UniqueID). Because of this there is no way
433 /// to distinguish between the link and the file after the link has been
436 /// The To path must be an existing file or a hardlink. The From file must not
437 /// have been added before. The To Path must not be a directory. The From Node
438 /// is added as a hard link which points to the resolved file of To Node.
439 /// \return true if the above condition is satisfied and hardlink was
440 /// successfully created, false otherwise.
441 bool addHardLink(const Twine &From, const Twine &To);
443 /// Add a buffer to the VFS with a path. The VFS does not own the buffer.
444 /// If present, User, Group, Type and Perms apply to the newly-created file
446 /// \return true if the file or directory was successfully added,
447 /// false if the file or directory already exists in the file system with
448 /// different contents.
449 bool addFileNoOwn(const Twine &Path, time_t ModificationTime,
450 llvm::MemoryBuffer *Buffer, Optional<uint32_t> User = None,
451 Optional<uint32_t> Group = None,
452 Optional<llvm::sys::fs::file_type> Type = None,
453 Optional<llvm::sys::fs::perms> Perms = None);
455 std::string toString() const;
457 /// Return true if this file system normalizes . and .. in paths.
458 bool useNormalizedPaths() const { return UseNormalizedPaths; }
460 llvm::ErrorOr<Status> status(const Twine &Path) override;
461 llvm::ErrorOr<std::unique_ptr<File>>
462 openFileForRead(const Twine &Path) override;
463 directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
465 llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
466 return WorkingDirectory;
468 /// Canonicalizes \p Path by combining with the current working
469 /// directory and normalizing the path (e.g. remove dots). If the current
470 /// working directory is not set, this returns errc::operation_not_permitted.
472 /// This doesn't resolve symlinks as they are not supported in in-memory file
474 std::error_code getRealPath(const Twine &Path,
475 SmallVectorImpl<char> &Output) const override;
476 std::error_code isLocal(const Twine &Path, bool &Result) override;
477 std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
480 /// Get a globally unique ID for a virtual file or directory.
481 llvm::sys::fs::UniqueID getNextVirtualUniqueID();
483 /// Gets a \p FileSystem for a virtual file system described in YAML
485 IntrusiveRefCntPtr<FileSystem>
486 getVFSFromYAML(std::unique_ptr<llvm::MemoryBuffer> Buffer,
487 llvm::SourceMgr::DiagHandlerTy DiagHandler,
488 StringRef YAMLFilePath, void *DiagContext = nullptr,
489 IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem());
491 struct YAMLVFSEntry {
492 template <typename T1, typename T2>
493 YAMLVFSEntry(T1 &&VPath, T2 &&RPath)
494 : VPath(std::forward<T1>(VPath)), RPath(std::forward<T2>(RPath)) {}
499 class VFSFromYamlDirIterImpl;
500 class RedirectingFileSystemParser;
502 /// A virtual file system parsed from a YAML file.
504 /// Currently, this class allows creating virtual directories and mapping
505 /// virtual file paths to existing external files, available in \c ExternalFS.
507 /// The basic structure of the parsed file is:
510 /// 'version': <version number>,
511 /// <optional configuration>
513 /// <directory entries>
518 /// All configuration options are optional.
519 /// 'case-sensitive': <boolean, default=true>
520 /// 'use-external-names': <boolean, default=true>
521 /// 'overlay-relative': <boolean, default=false>
522 /// 'fallthrough': <boolean, default=true>
524 /// Virtual directories are represented as
527 /// 'type': 'directory',
528 /// 'name': <string>,
529 /// 'contents': [ <file or directory entries> ]
533 /// The default attributes for virtual directories are:
535 /// MTime = now() when created
539 /// UniqueID = unspecified unique value
542 /// Re-mapped files are represented as
546 /// 'name': <string>,
547 /// 'use-external-name': <boolean> # Optional
548 /// 'external-contents': <path to external file>
552 /// and inherit their attributes from the external contents.
554 /// In both cases, the 'name' field may contain multiple path components (e.g.
555 /// /path/to/file). However, any directory that contains more than one child
556 /// must be uniquely represented by a directory entry.
557 class RedirectingFileSystem : public vfs::FileSystem {
559 enum EntryKind { EK_Directory, EK_File };
561 /// A single file or directory in the VFS.
567 Entry(EntryKind K, StringRef Name) : Kind(K), Name(Name) {}
568 virtual ~Entry() = default;
570 StringRef getName() const { return Name; }
571 EntryKind getKind() const { return Kind; }
574 class RedirectingDirectoryEntry : public Entry {
575 std::vector<std::unique_ptr<Entry>> Contents;
579 RedirectingDirectoryEntry(StringRef Name,
580 std::vector<std::unique_ptr<Entry>> Contents,
582 : Entry(EK_Directory, Name), Contents(std::move(Contents)),
584 RedirectingDirectoryEntry(StringRef Name, Status S)
585 : Entry(EK_Directory, Name), S(std::move(S)) {}
587 Status getStatus() { return S; }
589 void addContent(std::unique_ptr<Entry> Content) {
590 Contents.push_back(std::move(Content));
593 Entry *getLastContent() const { return Contents.back().get(); }
595 using iterator = decltype(Contents)::iterator;
597 iterator contents_begin() { return Contents.begin(); }
598 iterator contents_end() { return Contents.end(); }
600 static bool classof(const Entry *E) { return E->getKind() == EK_Directory; }
603 class RedirectingFileEntry : public Entry {
605 enum NameKind { NK_NotSet, NK_External, NK_Virtual };
608 std::string ExternalContentsPath;
612 RedirectingFileEntry(StringRef Name, StringRef ExternalContentsPath,
614 : Entry(EK_File, Name), ExternalContentsPath(ExternalContentsPath),
617 StringRef getExternalContentsPath() const { return ExternalContentsPath; }
619 /// whether to use the external path as the name for this file.
620 bool useExternalName(bool GlobalUseExternalName) const {
621 return UseName == NK_NotSet ? GlobalUseExternalName
622 : (UseName == NK_External);
625 NameKind getUseName() const { return UseName; }
627 static bool classof(const Entry *E) { return E->getKind() == EK_File; }
631 friend class VFSFromYamlDirIterImpl;
632 friend class RedirectingFileSystemParser;
634 /// The root(s) of the virtual file system.
635 std::vector<std::unique_ptr<Entry>> Roots;
637 /// The file system to use for external references.
638 IntrusiveRefCntPtr<FileSystem> ExternalFS;
640 /// If IsRelativeOverlay is set, this represents the directory
641 /// path that should be prefixed to each 'external-contents' entry
642 /// when reading from YAML files.
643 std::string ExternalContentsPrefixDir;
645 /// @name Configuration
648 /// Whether to perform case-sensitive comparisons.
650 /// Currently, case-insensitive matching only works correctly with ASCII.
651 bool CaseSensitive = true;
653 /// IsRelativeOverlay marks whether a ExternalContentsPrefixDir path must
654 /// be prefixed in every 'external-contents' when reading from YAML files.
655 bool IsRelativeOverlay = false;
657 /// Whether to use to use the value of 'external-contents' for the
658 /// names of files. This global value is overridable on a per-file basis.
659 bool UseExternalNames = true;
661 /// Whether to attempt a file lookup in external file system after it wasn't
663 bool IsFallthrough = true;
666 /// Virtual file paths and external files could be canonicalized without "..",
667 /// "." and "./" in their paths. FIXME: some unittests currently fail on
668 /// win32 when using remove_dots and remove_leading_dotslash on paths.
669 bool UseCanonicalizedPaths =
676 RedirectingFileSystem(IntrusiveRefCntPtr<FileSystem> ExternalFS)
677 : ExternalFS(std::move(ExternalFS)) {}
679 /// Looks up the path <tt>[Start, End)</tt> in \p From, possibly
680 /// recursing into the contents of \p From if it is a directory.
681 ErrorOr<Entry *> lookupPath(llvm::sys::path::const_iterator Start,
682 llvm::sys::path::const_iterator End,
685 /// Get the status of a given an \c Entry.
686 ErrorOr<Status> status(const Twine &Path, Entry *E);
689 /// Looks up \p Path in \c Roots.
690 ErrorOr<Entry *> lookupPath(const Twine &Path) const;
692 /// Parses \p Buffer, which is expected to be in YAML format and
693 /// returns a virtual file system representing its contents.
694 static RedirectingFileSystem *
695 create(std::unique_ptr<MemoryBuffer> Buffer,
696 SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
697 void *DiagContext, IntrusiveRefCntPtr<FileSystem> ExternalFS);
699 ErrorOr<Status> status(const Twine &Path) override;
700 ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override;
702 std::error_code getRealPath(const Twine &Path,
703 SmallVectorImpl<char> &Output) const override;
705 llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override;
707 std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
709 std::error_code isLocal(const Twine &Path, bool &Result) override;
711 directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
713 void setExternalContentsPrefixDir(StringRef PrefixDir);
715 StringRef getExternalContentsPrefixDir() const;
717 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
718 LLVM_DUMP_METHOD void dump() const;
719 LLVM_DUMP_METHOD void dumpEntry(Entry *E, int NumSpaces = 0) const;
723 /// Collect all pairs of <virtual path, real path> entries from the
724 /// \p YAMLFilePath. This is used by the module dependency collector to forward
725 /// the entries into the reproducer output VFS YAML file.
726 void collectVFSFromYAML(
727 std::unique_ptr<llvm::MemoryBuffer> Buffer,
728 llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
729 SmallVectorImpl<YAMLVFSEntry> &CollectedEntries,
730 void *DiagContext = nullptr,
731 IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem());
733 class YAMLVFSWriter {
734 std::vector<YAMLVFSEntry> Mappings;
735 Optional<bool> IsCaseSensitive;
736 Optional<bool> IsOverlayRelative;
737 Optional<bool> UseExternalNames;
738 std::string OverlayDir;
741 YAMLVFSWriter() = default;
743 void addFileMapping(StringRef VirtualPath, StringRef RealPath);
745 void setCaseSensitivity(bool CaseSensitive) {
746 IsCaseSensitive = CaseSensitive;
749 void setUseExternalNames(bool UseExtNames) { UseExternalNames = UseExtNames; }
751 void setOverlayDir(StringRef OverlayDirectory) {
752 IsOverlayRelative = true;
753 OverlayDir.assign(OverlayDirectory.str());
756 const std::vector<YAMLVFSEntry> &getMappings() const { return Mappings; }
758 void write(llvm::raw_ostream &OS);
764 #endif // LLVM_SUPPORT_VIRTUALFILESYSTEM_H