LLVM 20.0.0git
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::FileCollector Class Reference

Captures file system interaction and generates data to be later replayed with the RedirectingFileSystem. More...

#include "llvm/Support/FileCollector.h"

Inheritance diagram for llvm::FileCollector:
Inheritance graph
[legend]

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::FileSystemcreateCollectorVFS (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FileCollector()

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.

Member Function Documentation

◆ addDirectoryImpl()

llvm::vfs::directory_iterator FileCollector::addDirectoryImpl ( const llvm::Twine Dir,
IntrusiveRefCntPtr< vfs::FileSystem FS,
std::error_code &  EC 
)
overrideprotectedvirtual

◆ addFileImpl()

void FileCollector::addFileImpl ( StringRef  SrcPath)
overrideprotectedvirtual

◆ copyFiles()

std::error_code FileCollector::copyFiles ( bool  StopOnError = true)

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.

◆ createCollectorVFS()

IntrusiveRefCntPtr< vfs::FileSystem > FileCollector::createCollectorVFS ( IntrusiveRefCntPtr< vfs::FileSystem BaseFS,
std::shared_ptr< FileCollector Collector 
)
static

Create a VFS that uses Collector to collect files accessed via BaseFS.

Definition at line 314 of file FileCollector.cpp.

References Collector.

◆ writeMapping()

std::error_code FileCollector::writeMapping ( StringRef  MappingFile)

Member Data Documentation

◆ Canonicalizer

PathCanonicalizer llvm::FileCollector::Canonicalizer
protected

Helper utility for canonicalizing paths.

Definition at line 141 of file FileCollector.h.

Referenced by addFileImpl().

◆ OverlayRoot

const std::string llvm::FileCollector::OverlayRoot
protected

The root directory where the VFS overlay lives.

Definition at line 135 of file FileCollector.h.

Referenced by FileCollector(), and writeMapping().

◆ Root

const std::string llvm::FileCollector::Root
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().

◆ VFSWriter

vfs::YAMLVFSWriter llvm::FileCollector::VFSWriter
protected

The yaml mapping writer.

Definition at line 138 of file FileCollector.h.

Referenced by copyFiles(), and writeMapping().


The documentation for this class was generated from the following files: