Skip to content

Commit 4b6a027

Browse files
author
Federico Ponzi
committed
fixes #67108 by using the external crate
1 parent 3014f23 commit 4b6a027

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

Cargo.lock

+7
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,12 @@ dependencies = [
21422142
"winapi 0.3.8",
21432143
]
21442144

2145+
[[package]]
2146+
name = "pathdiff"
2147+
version = "0.2.0"
2148+
source = "registry+https://github.com/rust-lang/crates.io-index"
2149+
checksum = "877630b3de15c0b64cc52f659345724fbf6bdad9bd9566699fc53688f3c34a34"
2150+
21452151
[[package]]
21462152
name = "percent-encoding"
21472153
version = "1.0.1"
@@ -3318,6 +3324,7 @@ dependencies = [
33183324
"log",
33193325
"memmap",
33203326
"num_cpus",
3327+
"pathdiff",
33213328
"rustc_apfloat",
33223329
"rustc_ast",
33233330
"rustc_attr",

src/librustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ log = "0.4.5"
1818
libc = "0.2.50"
1919
jobserver = "0.1.11"
2020
tempfile = "3.1"
21+
pathdiff = "0.2.0"
2122

2223
rustc_serialize = { path = "../librustc_serialize" }
2324
rustc_ast = { path = "../librustc_ast" }

src/librustc_codegen_ssa/back/rpath.rs

+2-31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxHashSet;
22
use std::env;
33
use std::fs;
44
use std::path::{Path, PathBuf};
5+
use pathdiff::diff_paths;
56

67
use rustc_hir::def_id::CrateNum;
78
use rustc_middle::middle::cstore::LibSource;
@@ -109,37 +110,7 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> Str
109110
// In particular, this handles the case on unix where both paths are
110111
// absolute but with only the root as the common directory.
111112
fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
112-
use std::path::Component;
113-
114-
if path.is_absolute() != base.is_absolute() {
115-
path.is_absolute().then(|| PathBuf::from(path))
116-
} else {
117-
let mut ita = path.components();
118-
let mut itb = base.components();
119-
let mut comps: Vec<Component<'_>> = vec![];
120-
loop {
121-
match (ita.next(), itb.next()) {
122-
(None, None) => break,
123-
(Some(a), None) => {
124-
comps.push(a);
125-
comps.extend(ita.by_ref());
126-
break;
127-
}
128-
(None, _) => comps.push(Component::ParentDir),
129-
(Some(a), Some(b)) if comps.is_empty() && a == b => (),
130-
(Some(a), Some(b)) if b == Component::CurDir => comps.push(a),
131-
(Some(_), Some(b)) if b == Component::ParentDir => return None,
132-
(Some(a), Some(_)) => {
133-
comps.push(Component::ParentDir);
134-
comps.extend(itb.map(|_| Component::ParentDir));
135-
comps.push(a);
136-
comps.extend(ita.by_ref());
137-
break;
138-
}
139-
}
140-
}
141-
Some(comps.iter().map(|c| c.as_os_str()).collect())
142-
}
113+
diff_paths(path, base)
143114
}
144115

145116
fn get_install_prefix_rpath(config: &mut RPathConfig<'_>) -> String {

0 commit comments

Comments
 (0)