From cdd146b8954d704a07a4445f00ef8ed0f65da096 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 22 Jan 2014 22:41:53 +0100 Subject: [PATCH 1/3] Add std::os::self_exe_name() --- src/libstd/os.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 93762a3cdd5c7..1b55427fc2dbc 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -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 { +pub fn self_exe_name() -> Option { #[cfg(target_os = "freebsd")] fn load_self() -> Option<~[u8]> { @@ -402,7 +402,14 @@ pub fn self_exe_path() -> Option { } } - 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 { + 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(); From 8cce35e490ce259244656e12d272ab1915b0541b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 22 Jan 2014 23:45:52 +0100 Subject: [PATCH 2/3] 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. --- src/librustc/metadata/filesearch.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index f8e7a28d27708..fd8c620dc4e96 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -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) -> Option { + 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") } } From 51103c89d06953fc534572723f030b292fabe73d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 23 Jan 2014 12:56:10 +0100 Subject: [PATCH 3/3] Make check-summary.py support file globbing Fixes the following error when executing `make check-lite`: Traceback (most recent call last): File "/home/bnoordhuis/src/rust/src/etc/check-summary.py", line 27, in map(summarise, logfiles) File "/home/bnoordhuis/src/rust/src/etc/check-summary.py", line 10, in summarise with open(fname) as fd: IOError: [Errno 2] No such file or directory: 'tmp/*.log' --- src/etc/check-summary.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/etc/check-summary.py b/src/etc/check-summary.py index de777c997299d..dbff82d2b6bbb 100755 --- a/src/etc/check-summary.py +++ b/src/etc/check-summary.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # xfail-license +import glob import sys if __name__ == '__main__': @@ -24,7 +25,8 @@ def summarise(fname): 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')