34std::string NormalizePath(llvm::StringRef path) {
44 : m_pairs(), m_callback(callback), m_callback_baton(callback_baton) {}
47 : m_pairs(rhs.m_pairs) {}
51 std::scoped_lock<std::recursive_mutex, std::recursive_mutex> locks(
m_mutex, rhs.
m_mutex);
64 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
66 m_pairs.emplace_back(
pair(NormalizePath(path), NormalizePath(replacement)));
72 std::scoped_lock<std::recursive_mutex, std::recursive_mutex> locks(
m_mutex, rhs.
m_mutex);
76 for (pos = rhs.
m_pairs.begin(); pos != end; ++pos)
84 llvm::StringRef replacement,
bool notify) {
85 auto normalized_path = NormalizePath(path);
86 auto normalized_replacement = NormalizePath(replacement);
87 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
89 if (
pair.first.GetStringRef() == normalized_path &&
90 pair.second.GetStringRef() == normalized_replacement)
93 Append(path, replacement, notify);
98 uint32_t index,
bool notify) {
99 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
105 insert_iter =
m_pairs.begin() + index;
106 m_pairs.emplace(insert_iter,
pair(NormalizePath(path),
107 NormalizePath(replacement)));
113 uint32_t index,
bool notify) {
114 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
118 m_pairs[index] =
pair(NormalizePath(path), NormalizePath(replacement));
125 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
140 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
141 unsigned int numPairs =
m_pairs.size();
143 if (pair_index < 0) {
145 for (index = 0; index < numPairs; ++index)
146 s->
Printf(
"[%d] \"%s\" -> \"%s\"\n", index,
147 m_pairs[index].first.GetCString(),
148 m_pairs[index].second.GetCString());
150 if (
static_cast<unsigned int>(pair_index) < numPairs)
151 s->
Printf(
"%s -> %s",
m_pairs[pair_index].first.GetCString(),
152 m_pairs[pair_index].second.GetCString());
157 llvm::json::Array entries;
158 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
160 llvm::json::Array entry{
pair.first.GetStringRef().str(),
161 pair.second.GetStringRef().str()};
162 entries.emplace_back(std::move(entry));
168 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
187 llvm::sys::path::Style style) {
188 auto component = llvm::sys::path::begin(components, style);
189 auto e = llvm::sys::path::end(components);
190 while (component != e &&
191 llvm::sys::path::is_separator(*component->data(), style))
193 for (; component != e; ++component)
198 bool only_if_exists)
const {
199 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
200 if (
m_pairs.empty() || mapping_path.empty())
204 for (
const auto &it :
m_pairs) {
205 llvm::StringRef prefix = it.first.GetStringRef();
208 llvm::StringRef path = mapping_path;
209 if (!path.consume_front(prefix)) {
221 if (!path_is_relative)
224 FileSpec remapped(it.second.GetStringRef());
226 llvm::sys::path::Style::native);
234std::optional<llvm::StringRef>
236 std::string path = file.
GetPath();
237 llvm::StringRef path_ref(path);
238 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
239 for (
const auto &it :
m_pairs) {
240 llvm::StringRef removed_prefix = it.second.GetStringRef();
241 if (!path_ref.consume_front(it.second.GetStringRef()))
243 auto orig_file = it.first.GetStringRef();
245 llvm::sys::path::Style::native);
246 fixed.
SetFile(orig_file, orig_style);
248 return removed_prefix;
253std::optional<FileSpec>
267 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
280 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
294 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
299 for (pos = begin; pos != end; ++pos) {
300 if (pos->first == path)
308 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
313 for (pos = begin; pos != end; ++pos) {
314 if (pos->first == path)
322 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
325 new_path =
m_pairs[idx].second;
333 std::lock_guard<std::recursive_mutex> lock(
m_mutex);
338 for (pos = begin; pos != end; ++pos) {
339 if (pos->first == path)
340 return std::distance(begin, pos);
static void AppendPathComponents(FileSpec &path, llvm::StringRef components, llvm::sys::path::Style style)
Append components to path, applying style.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
void AppendPathComponent(llvm::StringRef component)
static std::optional< Style > GuessPathStyle(llvm::StringRef absolute_path)
Attempt to guess path style for a given path string.
bool IsRelative() const
Returns true if the filespec represents a relative path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
bool Remove(size_t index, bool notify)
bool AppendUnique(llvm::StringRef path, llvm::StringRef replacement, bool notify)
Append <path, replacement> pair without duplication.
iterator FindIteratorForPath(ConstString path)
std::optional< FileSpec > FindFile(const FileSpec &orig_spec) const
Finds a source file given a file spec using the path remappings.
bool Replace(llvm::StringRef path, llvm::StringRef replacement, bool notify)
std::recursive_mutex m_mutex
uint32_t FindIndexForPath(llvm::StringRef path) const
void Insert(llvm::StringRef path, llvm::StringRef replacement, uint32_t insert_idx, bool notify)
collection::const_iterator const_iterator
ChangedCallback m_callback
const PathMappingList & operator=(const PathMappingList &rhs)
void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify)
bool RemapPath(ConstString path, ConstString &new_path) const
bool GetPathsAtIndex(uint32_t idx, ConstString &path, ConstString &new_path) const
collection::iterator iterator
std::pair< ConstString, ConstString > pair
llvm::json::Value ToJSON()
std::optional< llvm::StringRef > ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const
Perform reverse source path remap for input file.
void Dump(Stream *s, int pair_index=-1)
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
A class that represents a running process on the host machine.