LLVM: lib/Support/FileCollector.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
15
16using namespace llvm;
17
20
22 std::lock_guardstd::mutex lock(Mutex);
23 std::string FileStr = File.str();
26}
27
30 std::error_code EC;
32}
33
36
37
39 return true;
40 Path = TmpDest;
41
42
43
44
45
46 UpperDest = Path.upper();
48 return false;
49 return true;
50}
51
58
59void FileCollector::PathCanonicalizer::updateWithRealPath(
61 StringRef SrcPath(Path.begin(), Path.size());
64
65
66
67
69 auto DirWithSymlink = CachedDirs.find(Directory);
70 if (DirWithSymlink == CachedDirs.end()) {
71
72 if (VFS->getRealPath(Directory, RealPath))
73 return;
74 CachedDirs[Directory] = std::string(RealPath);
75 } else {
76 RealPath = DirWithSymlink->second;
77 }
78
79
80
81
82
83
85
86
87 Path.swap(RealPath);
88}
89
90
92
94
95
97
98
100 StringRef(Path.begin(), Path.size()))
101 .begin());
102}
103
104FileCollector::PathCanonicalizer::PathStorage
109
110
111
112
114 updateWithRealPath(Paths.CopyFrom);
115
116
118
119 return Paths;
120}
121
124
127
128
129
130
131
132
133 addFileToMapping(Paths.VirtualPath, DstPath);
134}
135
139 std::error_code &EC) {
140 auto It = FS->dir_begin(Dir, EC);
141 if (EC)
142 return It;
149 }
150 }
151 if (EC)
152 return It;
153
154 return FS->dir_begin(Dir, EC);
155}
156
157
158
159static std::error_code
162 int FD;
163
164 if (auto EC =
166 return EC;
167
170 return EC;
171
173 return EC;
174
175 return {};
176}
177
180 if (Err) {
181 return Err;
182 }
183
184 std::lock_guardstd::mutex lock(Mutex);
185
186 for (auto &entry : VFSWriter.getMappings()) {
187
189 if (std::error_code EC = sys::fs::status(entry.VPath, Stat)) {
190 if (StopOnError)
191 return EC;
192 continue;
193 }
194
195
197 continue;
198
199
200 if (std::error_code EC =
202 true)) {
203 if (StopOnError)
204 return EC;
205 }
206
208
209 if (std::error_code EC =
211 true)) {
212 if (StopOnError)
213 return EC;
214 }
215 continue;
216 }
217
218
219 if (std::error_code EC = sys::fs::copy_file(entry.VPath, entry.RPath)) {
220 if (StopOnError)
221 return EC;
222 }
223
224
227 if (StopOnError)
228 return EC;
229 }
230 }
231
232
234 }
235 return {};
236}
237
239 std::lock_guardstd::mutex lock(Mutex);
240
243 VFSWriter.setUseExternalNames(false);
244
245 std::error_code EC;
247 if (EC)
248 return EC;
249
251
252 return {};
253}
254
255namespace llvm {
256
258public:
260 std::shared_ptr Collector)
261 : FS(std::move(FS)), Collector(std::move(Collector)) {}
262
264 auto Result = FS->status(Path);
265 if (Result && Result->exists())
266 Collector->addFile(Path);
267 return Result;
268 }
269
272 auto Result = FS->openFileForRead(Path);
273 if (Result && *Result)
274 Collector->addFile(Path);
275 return Result;
276 }
277
279 std::error_code &EC) override {
280 return Collector->addDirectoryImpl(Dir, FS, EC);
281 }
282
285 auto EC = FS->getRealPath(Path, Output);
286 if (!EC) {
287 Collector->addFile(Path);
288 if (Output.size() > 0)
289 Collector->addFile(Output);
290 }
291 return EC;
292 }
293
294 std::error_code isLocal(const Twine &Path, bool &Result) override {
295 return FS->isLocal(Path, Result);
296 }
297
299 return FS->getCurrentWorkingDirectory();
300 }
301
303 return FS->setCurrentWorkingDirectory(Path);
304 }
305
306private:
308 std::shared_ptr Collector;
309};
310
311}
312
313IntrusiveRefCntPtrvfs::FileSystem
315 std::shared_ptr Collector) {
318}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static std::error_code copyAccessAndModificationTime(StringRef Filename, const sys::fs::file_status &Stat)
Set the access and modification time for the given file from the given status object.
Definition FileCollector.cpp:160
static bool isCaseSensitivePath(StringRef Path)
Definition FileCollector.cpp:34
static void makeAbsolute(vfs::FileSystem &VFS, SmallVectorImpl< char > &Path)
Make Path absolute.
Definition FileCollector.cpp:91
Provides a library for accessing information about this process and other processes on the operating ...
Register Usage Information Collector
This file defines the SmallString class.
Represents either an error or a value T.
std::mutex Mutex
Synchronizes access to internal data structures.
void addDirectory(const Twine &Dir)
Definition FileCollector.cpp:28
virtual ~FileCollectorBase()
void addFile(const Twine &file)
Definition FileCollector.cpp:21
virtual llvm::vfs::directory_iterator addDirectoryImpl(const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC)=0
bool markAsSeen(StringRef Path)
virtual void addFileImpl(StringRef SrcPath)=0
FileCollectorFileSystem(IntrusiveRefCntPtr< vfs::FileSystem > FS, std::shared_ptr< FileCollector > Collector)
Definition FileCollector.cpp:259
std::error_code getRealPath(const Twine &Path, SmallVectorImpl< char > &Output) override
Gets real path of Path e.g.
Definition FileCollector.cpp:283
std::error_code setCurrentWorkingDirectory(const llvm::Twine &Path) override
Set the working directory.
Definition FileCollector.cpp:302
std::error_code isLocal(const Twine &Path, bool &Result) override
Is the file mounted on a local filesystem?
Definition FileCollector.cpp:294
llvm::ErrorOr< llvm::vfs::Status > status(const Twine &Path) override
Get the status of the entry at Path, if one exists.
Definition FileCollector.cpp:263
llvm::ErrorOr< std::unique_ptr< llvm::vfs::File > > openFileForRead(const Twine &Path) override
Get a File object for the text file at Path, if one exists.
Definition FileCollector.cpp:271
llvm::vfs::directory_iterator dir_begin(const llvm::Twine &Dir, std::error_code &EC) override
Get a directory_iterator for Dir.
Definition FileCollector.cpp:278
llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const override
Get the working directory of this file system.
Definition FileCollector.cpp:298
LLVM_ABI PathStorage canonicalize(StringRef SrcPath)
Canonicalize a pair of virtual and real paths.
Definition FileCollector.cpp:105
llvm::vfs::directory_iterator addDirectoryImpl(const llvm::Twine &Dir, IntrusiveRefCntPtr< vfs::FileSystem > FS, std::error_code &EC) override
Definition FileCollector.cpp:137
std::error_code writeMapping(StringRef MappingFile)
Write the yaml mapping (for the VFS) to the given file.
Definition FileCollector.cpp:238
FileCollector(std::string Root, std::string OverlayRoot, IntrusiveRefCntPtr< vfs::FileSystem > VFS)
Root is the directory where collected files are will be stored.
Definition FileCollector.cpp:52
std::error_code copyFiles(bool StopOnError=true)
Copy the files into the root directory.
Definition FileCollector.cpp:178
const std::string OverlayRoot
The root directory where the VFS overlay lives.
PathCanonicalizer Canonicalizer
Helper utility for canonicalizing paths.
const std::string Root
The directory where collected files are copied to in copyFiles().
vfs::YAMLVFSWriter VFSWriter
The yaml mapping writer.
void addFileImpl(StringRef SrcPath) override
Definition FileCollector.cpp:122
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.
Definition FileCollector.cpp:314
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A raw_ostream that writes to a file descriptor.
static LLVM_ABI std::error_code SafelyCloseFileDescriptor(int FD)
LLVM_ABI TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
LLVM_ABI TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
Represents the result of a call to sys::fs::status().
The virtual file system interface.
virtual std::error_code makeAbsolute(SmallVectorImpl< char > &Path) const
Make Path an absolute path.
virtual std::error_code getRealPath(const Twine &Path, SmallVectorImpl< char > &Output)
Gets real path of Path e.g.
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
LLVM_ABI ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
LLVM_ABI std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
LLVM_ABI bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI StringRef remove_leading_dotslash(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI StringRef relative_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get relative path.
LLVM_ABI IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
This is an optimization pass for GlobalISel generic memory operations.
IntrusiveRefCntPtr< T > makeIntrusiveRefCnt(Args &&...A)
Factory function for creating intrusive ref counted pointers.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
SmallString< 256 > VirtualPath
SmallString< 256 > CopyFrom