LLVM 20.0.0git
|
Captures file system interaction and generates data to be later replayed with the RedirectingFileSystem. More...
#include "llvm/Support/FileCollector.h"
Classes | |
class | PathCanonicalizer |
Helper utility that encapsulates the logic for canonicalizing a virtual path and a path to copy from. More... | |
Public Member Functions | |
FileCollector (std::string Root, std::string OverlayRoot) | |
Root is the directory where collected files are will be stored. | |
std::error_code | writeMapping (StringRef MappingFile) |
Write the yaml mapping (for the VFS) to the given file. | |
std::error_code | copyFiles (bool StopOnError=true) |
Copy the files into the root directory. | |
Public Member Functions inherited from llvm::FileCollectorBase | |
FileCollectorBase () | |
virtual | ~FileCollectorBase () |
void | addFile (const Twine &file) |
void | addDirectory (const Twine &Dir) |
Static Public Member Functions | |
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 . | |
Protected Member Functions | |
void | addFileImpl (StringRef SrcPath) override |
llvm::vfs::directory_iterator | addDirectoryImpl (const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC) override |
Protected Member Functions inherited from llvm::FileCollectorBase | |
bool | markAsSeen (StringRef Path) |
virtual void | addFileImpl (StringRef SrcPath)=0 |
virtual llvm::vfs::directory_iterator | addDirectoryImpl (const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC)=0 |
Protected Attributes | |
const std::string | Root |
The directory where collected files are copied to in copyFiles(). | |
const std::string | OverlayRoot |
The root directory where the VFS overlay lives. | |
vfs::YAMLVFSWriter | VFSWriter |
The yaml mapping writer. | |
PathCanonicalizer | Canonicalizer |
Helper utility for canonicalizing paths. | |
Protected Attributes inherited from llvm::FileCollectorBase | |
std::mutex | Mutex |
Synchronizes access to internal data structures. | |
StringSet | Seen |
Tracks already seen files so they can be skipped. | |
Captures file system interaction and generates data to be later replayed with the RedirectingFileSystem.
For any file that gets accessed we eventually create:
That intent is that later when the mapping is used by RedirectingFileSystem it simulates the state of FS that we collected.
We generate file copies and mapping lazily - see writeMapping and copyFiles. We don't try to capture the state of the file at the exact time when it's accessed. Files might get changed, deleted ... we record only the "final" state.
In order to preserve the relative topology of files we use their real paths as relative paths inside of the Root.
Definition at line 69 of file FileCollector.h.
FileCollector::FileCollector | ( | std::string | Root, |
std::string | OverlayRoot | ||
) |
Root
is the directory where collected files are will be stored.
OverlayRoot
is VFS mapping root. Root
directory gets created in copyFiles unless it already exists.
Definition at line 52 of file FileCollector.cpp.
References assert(), llvm::sys::path::is_absolute(), OverlayRoot, and Root.
|
overrideprotectedvirtual |
Implements llvm::FileCollectorBase.
Definition at line 137 of file FileCollector.cpp.
References llvm::FileCollectorBase::addFile(), llvm::sys::fs::directory_file, llvm::sys::fs::regular_file, and llvm::sys::fs::symlink_file.
|
overrideprotectedvirtual |
Implements llvm::FileCollectorBase.
Definition at line 122 of file FileCollector.cpp.
References llvm::sys::path::append(), llvm::FileCollector::PathCanonicalizer::canonicalize(), Canonicalizer, llvm::FileCollector::PathCanonicalizer::PathStorage::CopyFrom, llvm::sys::path::relative_path(), Root, and llvm::FileCollector::PathCanonicalizer::PathStorage::VirtualPath.
Copy the files into the root directory.
When StopOnError is true (the default) we abort as soon as one file cannot be copied. This is relatively common, for example when a file was removed after it was added to the mapping.
Definition at line 178 of file FileCollector.cpp.
References llvm::sys::fs::copy_file(), copyAccessAndModificationTime(), llvm::sys::fs::create_directories(), llvm::sys::fs::directory_file, llvm::sys::fs::file_not_found, llvm::vfs::YAMLVFSWriter::getMappings(), llvm::sys::fs::getPermissions(), llvm::sys::path::parent_path(), Root, llvm::sys::fs::setPermissions(), llvm::sys::fs::status(), and VFSWriter.
|
static |
Create a VFS that uses Collector
to collect files accessed via BaseFS
.
Definition at line 314 of file FileCollector.cpp.
References Collector.
std::error_code FileCollector::writeMapping | ( | StringRef | MappingFile | ) |
Write the yaml mapping (for the VFS) to the given file.
Definition at line 238 of file FileCollector.cpp.
References isCaseSensitivePath(), llvm::sys::fs::OF_TextWithCRLF, OverlayRoot, llvm::vfs::YAMLVFSWriter::setCaseSensitivity(), llvm::vfs::YAMLVFSWriter::setOverlayDir(), llvm::vfs::YAMLVFSWriter::setUseExternalNames(), VFSWriter, and llvm::vfs::YAMLVFSWriter::write().
|
protected |
Helper utility for canonicalizing paths.
Definition at line 141 of file FileCollector.h.
Referenced by addFileImpl().
|
protected |
The root directory where the VFS overlay lives.
Definition at line 135 of file FileCollector.h.
Referenced by FileCollector(), and writeMapping().
|
protected |
The directory where collected files are copied to in copyFiles().
Definition at line 132 of file FileCollector.h.
Referenced by addFileImpl(), copyFiles(), and FileCollector().
|
protected |
The yaml mapping writer.
Definition at line 138 of file FileCollector.h.
Referenced by copyFiles(), and writeMapping().