34std::string NormalizePath(llvm::StringRef path) {
51 std::scoped_lock<std::mutex, std::mutex, std::mutex> locks(
64 llvm::StringRef replacement) {
66 m_pairs.emplace_back(
pair(NormalizePath(path), NormalizePath(replacement)));
71 void *baton =
nullptr;
77 if (notify && callback)
78 callback(*
this, baton);
98 for (pos = rhs.
m_pairs.begin(); pos != end; ++pos)
105 llvm::StringRef replacement,
bool notify) {
106 auto normalized_path = NormalizePath(path);
107 auto normalized_replacement = NormalizePath(replacement);
111 if (llvm::StringRef(
pair.first) == normalized_path &&
112 llvm::StringRef(
pair.second) == normalized_replacement)
122 uint32_t index,
bool notify) {
130 insert_iter =
m_pairs.begin() + index;
132 pair(NormalizePath(path), NormalizePath(replacement)));
138 uint32_t index,
bool notify) {
144 m_pairs[index] =
pair(NormalizePath(path), NormalizePath(replacement));
168 unsigned int numPairs =
m_pairs.size();
170 if (pair_index < 0) {
172 for (index = 0; index < numPairs; ++index)
173 s->
Printf(
"[%d] \"%s\" -> \"%s\"\n", index,
m_pairs[index].first.c_str(),
174 m_pairs[index].second.c_str());
176 if (
static_cast<unsigned int>(pair_index) < numPairs)
178 m_pairs[pair_index].second.c_str());
183 llvm::json::Array entries;
186 llvm::json::Array entry{
pair.first,
pair.second};
187 entries.emplace_back(std::move(entry));
203 std::string &new_path)
const {
204 if (std::optional<FileSpec> remapped =
RemapPath(path)) {
205 new_path = remapped->GetPath();
213 llvm::sys::path::Style style) {
214 auto component = llvm::sys::path::begin(components, style);
215 auto e = llvm::sys::path::end(components);
216 while (component != e &&
217 llvm::sys::path::is_separator(*component->data(), style))
219 for (; component != e; ++component)
224 bool only_if_exists)
const {
226 if (
m_pairs.empty() || mapping_path.empty())
230 for (
const auto &it :
m_pairs) {
231 llvm::StringRef prefix(it.first);
234 llvm::StringRef path = mapping_path;
235 if (!path.consume_front(prefix)) {
247 if (!path_is_relative)
252 llvm::sys::path::Style::native);
260std::optional<llvm::StringRef>
262 std::string path = file.
GetPath();
263 llvm::StringRef path_ref(path);
265 for (
const auto &it :
m_pairs) {
266 llvm::StringRef removed_prefix(it.second);
267 if (!path_ref.consume_front(it.second))
269 llvm::StringRef orig_file(it.first);
271 llvm::sys::path::Style::native);
272 fixed.
SetFile(orig_file, orig_style);
274 return removed_prefix;
279std::optional<FileSpec>
299 m_pairs[idx].second = new_path.str();
326 for (pos = begin; pos != end; ++pos) {
327 if (pos->first == path)
334 std::string &new_path)
const {
338 new_path =
m_pairs[idx].second;
346 const std::string path = NormalizePath(orig_path);
351 for (pos = begin; pos != end; ++pos) {
352 if (pos->first == path)
353 return std::distance(begin, pos);
static void AppendPathComponents(FileSpec &path, llvm::StringRef components, llvm::sys::path::Style style)
Append components to path, applying style.
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.
uint32_t FindIndexForPathNoLock(llvm::StringRef path) const
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)
llvm::json::Value ToJSON() const
bool RemapPath(llvm::StringRef path, std::string &new_path) const
void(* ChangedCallback)(const PathMappingList &path_list, void *baton)
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 AppendNoLock(llvm::StringRef path, llvm::StringRef replacement)
void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify)
iterator FindIteratorForPath(llvm::StringRef path)
std::pair< std::string, std::string > pair
collection::iterator iterator
bool GetPathsAtIndex(uint32_t idx, std::string &path, std::string &new_path) const
uint32_t m_mod_id
Incremented anytime anything is added to or removed from m_pairs.
void Notify(bool notify) const
std::mutex m_callback_mutex
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.