Skip to content

Commit a5ab960

Browse files
committed
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.
2 parents 5675f28 + 51103c8 commit a5ab960

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/etc/check-summary.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# xfail-license
33

4+
import glob
45
import sys
56

67
if __name__ == '__main__':
@@ -24,7 +25,8 @@ def summarise(fname):
2425
def count(t):
2526
return sum(map(lambda (f, s): len(s.get(t, [])), summaries))
2627
logfiles = sys.argv[1:]
27-
map(summarise, logfiles)
28+
for files in map(glob.glob, logfiles):
29+
map(summarise, files)
2830
ok = count('ok')
2931
failed = count('failed')
3032
ignored = count('ignored')

src/librustc/metadata/filesearch.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,24 @@ fn make_rustpkg_target_lib_path(dir: &Path,
160160
}
161161

162162
pub fn get_or_default_sysroot() -> Path {
163-
match os::self_exe_path() {
164-
option::Some(p) => { let mut p = p; p.pop(); p }
163+
// Follow symlinks. If the resolved path is relative, make it absolute.
164+
fn canonicalize(path: Option<Path>) -> Option<Path> {
165+
path.and_then(|mut path|
166+
match io::io_error::cond.trap(|_| ()).inside(|| fs::readlink(&path)) {
167+
Some(canon) => {
168+
if canon.is_absolute() {
169+
Some(canon)
170+
} else {
171+
path.pop();
172+
Some(path.join(canon))
173+
}
174+
},
175+
None => Some(path),
176+
})
177+
}
178+
179+
match canonicalize(os::self_exe_name()) {
180+
option::Some(p) => { let mut p = p; p.pop(); p.pop(); p }
165181
option::None => fail!("can't determine value for sysroot")
166182
}
167183
}

src/libstd/os.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ pub fn dll_filename(base: &str) -> ~str {
337337
format!("{}{}{}", consts::DLL_PREFIX, base, consts::DLL_SUFFIX)
338338
}
339339

340-
/// Optionally returns the filesystem path to the current executable which is
340+
/// Optionally returns the filesystem path of the current executable which is
341341
/// running. If any failure occurs, None is returned.
342-
pub fn self_exe_path() -> Option<Path> {
342+
pub fn self_exe_name() -> Option<Path> {
343343

344344
#[cfg(target_os = "freebsd")]
345345
fn load_self() -> Option<~[u8]> {
@@ -402,7 +402,14 @@ pub fn self_exe_path() -> Option<Path> {
402402
}
403403
}
404404

405-
load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p }))
405+
load_self().and_then(Path::new_opt)
406+
}
407+
408+
/// Optionally returns the filesystem path to the current executable which is
409+
/// running. Like self_exe_name() but without the binary's name.
410+
/// If any failure occurs, None is returned.
411+
pub fn self_exe_path() -> Option<Path> {
412+
self_exe_name().map(|mut p| { p.pop(); p })
406413
}
407414

408415
/**
@@ -1310,6 +1317,17 @@ mod tests {
13101317
assert_eq!(getenv(n), option::Some(s));
13111318
}
13121319
1320+
#[test]
1321+
fn test_self_exe_name() {
1322+
let path = os::self_exe_name();
1323+
assert!(path.is_some());
1324+
let path = path.unwrap();
1325+
debug!("{:?}", path.clone());
1326+
1327+
// Hard to test this function
1328+
assert!(path.is_absolute());
1329+
}
1330+
13131331
#[test]
13141332
fn test_self_exe_path() {
13151333
let path = os::self_exe_path();

0 commit comments

Comments
 (0)