about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa/back
diff options
context:
space:
mode:
authorFederico Ponzi <isaacisback92@gmail.com>2020-07-18 00:01:27 +0200
committerFederico Ponzi <isaacisback92@gmail.com>2020-07-18 00:01:27 +0200
commit4b6a0278fe2d1c8d74a6bfe5b14c3022ca3b3c46 (patch)
tree4f8beb727fc0bea33c7ead7f353eadde41d948a1 /src/librustc_codegen_ssa/back
parent3014f23ddd437d2ba9947383c4565d09c1eb39f2 (diff)
downloadrust-4b6a0278fe2d1c8d74a6bfe5b14c3022ca3b3c46.tar.gz
rust-4b6a0278fe2d1c8d74a6bfe5b14c3022ca3b3c46.zip
fixes #67108 by using the external crate
Diffstat (limited to 'src/librustc_codegen_ssa/back')
-rw-r--r--src/librustc_codegen_ssa/back/rpath.rs33
1 files changed, 2 insertions, 31 deletions
diff --git a/src/librustc_codegen_ssa/back/rpath.rs b/src/librustc_codegen_ssa/back/rpath.rs
index c02e4f279b1..e1d649c6ed3 100644
--- a/src/librustc_codegen_ssa/back/rpath.rs
+++ b/src/librustc_codegen_ssa/back/rpath.rs
@@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxHashSet;
 use std::env;
 use std::fs;
 use std::path::{Path, PathBuf};
+use pathdiff::diff_paths;
 
 use rustc_hir::def_id::CrateNum;
 use rustc_middle::middle::cstore::LibSource;
@@ -109,37 +110,7 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> Str
 // In particular, this handles the case on unix where both paths are
 // absolute but with only the root as the common directory.
 fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
-    use std::path::Component;
-
-    if path.is_absolute() != base.is_absolute() {
-        path.is_absolute().then(|| PathBuf::from(path))
-    } else {
-        let mut ita = path.components();
-        let mut itb = base.components();
-        let mut comps: Vec<Component<'_>> = vec![];
-        loop {
-            match (ita.next(), itb.next()) {
-                (None, None) => break,
-                (Some(a), None) => {
-                    comps.push(a);
-                    comps.extend(ita.by_ref());
-                    break;
-                }
-                (None, _) => comps.push(Component::ParentDir),
-                (Some(a), Some(b)) if comps.is_empty() && a == b => (),
-                (Some(a), Some(b)) if b == Component::CurDir => comps.push(a),
-                (Some(_), Some(b)) if b == Component::ParentDir => return None,
-                (Some(a), Some(_)) => {
-                    comps.push(Component::ParentDir);
-                    comps.extend(itb.map(|_| Component::ParentDir));
-                    comps.push(a);
-                    comps.extend(ita.by_ref());
-                    break;
-                }
-            }
-        }
-        Some(comps.iter().map(|c| c.as_os_str()).collect())
-    }
+    diff_paths(path, base)
 }
 
 fn get_install_prefix_rpath(config: &mut RPathConfig<'_>) -> String {