mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Add debug tracing to FilePathMapping::map_prefix
This commit is contained in:
parent
77972d2d01
commit
90fce805a3
@ -1098,28 +1098,43 @@ 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) {
|
||||
// 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() {
|
||||
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
|
||||
// result in `foo/bar/`, that is, there'll be an additional directory
|
||||
// separator at the end. This can lead to duplicated directory separators
|
||||
// in remapped paths down the line.
|
||||
// So, if we have an exact match, we just return that without a call
|
||||
// to `Path::join()`.
|
||||
to.clone()
|
||||
} else {
|
||||
to.join(rest)
|
||||
};
|
||||
|
||||
return (remapped, true);
|
||||
}
|
||||
if path.as_os_str().is_empty() {
|
||||
return (path, false);
|
||||
}
|
||||
|
||||
(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 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
|
||||
// result in `foo/bar/`, that is, there'll be an additional directory
|
||||
// separator at the end. This can lead to duplicated directory separators
|
||||
// in remapped paths down the line.
|
||||
// So, if we have an exact match, we just return that without a call
|
||||
// to `Path::join()`.
|
||||
to.clone()
|
||||
} 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user