Pre-canoncalize ExternLocation::ExactPaths

This commit is contained in:
Ryan Levick
2021-01-26 22:27:42 +01:00
parent c6bc46227a
commit 6c7ecd007f
5 changed files with 54 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
use crate::session::Session;
use rustc_data_structures::profiling::VerboseTimingGuard;
use std::path::{Path, PathBuf};
impl Session {
pub fn timer<'a>(&'a self, what: &'static str) -> VerboseTimingGuard<'a> {
@@ -30,3 +31,25 @@ pub enum NativeLibKind {
}
rustc_data_structures::impl_stable_hash_via_hash!(NativeLibKind);
/// A path that has been canonicalized along with its original, non-canonicalized form
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct CanonicalizedPath {
// Optional since canonicalization can sometimes fail
canonicalized: Option<PathBuf>,
original: PathBuf,
}
impl CanonicalizedPath {
pub fn new(path: &Path) -> Self {
Self { original: path.to_owned(), canonicalized: std::fs::canonicalize(path).ok() }
}
pub fn canonicalized(&self) -> &PathBuf {
self.canonicalized.as_ref().unwrap_or(self.original())
}
pub fn original(&self) -> &PathBuf {
&self.original
}
}