Add debug tracing to FilePathMapping::map_prefix

This commit is contained in:
Michael Woerister 2022-05-05 17:01:39 +02:00
parent 77972d2d01
commit 90fce805a3

View File

@ -1098,10 +1098,20 @@ impl FilePathMapping {
/// The return value is the remapped path and a boolean indicating whether
/// the path was affected by the mapping.
pub fn map_prefix(&self, path: PathBuf) -> (PathBuf, bool) {
if path.as_os_str().is_empty() {
return (path, false);
}
return remap_path_prefix(&self.mapping, path);
#[instrument(level = "debug", skip(mapping))]
fn remap_path_prefix(mapping: &[(PathBuf, PathBuf)], path: PathBuf) -> (PathBuf, bool) {
// NOTE: We are iterating over the mapping entries from last to first
// because entries specified later on the command line should
// take precedence.
for &(ref from, ref to) in self.mapping.iter().rev() {
for &(ref from, ref to) in mapping.iter().rev() {
debug!("Trying to apply {:?} => {:?}", from, to);
if let Ok(rest) = path.strip_prefix(from) {
let remapped = if rest.as_os_str().is_empty() {
// This is subtle, joining an empty path onto e.g. `foo/bar` will
@ -1114,13 +1124,18 @@ impl FilePathMapping {
} else {
to.join(rest)
};
debug!("Match - remapped {:?} => {:?}", path, remapped);
return (remapped, true);
} else {
debug!("No match - prefix {:?} does not match {:?}", from, path);
}
}
debug!("Path {:?} was not remapped", path);
(path, false)
}
}
fn map_filename_prefix(&self, file: &FileName) -> (FileName, bool) {
match file {