Skip to content

Follow symlinks in sysroot #11750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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