about summary refs log tree commit diff
path: root/compiler/rustc_session/src/utils.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-29 10:11:16 +0000
committerbors <bors@rust-lang.org>2021-01-29 10:11:16 +0000
commitc4e33b51c1a2d5e599b949fa3006467b88df253a (patch)
tree6650ae4a6bee22f1b5f37963ee346514a423e4fa /compiler/rustc_session/src/utils.rs
parent099f27b6cbf10e31d41e4a2e6cb55ec39dbb0527 (diff)
parent6c7ecd007f9c8fdf7f5cbbc01837cc04c81a781c (diff)
downloadrust-c4e33b51c1a2d5e599b949fa3006467b88df253a.tar.gz
rust-c4e33b51c1a2d5e599b949fa3006467b88df253a.zip
Auto merge of #81419 - rylev:canocalize-extern-entries, r=petrochenkov
Pre-canoncalize ExternLocation::ExactPaths

This stores pre-canacolized paths inside `ExternLocation::ExactPaths` so that we don't need to canoncalize them every time we want to compare them to source lib paths.

This is related to #81414.
Diffstat (limited to 'compiler/rustc_session/src/utils.rs')
-rw-r--r--compiler/rustc_session/src/utils.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs
index 15447c01d1e..f3d33309124 100644
--- a/compiler/rustc_session/src/utils.rs
+++ b/compiler/rustc_session/src/utils.rs
@@ -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
+    }
+}