Skip to content

Commit

Permalink
auto merge of #11750 : bnoordhuis/rust/follow-rustc-symlink, r=thesti…
Browse files Browse the repository at this point in the history
…nger

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.
  • Loading branch information
bors committed Jan 24, 2014
2 parents 5675f28 + 51103c8 commit a5ab960
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/etc/check-summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# xfail-license

import glob
import sys

if __name__ == '__main__':
Expand All @@ -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')
Expand Down
20 changes: 18 additions & 2 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
24 changes: 21 additions & 3 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]> {
Expand Down Expand Up @@ -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 })
}

/**
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a5ab960

Please sign in to comment.