22 std::lock_guard<std::mutex> lock(
Mutex);
23 std::string FileStr = File.str();
46 UpperDest = Path.upper();
59void FileCollector::PathCanonicalizer::updateWithRealPath(
61 StringRef SrcPath(Path.begin(), Path.size());
69 auto DirWithSymlink = CachedDirs.
find(Directory);
70 if (DirWithSymlink == CachedDirs.
end()) {
75 CachedDirs[Directory] = std::string(RealPath);
77 RealPath = DirWithSymlink->second;
105FileCollector::PathCanonicalizer::PathStorage
140 std::error_code &EC) {
141 auto It = FS->dir_begin(Dir, EC);
155 return FS->dir_begin(Dir, EC);
160static std::error_code
185 std::lock_guard<std::mutex> lock(
Mutex);
187 for (
auto &entry :
VFSWriter.getMappings()) {
201 if (std::error_code EC =
210 if (std::error_code EC =
240 std::lock_guard<std::mutex> lock(
Mutex);
261 std::shared_ptr<FileCollector> Collector)
265 auto Result = FS->status(Path);
266 if (Result && Result->exists())
267 Collector->addFile(Path);
273 auto Result = FS->openFileForRead(Path);
274 if (Result && *Result)
275 Collector->addFile(Path);
280 std::error_code &EC)
override {
281 return Collector->addDirectoryImpl(Dir, FS, EC);
286 auto EC = FS->getRealPath(Path, Output);
288 Collector->addFile(Path);
289 if (Output.
size() > 0)
290 Collector->addFile(Output);
296 return FS->isLocal(Path, Result);
300 return FS->getCurrentWorkingDirectory();
304 return FS->setCurrentWorkingDirectory(Path);
309 std::shared_ptr<FileCollector>
Collector;
314IntrusiveRefCntPtr<vfs::FileSystem>
316 std::shared_ptr<FileCollector>
Collector) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static std::error_code copyAccessAndModificationTime(StringRef Filename, const sys::fs::file_status &Stat)
Set the access and modification time for the given file from the given status object.
static bool isCaseSensitivePath(StringRef Path)
static void makeAbsolute(vfs::FileSystem &VFS, SmallVectorImpl< char > &Path)
Make Path absolute.
Provides a library for accessing information about this process and other processes on the operating ...
Register Usage Information Collector
This file defines the SmallString class.
Represents either an error or a value T.
std::mutex Mutex
Synchronizes access to internal data structures.
void addDirectory(const Twine &Dir)
virtual ~FileCollectorBase()
void addFile(const Twine &file)
virtual llvm::vfs::directory_iterator addDirectoryImpl(const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC)=0
bool markAsSeen(StringRef Path)
virtual void addFileImpl(StringRef SrcPath)=0
FileCollectorFileSystem(IntrusiveRefCntPtr< vfs::FileSystem > FS, std::shared_ptr< FileCollector > Collector)
std::error_code getRealPath(const Twine &Path, SmallVectorImpl< char > &Output) override
Gets real path of Path e.g.
std::error_code setCurrentWorkingDirectory(const llvm::Twine &Path) override
Set the working directory.
std::error_code isLocal(const Twine &Path, bool &Result) override
Is the file mounted on a local filesystem?
llvm::ErrorOr< llvm::vfs::Status > status(const Twine &Path) override
Get the status of the entry at Path, if one exists.
llvm::ErrorOr< std::unique_ptr< llvm::vfs::File > > openFileForRead(const Twine &Path) override
Get a File object for the text file at Path, if one exists.
llvm::vfs::directory_iterator dir_begin(const llvm::Twine &Dir, std::error_code &EC) override
Get a directory_iterator for Dir.
llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const override
Get the working directory of this file system.
LLVM_ABI PathStorage canonicalize(StringRef SrcPath)
Canonicalize a pair of virtual and real paths.
llvm::vfs::directory_iterator addDirectoryImpl(const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC) override
std::error_code writeMapping(StringRef MappingFile)
Write the yaml mapping (for the VFS) to the given file.
FileCollector(std::string Root, std::string OverlayRoot, IntrusiveRefCntPtr< vfs::FileSystem > VFS)
Root is the directory where collected files are will be stored.
std::error_code copyFiles(bool StopOnError=true)
Copy the files into the root directory.
const std::string OverlayRoot
The root directory where the VFS overlay lives.
PathCanonicalizer Canonicalizer
Helper utility for canonicalizing paths.
const std::string Root
The directory where collected files are copied to in copyFiles().
vfs::YAMLVFSWriter VFSWriter
The yaml mapping writer.
void addFileImpl(StringRef SrcPath) override
static IntrusiveRefCntPtr< vfs::FileSystem > createCollectorVFS(IntrusiveRefCntPtr< vfs::FileSystem > BaseFS, std::shared_ptr< FileCollector > Collector)
Create a VFS that uses Collector to collect files accessed via BaseFS.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A raw_ostream that writes to a file descriptor.
static LLVM_ABI std::error_code SafelyCloseFileDescriptor(int FD)
LLVM_ABI TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
LLVM_ABI TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
Represents the result of a call to sys::fs::status().
The virtual file system interface.
virtual std::error_code makeAbsolute(SmallVectorImpl< char > &Path) const
Make Path an absolute path.
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
LLVM_ABI ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
LLVM_ABI std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
LLVM_ABI bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI StringRef remove_leading_dotslash(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI StringRef relative_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get relative path.
LLVM_ABI IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
This is an optimization pass for GlobalISel generic memory operations.
IntrusiveRefCntPtr< T > makeIntrusiveRefCnt(Args &&...A)
Factory function for creating intrusive ref counted pointers.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
SmallString< 256 > VirtualPath
SmallString< 256 > CopyFrom