auto merge of #11750 : bnoordhuis/rust/follow-rustc-symlink, r=thestinger

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:
bors 2014-01-24 06:06:33 -08:00
commit a5ab960d2e
3 changed files with 42 additions and 6 deletions

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python
# xfail-license
import glob
import sys
if __name__ == '__main__':
@ -24,7 +25,8 @@ if __name__ == '__main__':
def count(t):
return sum(map(lambda (f, s): len(s.get(t, [])), summaries))
logfiles = sys.argv[1:]
map(summarise, logfiles)
for files in map(glob.glob, logfiles):
map(summarise, files)
ok = count('ok')
failed = count('failed')
ignored = count('ignored')

View file

@ -160,8 +160,24 @@ fn make_rustpkg_target_lib_path(dir: &Path,
}
pub fn get_or_default_sysroot() -> Path {
match os::self_exe_path() {
option::Some(p) => { let mut p = p; p.pop(); p }
// Follow symlinks. If the resolved path is relative, make it absolute.
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")
}
}

View file

@ -337,9 +337,9 @@ pub fn dll_filename(base: &str) -> ~str {
format!("{}{}{}", consts::DLL_PREFIX, base, consts::DLL_SUFFIX)
}
/// Optionally returns the filesystem path to the current executable which is
/// Optionally returns the filesystem path of the current executable which is
/// running. If any failure occurs, None is returned.
pub fn self_exe_path() -> Option<Path> {
pub fn self_exe_name() -> Option<Path> {
#[cfg(target_os = "freebsd")]
fn load_self() -> Option<~[u8]> {
@ -402,7 +402,14 @@ pub fn self_exe_path() -> Option<Path> {
}
}
load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p }))
load_self().and_then(Path::new_opt)
}
/// Optionally returns the filesystem path to the current executable which is
/// running. Like self_exe_name() but without the binary's name.
/// If any failure occurs, None is returned.
pub fn self_exe_path() -> Option<Path> {
self_exe_name().map(|mut p| { p.pop(); p })
}
/**
@ -1310,6 +1317,17 @@ mod tests {
assert_eq!(getenv(n), option::Some(s));
}
#[test]
fn test_self_exe_name() {
let path = os::self_exe_name();
assert!(path.is_some());
let path = path.unwrap();
debug!("{:?}", path.clone());
// Hard to test this function
assert!(path.is_absolute());
}
#[test]
fn test_self_exe_path() {
let path = os::self_exe_path();