LLVM  11.0.0git
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"

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

Public Member Functions

 FileCollector (std::string Root, std::string OverlayRoot)
 Root is the directory where collected files are will be stored. More...
 
void addFile (const Twine &file)
 
void addDirectory (const Twine &Dir)
 
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...
 

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)
 
llvm::vfs::directory_iterator addDirectoryImpl (const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC)
 

Protected Attributes

std::mutex Mutex
 Synchronizes access to Seen, VFSWriter and SymlinkMap. More...
 
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...
 
StringSet Seen
 Tracks already seen files so they can be skipped. More...
 
vfs::YAMLVFSWriter VFSWriter
 The yaml mapping writer. More...
 
StringMap< std::string > SymlinkMap
 Caches RealPath calls when resolving symlinks. 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 41 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 35 of file FileCollector.cpp.

References llvm::sys::path::append(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::sys::path::filename(), llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::sys::path::parent_path(), llvm::sys::fs::real_path(), llvm::StringRef::str(), llvm::SmallString< InternalLen >::str(), llvm::SmallVectorImpl< T >::swap(), and SymlinkMap.

Member Function Documentation

◆ addDirectory()

void FileCollector::addDirectory ( const Twine Dir)

◆ addDirectoryImpl()

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

◆ addFile()

void FileCollector::addFile ( const Twine file)

Definition at line 63 of file FileCollector.cpp.

References addFileImpl(), and llvm::Twine::str().

Referenced by addDirectoryImpl().

◆ addFileImpl()

void FileCollector::addFileImpl ( StringRef  SrcPath)
protected

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

◆ writeMapping()

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

Member Data Documentation

◆ Mutex

std::mutex llvm::FileCollector::Mutex
protected

Synchronizes access to Seen, VFSWriter and SymlinkMap.

Definition at line 93 of file FileCollector.h.

◆ OverlayRoot

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

The root directory where the VFS overlay lives.

Definition at line 99 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 96 of file FileCollector.h.

Referenced by addFileImpl().

◆ Seen

StringSet llvm::FileCollector::Seen
protected

Tracks already seen files so they can be skipped.

Definition at line 102 of file FileCollector.h.

◆ SymlinkMap

StringMap<std::string> llvm::FileCollector::SymlinkMap
protected

Caches RealPath calls when resolving symlinks.

Definition at line 108 of file FileCollector.h.

Referenced by FileCollector().

◆ VFSWriter

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

The yaml mapping writer.

Definition at line 105 of file FileCollector.h.

Referenced by writeMapping().


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