When calculating the sysroot, it's more accurate to use realpath() rather than
just one readlink() to account for any intermediate symlinks that the rustc
binary resolves itself to.
For rpath, realpath() is necessary because the rpath must dictate a relative
rpath from the destination back to the originally linked library, which works
more robustly if there are no symlinks involved.
Concretely, any binary generated on OSX into $TMPDIR requires an absolute rpath
because the temporary directory is behind a symlink with one layer of
indirection. This symlink causes all relative rpaths to fail to resolve.
cc #11734
cc #11857
use driver::session::Session;
use metadata::cstore;
use metadata::filesearch;
+use util::fs;
use collections::HashSet;
-use std::{os, slice};
+use std::os;
use syntax::abi;
fn not_win32(os: abi::Os) -> bool {
abi::OsWin32 => unreachable!()
};
- let mut lib = os::make_absolute(lib);
+ let mut lib = fs::realpath(&os::make_absolute(lib)).unwrap();
lib.pop();
- let mut output = os::make_absolute(output);
+ let mut output = fs::realpath(&os::make_absolute(output)).unwrap();
output.pop();
let relative = lib.path_relative_from(&output);
let relative = relative.expect("could not create rpath relative to output");
use std::io::fs;
use collections::HashSet;
+use myfs = util::fs;
+
pub enum FileMatch { FileMatches, FileDoesntMatch }
// A module for searching for libraries
pub fn get_or_default_sysroot() -> Path {
// Follow symlinks. If the resolved path is relative, make it absolute.
fn canonicalize(path: Option<Path>) -> Option<Path> {
- path.and_then(|mut path|
- match fs::readlink(&path) {
- Ok(canon) => {
- if canon.is_absolute() {
- Some(canon)
- } else {
- path.pop();
- Some(path.join(canon))
- }
- },
- Err(..) => Some(path),
+ path.and_then(|path|
+ match myfs::realpath(&path) {
+ Ok(canon) => Some(canon),
+ Err(e) => fail!("failed to get realpath: {}", e),
})
}