14 #ifndef LLVM_SUPPORT_VIRTUALFILESYSTEM_H 15 #define LLVM_SUPPORT_VIRTUALFILESYSTEM_H 34 #include <system_error> 69 const Twine &NewName);
118 getBuffer(
const Twine &Name, int64_t FileSize = -1,
119 bool RequiresNullTerminator =
true,
bool IsVolatile =
false) = 0;
122 virtual std::error_code close() = 0;
134 : Path(
std::move(Path)), Type(Type) {}
149 virtual std::error_code increment() = 0;
159 std::shared_ptr<detail::DirIterImpl> Impl;
163 : Impl(
std::move(I)) {
164 assert(Impl.get() !=
nullptr &&
"requires non-null implementation");
165 if (Impl->CurrentEntry.path().empty())
174 assert(Impl &&
"attempting to increment past end");
175 EC = Impl->increment();
176 if (Impl->CurrentEntry.path().empty())
185 if (Impl && RHS.Impl)
186 return Impl->CurrentEntry.path() == RHS.Impl->CurrentEntry.path();
187 return !Impl && !RHS.Impl;
190 return !(*
this == RHS);
200 std::stack<directory_iterator, std::vector<directory_iterator>>
Stack;
201 bool HasNoPushRequest =
false;
210 std::shared_ptr<detail::RecDirIterState>
215 std::error_code &EC);
227 return State == Other.State;
230 return !(*
this == RHS);
235 assert(!State->Stack.empty() &&
236 "Cannot get level without any iteration state");
237 return State->Stack.size() - 1;
240 void no_push() { State->HasNoPushRequest =
true; }
258 getBufferForFile(
const Twine &Name, int64_t FileSize = -1,
259 bool RequiresNullTerminator =
true,
bool IsVolatile =
false);
264 std::error_code &EC) = 0;
268 virtual std::error_code setCurrentWorkingDirectory(
const Twine &Path) = 0;
276 virtual std::error_code getRealPath(
const Twine &Path,
283 virtual std::error_code isLocal(
const Twine &Path,
bool &Result);
339 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
340 std::error_code isLocal(
const Twine &Path,
bool &Result)
override;
341 std::error_code getRealPath(
const Twine &Path,
372 : FS(
std::move(FS)) {}
375 return FS->status(Path);
379 return FS->openFileForRead(Path);
382 return FS->dir_begin(Dir, EC);
385 return FS->getCurrentWorkingDirectory();
388 return FS->setCurrentWorkingDirectory(Path);
392 return FS->getRealPath(Path, Output);
395 return FS->isLocal(Path, Result);
404 virtual void anchor();
409 class InMemoryDirectory;
416 std::unique_ptr<detail::InMemoryDirectory> Root;
417 std::string WorkingDirectory;
418 bool UseNormalizedPaths =
true;
422 bool addFile(
const Twine &Path, time_t ModificationTime,
423 std::unique_ptr<llvm::MemoryBuffer> Buffer,
439 bool addFile(
const Twine &Path, time_t ModificationTime,
440 std::unique_ptr<llvm::MemoryBuffer> Buffer,
465 bool addFileNoOwn(
const Twine &Path, time_t ModificationTime,
482 return WorkingDirectory;
490 std::error_code getRealPath(
const Twine &Path,
492 std::error_code isLocal(
const Twine &Path,
bool &Result)
override;
493 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
504 StringRef YAMLFilePath,
void *DiagContext =
nullptr,
508 template <
typename T1,
typename T2>
510 : VPath(
std::forward<
T1>(VPath)), RPath(
std::forward<T2>(RPath)) {}
584 virtual ~
Entry() =
default;
591 std::vector<std::unique_ptr<Entry>> Contents;
596 std::vector<std::unique_ptr<Entry>> Contents,
598 :
Entry(EK_Directory, Name), Contents(
std::move(Contents)),
601 :
Entry(EK_Directory, Name), S(
std::move(S)) {}
606 Contents.push_back(std::move(Content));
621 enum NameKind { NK_NotSet, NK_External, NK_Virtual };
624 std::string ExternalContentsPath;
630 :
Entry(EK_File, Name), ExternalContentsPath(ExternalContentsPath),
637 return UseName == NK_NotSet ? GlobalUseExternalName
638 : (UseName == NK_External);
650 bool shouldUseExternalFS()
const {
651 return ExternalFSValidWD && IsFallthrough;
655 std::vector<std::unique_ptr<Entry>> Roots;
658 std::string WorkingDirectory;
661 bool ExternalFSValidWD =
false;
669 std::string ExternalContentsPrefixDir;
677 bool CaseSensitive =
true;
681 bool IsRelativeOverlay =
false;
685 bool UseExternalNames =
true;
689 bool IsFallthrough =
true;
695 bool UseCanonicalizedPaths =
720 create(std::unique_ptr<MemoryBuffer> Buffer,
727 std::error_code getRealPath(
const Twine &Path,
732 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
734 std::error_code isLocal(
const Twine &Path,
bool &Result)
override;
738 void setExternalContentsPrefixDir(
StringRef PrefixDir);
740 StringRef getExternalContentsPrefixDir()
const;
744 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 753 std::unique_ptr<llvm::MemoryBuffer> Buffer,
756 void *DiagContext =
nullptr,
760 std::vector<YAMLVFSEntry> Mappings;
764 std::string OverlayDir;
772 IsCaseSensitive = CaseSensitive;
778 IsOverlayRelative =
true;
779 OverlayDir.assign(OverlayDirectory.
str());
782 const std::vector<YAMLVFSEntry> &
getMappings()
const {
return Mappings; }
790 #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.
typename SuperClass::const_iterator const_iterator
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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
Optional< std::vector< StOtherPiece > > Other
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)
FileSystemList::const_iterator const_reverse_iterator
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...
const_reverse_iterator overlays_rbegin() const
StringRef getName() const
Returns the name that should be used for this file or directory.
static Status copyWithNewName(const Status &In, const Twine &NewName)
Get a copy of a Status with a different name.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
const_iterator overlays_begin() const
void setCaseSensitivity(bool CaseSensitive)
const_reverse_iterator overlays_rend() const
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
FileSystemList::iterator reverse_iterator
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
reverse_iterator overlays_rbegin()
Get an iterator pointing to the least recently added file system.
std::reverse_iterator< iterator > reverse_iterator
std::unique_ptr< FileSystem > createPhysicalFileSystem()
Create an vfs::FileSystem for the 'real' file system, as seen by the operating system.
reverse_iterator overlays_rend()
Get an iterator pointing one-past the most recently added file system.
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
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.
typename SuperClass::iterator iterator
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.