about summary refs log tree commit diff
path: root/src/librustc_session
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2020-07-29 09:10:07 -0700
committerAlex Crichton <alex@alexcrichton.com>2020-07-30 08:21:10 -0700
commitcd8bdb5eb9a7440fa64500218f43b04429e64fc1 (patch)
tree30f22100a2b7f99b250a060acbf9099cb56f2b6d /src/librustc_session
parent584e83dd5ae7a75b8214560c22eafbcfe153caa6 (diff)
rustc: Ignore fs::canonicalize errors in metadata
This commit updates the metadata location logic to ignore errors when
calling `fs::canonicalize`. Canonicalization was added historically so
multiple `-L` paths to the same directory don't print errors about
multiple candidates (since rustc can deduplicate same-named paths), but
canonicalization doesn't work on all filesystems. Cargo, for example,
always uses this sort of fallback where it will opportunitistically try
to canonicalize but fall back to using the input path if it otherwise
doesn't work.

If rustc is run on a filesystem that doesn't support canonicalization
then the effect of this change will be that `-L` paths which logically
point to the same directory will cause errors, but that's a rare enough
occurrence it shouldn't cause much issue in practice. Otherwise rustc
doesn't work at all today on those sorts of filesystem where
canonicalization isn't supported!
Diffstat (limited to 'src/librustc_session')
-rw-r--r--src/librustc_session/filesearch.rs32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/librustc_session/filesearch.rs b/src/librustc_session/filesearch.rs
index 27396c524f4..504490d938c 100644
--- a/src/librustc_session/filesearch.rs
+++ b/src/librustc_session/filesearch.rs
@@ -117,28 +117,22 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
 
 pub fn get_or_default_sysroot() -> PathBuf {
     // Follow symlinks.  If the resolved path is relative, make it absolute.
-    fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
-        path.and_then(|path| {
-            match fs::canonicalize(&path) {
-                // See comments on this target function, but the gist is that
-                // gcc chokes on verbatim paths which fs::canonicalize generates
-                // so we try to avoid those kinds of paths.
-                Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)),
-                Err(e) => panic!("failed to get realpath: {}", e),
-            }
-        })
+    fn canonicalize(path: PathBuf) -> PathBuf {
+        let path = fs::canonicalize(&path).unwrap_or(path);
+        // See comments on this target function, but the gist is that
+        // gcc chokes on verbatim paths which fs::canonicalize generates
+        // so we try to avoid those kinds of paths.
+        fix_windows_verbatim_for_gcc(&path)
     }
 
     match env::current_exe() {
-        Ok(exe) => match canonicalize(Some(exe)) {
-            Some(mut p) => {
-                p.pop();
-                p.pop();
-                p
-            }
-            None => panic!("can't determine value for sysroot"),
-        },
-        Err(ref e) => panic!(format!("failed to get current_exe: {}", e)),
+        Ok(exe) => {
+            let mut p = canonicalize(exe);
+            p.pop();
+            p.pop();
+            p
+        }
+        Err(e) => panic!("failed to get current_exe: {}", e),
     }
 }