15 #ifndef LLVM_SUPPORT_VIRTUALFILESYSTEM_H 16 #define LLVM_SUPPORT_VIRTUALFILESYSTEM_H 35 #include <system_error> 119 getBuffer(
const Twine &Name, int64_t FileSize = -1,
120 bool RequiresNullTerminator =
true,
bool IsVolatile =
false) = 0;
123 virtual std::error_code close() = 0;
135 : Path(
std::move(Path)), Type(Type) {}
150 virtual std::error_code increment() = 0;
160 std::shared_ptr<detail::DirIterImpl> Impl;
164 : Impl(
std::move(I)) {
165 assert(Impl.get() !=
nullptr &&
"requires non-null implementation");
166 if (Impl->CurrentEntry.path().empty())
175 assert(Impl &&
"attempting to increment past end");
176 EC = Impl->increment();
177 if (Impl->CurrentEntry.path().empty())
186 if (Impl && RHS.Impl)
187 return Impl->CurrentEntry.path() == RHS.Impl->CurrentEntry.path();
188 return !Impl && !RHS.Impl;
191 return !(*
this == RHS);
201 std::stack<directory_iterator, std::vector<directory_iterator>>
Stack;
202 bool HasNoPushRequest =
false;
211 std::shared_ptr<detail::RecDirIterState>
216 std::error_code &EC);
228 return State == Other.State;
231 return !(*
this == RHS);
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; }
259 getBufferForFile(
const Twine &Name, int64_t FileSize = -1,
260 bool RequiresNullTerminator =
true,
bool IsVolatile =
false);
265 std::error_code &EC) = 0;
269 virtual std::error_code setCurrentWorkingDirectory(
const Twine &Path) = 0;
277 virtual std::error_code getRealPath(
const Twine &Path,
284 virtual std::error_code isLocal(
const Twine &Path,
bool &Result);
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,
356 : FS(
std::move(FS)) {}
359 return FS->status(Path);
363 return FS->openFileForRead(Path);
366 return FS->dir_begin(Dir, EC);
369 return FS->getCurrentWorkingDirectory();
372 return FS->setCurrentWorkingDirectory(Path);
376 return FS->getRealPath(Path, Output);
379 return FS->isLocal(Path, Result);
388 virtual void anchor();
393 class InMemoryDirectory;
400 std::unique_ptr<detail::InMemoryDirectory> Root;
401 std::string WorkingDirectory;
402 bool UseNormalizedPaths =
true;
406 bool addFile(
const Twine &Path, time_t ModificationTime,
407 std::unique_ptr<llvm::MemoryBuffer> Buffer,
423 bool addFile(
const Twine &Path, time_t ModificationTime,
424 std::unique_ptr<llvm::MemoryBuffer> Buffer,
449 bool addFileNoOwn(
const Twine &Path, time_t ModificationTime,
466 return WorkingDirectory;
474 std::error_code getRealPath(
const Twine &Path,
476 std::error_code isLocal(
const Twine &Path,
bool &Result)
override;
477 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
488 StringRef YAMLFilePath,
void *DiagContext =
nullptr,
492 template <
typename T1,
typename T2>
494 : VPath(
std::forward<
T1>(VPath)), RPath(
std::forward<T2>(RPath)) {}
568 virtual ~
Entry() =
default;
575 std::vector<std::unique_ptr<Entry>> Contents;
580 std::vector<std::unique_ptr<Entry>> Contents,
582 :
Entry(EK_Directory, Name), Contents(
std::move(Contents)),
585 :
Entry(EK_Directory, Name), S(
std::move(S)) {}
590 Contents.push_back(std::move(Content));
605 enum NameKind { NK_NotSet, NK_External, NK_Virtual };
608 std::string ExternalContentsPath;
614 :
Entry(EK_File, Name), ExternalContentsPath(ExternalContentsPath),
621 return UseName == NK_NotSet ? GlobalUseExternalName
622 : (UseName == NK_External);
635 std::vector<std::unique_ptr<Entry>> Roots;
643 std::string ExternalContentsPrefixDir;
651 bool CaseSensitive =
true;
655 bool IsRelativeOverlay =
false;
659 bool UseExternalNames =
true;
663 bool IsFallthrough =
true;
669 bool UseCanonicalizedPaths =
677 : ExternalFS(
std::move(ExternalFS)) {}
695 create(std::unique_ptr<MemoryBuffer> Buffer,
702 std::error_code getRealPath(
const Twine &Path,
707 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
709 std::error_code isLocal(
const Twine &Path,
bool &Result)
override;
713 void setExternalContentsPrefixDir(
StringRef PrefixDir);
715 StringRef getExternalContentsPrefixDir()
const;
717 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 727 std::unique_ptr<llvm::MemoryBuffer> Buffer,
730 void *DiagContext =
nullptr,
734 std::vector<YAMLVFSEntry> Mappings;
738 std::string OverlayDir;
746 IsCaseSensitive = CaseSensitive;
752 IsOverlayRelative =
true;
753 OverlayDir.assign(OverlayDirectory.
str());
756 const std::vector<YAMLVFSEntry> &
getMappings()
const {
return Mappings; }
764 #endif // LLVM_SUPPORT_VIRTUALFILESYSTEM_H An input iterator over the recursive contents of a virtual path, similar to llvm::sys::fs::recursive_...
const directory_entry * operator->() const
const directory_entry & operator*() const
A file system that allows overlaying one AbstractFileSystem on top of another.
std::reverse_iterator< const_iterator > const_reverse_iterator
iterator overlays_begin()
Get an iterator pointing to the most recently added file system.
An interface for virtual file systems to provide an iterator over the (non-recursive) contents of a d...
llvm::StringRef path() const
Represents either an error or a value T.
RedirectingDirectoryEntry(StringRef Name, std::vector< std::unique_ptr< Entry >> Contents, Status S)
const directory_entry & operator*() const
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
bool operator==(const directory_iterator &RHS) const
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
This class represents lattice values for constants.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
ProxyFileSystem(IntrusiveRefCntPtr< FileSystem > FS)
FileSystemList::reverse_iterator iterator
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const override
Get the working directory of this file system.
llvm::sys::fs::UniqueID getNextVirtualUniqueID()
Get a globally unique ID for a virtual file or directory.
YAMLVFSEntry(T1 &&VPath, T2 &&RPath)
directory_entry(std::string Path, llvm::sys::fs::file_type Type)
const std::vector< YAMLVFSEntry > & getMappings() const
llvm::sys::fs::file_type type() const
EntryKind getKind() const
The result of a status operation.
FileSystemList::const_reverse_iterator const_iterator
Entry(EntryKind K, StringRef Name)
Represents the result of a call to sys::fs::status().
bool useExternalName(bool GlobalUseExternalName) const
whether to use the external path as the name for this file.
int level() const
Gets the current level. Starting path is at level 0.
llvm::ErrorOr< std::unique_ptr< File > > openFileForRead(const Twine &Path) override
Get a File object for the file at Path, if one exists.
directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override
Get a directory_iterator for Dir.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getName() const
Returns the name that should be used for this file or directory.
const_iterator overlays_begin() const
void setCaseSensitivity(bool CaseSensitive)
StringRef getExternalContentsPath() const
directory_entry CurrentEntry
bool operator==(const recursive_directory_iterator &Other) const
RedirectingFileEntry(StringRef Name, StringRef ExternalContentsPath, NameKind UseName)
directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
llvm::sys::fs::file_type getType() const
llvm::sys::TimePoint getLastModificationTime() const
bool isRegularFile() const
A virtual file system parsed from a YAML file.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
The instances of the Type class are immutable: once they are created, they are never changed...
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::sys::fs::perms getPermissions() const
std::reverse_iterator< iterator > reverse_iterator
A single file or directory in the VFS.
void addContent(std::unique_ptr< Entry > Content)
Keeps state for the recursive_directory_iterator.
std::error_code getRealPath(const Twine &Path, SmallVectorImpl< char > &Output) const override
Gets real path of Path e.g.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
By default, this delegates all calls to the underlying file system.
static void write(bool isBE, void *P, T V)
bool isStatusKnown() const
static Status copyWithNewName(const Status &In, StringRef NewName)
Get a copy of a Status with a different name.
std::error_code isLocal(const Twine &Path, bool &Result) override
Is the file mounted on a local filesystem?
A member of a directory, yielded by a directory_iterator.
virtual llvm::ErrorOr< std::string > getName()
Get the name of the file.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
std::error_code setCurrentWorkingDirectory(const Twine &Path) override
Set the working directory.
bool useNormalizedPaths() const
Return true if this file system normalizes . and .. in paths.
BlockVerifier::State From
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
bool equivalent(const Status &Other) const
void setUseExternalNames(bool UseExtNames)
The virtual file system interface.
Entry * getLastContent() const
const directory_entry * operator->() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
uint32_t getGroup() const
A thread-safe version of RefCountedBase.
An in-memory file system.
bool operator!=(const directory_iterator &RHS) const
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
file_type
An enumeration for the file system's view of the type.
static bool classof(const Entry *E)
iterator contents_begin()
static bool classof(const Entry *E)
FileSystem & getUnderlyingFS()
Provides ErrorOr<T> smart pointer.
std::stack< directory_iterator, std::vector< directory_iterator > > Stack
reverse_iterator rbegin()
void collectVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, SmallVectorImpl< YAMLVFSEntry > &CollectedEntries, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Collect all pairs of <virtual path, real path> entries from the YAMLFilePath.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A helper class to hold the common YAML parsing state.
llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const override
Get the working directory of this file system.
llvm::sys::fs::UniqueID getUniqueID() const
RedirectingDirectoryEntry(StringRef Name, Status S)
This class implements an extremely fast bulk output stream that can only output to a stream...
bool operator!=(const recursive_directory_iterator &RHS) const
void setOverlayDir(StringRef OverlayDirectory)
StringRef - Represent a constant reference to a string, i.e.
decltype(Contents)::iterator iterator
const_iterator overlays_end() const
StringRef getName() const
NameKind getUseName() const
iterator overlays_end()
Get an iterator pointing one-past the least recently added file system.
directory_iterator(std::shared_ptr< detail::DirIterImpl > I)
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
llvm::ErrorOr< Status > status(const Twine &Path) override
Get the status of the entry at Path, if one exists.