LLVM  10.0.0svn
FileCollector.h
Go to the documentation of this file.
1 //===-- FileCollector.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_SUPPORT_FILE_COLLECTOR_H
10 #define LLVM_SUPPORT_FILE_COLLECTOR_H
11 
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/ADT/Twine.h"
17 
18 #include <mutex>
19 
20 namespace llvm {
21 
22 /// Collects files into a directory and generates a mapping that can be used by
23 /// the VFS.
25 public:
26  FileCollector(std::string Root, std::string OverlayRoot);
27 
28  void addFile(const Twine &file);
29 
30  /// Write the yaml mapping (for the VFS) to the given file.
31  std::error_code writeMapping(StringRef mapping_file);
32 
33  /// Copy the files into the root directory.
34  ///
35  /// When StopOnError is true (the default) we abort as soon as one file
36  /// cannot be copied. This is relatively common, for example when a file was
37  /// removed after it was added to the mapping.
38  std::error_code copyFiles(bool StopOnError = true);
39 
40  /// Create a VFS that collects all the paths that might be looked at by the
41  /// file system accesses.
44  std::shared_ptr<FileCollector> Collector);
45 
46 private:
47  void addFileImpl(StringRef SrcPath);
48 
49  bool markAsSeen(StringRef Path) { return Seen.insert(Path).second; }
50 
51  bool getRealPath(StringRef SrcPath, SmallVectorImpl<char> &Result);
52 
53  void addFileToMapping(StringRef VirtualPath, StringRef RealPath) {
54  VFSWriter.addFileMapping(VirtualPath, RealPath);
55  }
56 
57 protected:
58  /// Synchronizes adding files.
59  std::mutex Mutex;
60 
61  /// The root directory where files are copied.
62  std::string Root;
63 
64  /// The root directory where the VFS overlay lives.
65  std::string OverlayRoot;
66 
67  /// Tracks already seen files so they can be skipped.
69 
70  /// The yaml mapping writer.
72 
73  /// Caches RealPath calls when resolving symlinks.
75 };
76 
77 } // end namespace llvm
78 
79 #endif // LLVM_SUPPORT_FILE_COLLECTOR_H
*ViewGraph Emit a dot run run gv on the postscript file
Definition: GraphWriter.h:362
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringMap< std::string > SymlinkMap
Caches RealPath calls when resolving symlinks.
Definition: FileCollector.h:74
std::error_code copyFiles(bool StopOnError=true)
Copy the files into the root directory.
Collects files into a directory and generates a mapping that can be used by the VFS.
Definition: FileCollector.h:24
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
std::string OverlayRoot
The root directory where the VFS overlay lives.
Definition: FileCollector.h:65
StringSet Seen
Tracks already seen files so they can be skipped.
Definition: FileCollector.h:68
FileCollector(std::string Root, std::string OverlayRoot)
std::error_code writeMapping(StringRef mapping_file)
Write the yaml mapping (for the VFS) to the given file.
void addFileMapping(StringRef VirtualPath, StringRef RealPath)
vfs::YAMLVFSWriter VFSWriter
The yaml mapping writer.
Definition: FileCollector.h:71
void addFile(const Twine &file)
std::string Root
The root directory where files are copied.
Definition: FileCollector.h:62
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
static IntrusiveRefCntPtr< vfs::FileSystem > createCollectorVFS(IntrusiveRefCntPtr< vfs::FileSystem > BaseFS, std::shared_ptr< FileCollector > Collector)
Create a VFS that collects all the paths that might be looked at by the file system accesses...
Defines the virtual file system interface vfs::FileSystem.
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:27
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Register Usage Information Collector
std::mutex Mutex
Synchronizes adding files.
Definition: FileCollector.h:59