Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Support] move FileCollector from LLDB to llvm/Support
The file collector class is useful for creating reproducers, not just for LLDB, but for other tools as well in LLVM/Clang. Differential Revision: https://reviews.llvm.org/D65237 llvm-svn: 366956
- Loading branch information
Showing
8 changed files
with
110 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===-- FileCollector.h -----------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_SUPPORT_FILE_COLLECTOR_H | ||
#define LLVM_SUPPORT_FILE_COLLECTOR_H | ||
|
||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringMap.h" | ||
#include "llvm/ADT/StringSet.h" | ||
#include "llvm/ADT/Twine.h" | ||
#include "llvm/Support/VirtualFileSystem.h" | ||
|
||
#include <mutex> | ||
|
||
namespace llvm { | ||
|
||
/// Collects files into a directory and generates a mapping that can be used by | ||
/// the VFS. | ||
class FileCollector { | ||
public: | ||
FileCollector(std::string root, std::string overlay); | ||
|
||
void AddFile(const Twine &file); | ||
|
||
/// Write the yaml mapping (for the VFS) to the given file. | ||
std::error_code WriteMapping(StringRef mapping_file); | ||
|
||
/// Copy the files into the root directory. | ||
/// | ||
/// When stop_on_error 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. | ||
std::error_code CopyFiles(bool stop_on_error = true); | ||
|
||
private: | ||
void AddFileImpl(StringRef src_path); | ||
|
||
bool MarkAsSeen(StringRef path) { return m_seen.insert(path).second; } | ||
|
||
bool GetRealPath(StringRef src_path, | ||
SmallVectorImpl<char> &result); | ||
|
||
void AddFileToMapping(StringRef virtual_path, | ||
StringRef real_path) { | ||
m_vfs_writer.addFileMapping(virtual_path, real_path); | ||
} | ||
|
||
/// Synchronizes adding files. | ||
std::mutex m_mutex; | ||
|
||
/// The root directory where files are copied. | ||
std::string m_root; | ||
|
||
/// The root directory where the VFS overlay lives. | ||
std::string m_overlay_root; | ||
|
||
/// Tracks already seen files so they can be skipped. | ||
StringSet<> m_seen; | ||
|
||
/// The yaml mapping writer. | ||
vfs::YAMLVFSWriter m_vfs_writer; | ||
|
||
/// Caches real_path calls when resolving symlinks. | ||
StringMap<std::string> m_symlink_map; | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_SUPPORT_FILE_COLLECTOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters