LLVM  14.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]
Collaboration diagram for llvm::FileCollector:
Collaboration 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. More...
 
std::error_code writeMapping (StringRef MappingFile)
 Write the yaml mapping (for the VFS) to the given file. More...
 
std::error_code copyFiles (bool StopOnError=true)
 Copy the files into the root directory. More...
 
- 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. More...
 

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)
 

Protected Attributes

const std::string Root
 The directory where collected files are copied to in copyFiles(). More...
 
const std::string OverlayRoot
 The root directory where the VFS overlay lives. More...
 
vfs::YAMLVFSWriter VFSWriter
 The yaml mapping writer. More...
 
PathCanonicalizer Canonicalizer
 Helper utility for canonicalizing paths. More...
 
- Protected Attributes inherited from llvm::FileCollectorBase
std::mutex Mutex
 Synchronizes access to internal data structures. More...
 
StringSet Seen
 Tracks already seen files so they can be skipped. More...
 

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 70 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.

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 176 of file FileCollector.cpp.

◆ 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 312 of file FileCollector.cpp.

References Collector, and move.

◆ 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 142 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 136 of file FileCollector.h.

Referenced by writeMapping().

◆ Root

const std::string llvm::FileCollector::Root
protected

The directory where collected files are copied to in copyFiles().

Definition at line 133 of file FileCollector.h.

Referenced by addFileImpl().

◆ VFSWriter

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

The yaml mapping writer.

Definition at line 139 of file FileCollector.h.

Referenced by writeMapping().


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