about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
diff options
context:
space:
mode:
authorRyan Levick <ryan.levick@gmail.com>2021-01-26 22:27:42 +0100
committerRyan Levick <ryan.levick@gmail.com>2021-01-29 11:02:12 +0100
commit6c7ecd007f9c8fdf7f5cbbc01837cc04c81a781c (patch)
tree9da1b5ed7a022386d2b38bed8164d7cf112eb80b /compiler/rustc_metadata/src
parentc6bc46227ab57a844fc7a9ed3a6c9efb35c725a9 (diff)
downloadrust-6c7ecd007f9c8fdf7f5cbbc01837cc04c81a781c.tar.gz
rust-6c7ecd007f9c8fdf7f5cbbc01837cc04c81a781c.zip
Pre-canoncalize ExternLocation::ExactPaths
Diffstat (limited to 'compiler/rustc_metadata/src')
-rw-r--r--compiler/rustc_metadata/src/creader.rs10
-rw-r--r--compiler/rustc_metadata/src/locator.rs24
2 files changed, 21 insertions, 13 deletions
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs
index f203094fc73..e3fbd1a2b29 100644
--- a/compiler/rustc_metadata/src/creader.rs
+++ b/compiler/rustc_metadata/src/creader.rs
@@ -28,7 +28,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple};
 
 use proc_macro::bridge::client::ProcMacro;
 use std::path::Path;
-use std::{cmp, env, fs};
+use std::{cmp, env};
 use tracing::{debug, info};
 
 #[derive(Clone)]
@@ -252,10 +252,10 @@ impl<'a> CrateLoader<'a> {
                 // Only use `--extern crate_name=path` here, not `--extern crate_name`.
                 if let Some(mut files) = entry.files() {
                     if files.any(|l| {
-                        let l = fs::canonicalize(l).unwrap_or(l.clone().into());
-                        source.dylib.as_ref().map(|(p, _)| p) == Some(&l)
-                            || source.rlib.as_ref().map(|(p, _)| p) == Some(&l)
-                            || source.rmeta.as_ref().map(|(p, _)| p) == Some(&l)
+                        let l = l.canonicalized();
+                        source.dylib.as_ref().map(|(p, _)| p) == Some(l)
+                            || source.rlib.as_ref().map(|(p, _)| p) == Some(l)
+                            || source.rmeta.as_ref().map(|(p, _)| p) == Some(l)
                     }) {
                         ret = Some(cnum);
                     }
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index c4c025de8b3..b66c6cffb1b 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -224,6 +224,7 @@ use rustc_middle::middle::cstore::{CrateSource, MetadataLoader};
 use rustc_session::config::{self, CrateType};
 use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch};
 use rustc_session::search_paths::PathKind;
+use rustc_session::utils::CanonicalizedPath;
 use rustc_session::{CrateDisambiguator, Session};
 use rustc_span::symbol::{sym, Symbol};
 use rustc_span::Span;
@@ -244,7 +245,7 @@ crate struct CrateLocator<'a> {
 
     // Immutable per-search configuration.
     crate_name: Symbol,
-    exact_paths: Vec<PathBuf>,
+    exact_paths: Vec<CanonicalizedPath>,
     pub hash: Option<Svh>,
     pub host_hash: Option<Svh>,
     extra_filename: Option<&'a str>,
@@ -315,7 +316,7 @@ impl<'a> CrateLocator<'a> {
                     .into_iter()
                     .filter_map(|entry| entry.files())
                     .flatten()
-                    .map(PathBuf::from)
+                    .cloned()
                     .collect()
             } else {
                 // SVH being specified means this is a transitive dependency,
@@ -664,13 +665,19 @@ impl<'a> CrateLocator<'a> {
         let mut rmetas = FxHashMap::default();
         let mut dylibs = FxHashMap::default();
         for loc in &self.exact_paths {
-            if !loc.exists() {
-                return Err(CrateError::ExternLocationNotExist(self.crate_name, loc.clone()));
+            if !loc.canonicalized().exists() {
+                return Err(CrateError::ExternLocationNotExist(
+                    self.crate_name,
+                    loc.original().clone(),
+                ));
             }
-            let file = match loc.file_name().and_then(|s| s.to_str()) {
+            let file = match loc.original().file_name().and_then(|s| s.to_str()) {
                 Some(file) => file,
                 None => {
-                    return Err(CrateError::ExternLocationNotFile(self.crate_name, loc.clone()));
+                    return Err(CrateError::ExternLocationNotFile(
+                        self.crate_name,
+                        loc.original().clone(),
+                    ));
                 }
             };
 
@@ -685,7 +692,8 @@ impl<'a> CrateLocator<'a> {
                 // e.g. symbolic links. If we canonicalize too early, we resolve
                 // the symlink, the file type is lost and we might treat rlibs and
                 // rmetas as dylibs.
-                let loc_canon = fs::canonicalize(&loc).unwrap_or_else(|_| loc.clone());
+                let loc_canon = loc.canonicalized().clone();
+                let loc = loc.original();
                 if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
                     rlibs.insert(loc_canon, PathKind::ExternFlag);
                 } else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") {
@@ -695,7 +703,7 @@ impl<'a> CrateLocator<'a> {
                 }
             } else {
                 self.rejected_via_filename
-                    .push(CrateMismatch { path: loc.clone(), got: String::new() });
+                    .push(CrateMismatch { path: loc.original().clone(), got: String::new() });
             }
         }