Auto merge of #122450 - Urgau:simplify-trim-paths-feature, r=michaelwoerister
Simplify trim-paths feature by merging all debuginfo options together This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in https://github.com/rust-lang/rust/issues/111540#issuecomment-1994010274. And also do some correctness fixes found during the review. cc `@weihanglo` r? `@michaelwoerister`
This commit is contained in:
commit
685927aae6
18 changed files with 142 additions and 184 deletions
|
@ -271,6 +271,18 @@ impl RealFileName {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the path remmapped or not depending on the [`FileNameDisplayPreference`].
|
||||
///
|
||||
/// For the purpose of this function, local and short preference are equal.
|
||||
pub fn to_path(&self, display_pref: FileNameDisplayPreference) -> &Path {
|
||||
match display_pref {
|
||||
FileNameDisplayPreference::Local | FileNameDisplayPreference::Short => {
|
||||
self.local_path_if_available()
|
||||
}
|
||||
FileNameDisplayPreference::Remapped => self.remapped_path_if_available(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string_lossy(&self, display_pref: FileNameDisplayPreference) -> Cow<'_, str> {
|
||||
match display_pref {
|
||||
FileNameDisplayPreference::Local => self.local_path_if_available().to_string_lossy(),
|
||||
|
|
|
@ -1129,6 +1129,21 @@ impl FilePathMapping {
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies any path prefix substitution as defined by the mapping.
|
||||
/// The return value is the local path with a "virtual path" representing the remapped
|
||||
/// part if any remapping was performed.
|
||||
pub fn to_real_filename<'a>(&self, local_path: impl Into<Cow<'a, Path>>) -> RealFileName {
|
||||
let local_path = local_path.into();
|
||||
if let (remapped_path, true) = self.map_prefix(&*local_path) {
|
||||
RealFileName::Remapped {
|
||||
virtual_name: remapped_path.into_owned(),
|
||||
local_path: Some(local_path.into_owned()),
|
||||
}
|
||||
} else {
|
||||
RealFileName::LocalPath(local_path.into_owned())
|
||||
}
|
||||
}
|
||||
|
||||
/// Expand a relative path to an absolute path with remapping taken into account.
|
||||
/// Use this when absolute paths are required (e.g. debuginfo or crate metadata).
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue