Follow symlinks in sysroot
Before this commit, rustc looked in `dirname $0`/../lib for libraries but that doesn't work when rustc is invoked through a symlink. This commit makes rustc look in `dirname $(readlink $0)`/../lib, i.e. it first canonicalizes the symlink before walking up the directory tree. Fixes #3632.
This commit is contained in:
parent
cdd146b895
commit
8cce35e490
1 changed files with 18 additions and 2 deletions
|
@ -160,8 +160,24 @@ fn make_rustpkg_target_lib_path(dir: &Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_or_default_sysroot() -> Path {
|
pub fn get_or_default_sysroot() -> Path {
|
||||||
match os::self_exe_path() {
|
// Follow symlinks. If the resolved path is relative, make it absolute.
|
||||||
option::Some(p) => { let mut p = p; p.pop(); p }
|
fn canonicalize(path: Option<Path>) -> Option<Path> {
|
||||||
|
path.and_then(|mut path|
|
||||||
|
match io::io_error::cond.trap(|_| ()).inside(|| fs::readlink(&path)) {
|
||||||
|
Some(canon) => {
|
||||||
|
if canon.is_absolute() {
|
||||||
|
Some(canon)
|
||||||
|
} else {
|
||||||
|
path.pop();
|
||||||
|
Some(path.join(canon))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => Some(path),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
match canonicalize(os::self_exe_name()) {
|
||||||
|
option::Some(p) => { let mut p = p; p.pop(); p.pop(); p }
|
||||||
option::None => fail!("can't determine value for sysroot")
|
option::None => fail!("can't determine value for sysroot")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue