2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-09-04 13:54:36 -05:00
|
|
|
use driver::session;
|
2012-12-23 16:41:37 -06:00
|
|
|
use metadata::cstore;
|
2012-09-04 13:54:36 -05:00
|
|
|
use metadata::filesearch;
|
2011-10-04 17:23:32 -05:00
|
|
|
|
2012-12-23 16:41:37 -06:00
|
|
|
use core::util;
|
2013-04-03 08:28:36 -05:00
|
|
|
use core::hashmap::HashSet;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2013-03-22 13:09:13 -05:00
|
|
|
fn not_win32(os: session::os) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match os {
|
2012-08-03 21:59:04 -05:00
|
|
|
session::os_win32 => false,
|
|
|
|
_ => true
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
|
|
|
|
-> ~[~str] {
|
2012-01-12 10:59:49 -06:00
|
|
|
let os = sess.targ_cfg.os;
|
2011-10-06 16:28:52 -05:00
|
|
|
|
2011-10-06 15:11:56 -05:00
|
|
|
// No rpath on windows
|
2011-10-06 16:28:52 -05:00
|
|
|
if os == session::os_win32 {
|
2012-08-01 19:30:05 -05:00
|
|
|
return ~[];
|
2011-10-06 15:11:56 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("preparing the RPATH!");
|
2011-10-04 17:23:32 -05:00
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
let sysroot = sess.filesearch.sysroot();
|
2011-10-04 17:23:32 -05:00
|
|
|
let output = out_filename;
|
2012-01-12 10:59:49 -06:00
|
|
|
let libs = cstore::get_used_crate_files(sess.cstore);
|
2012-07-03 18:11:00 -05:00
|
|
|
// We don't currently rpath extern libraries, but we know
|
2011-10-05 01:12:46 -05:00
|
|
|
// where rustrt is and we know every rust program needs it
|
2012-06-28 17:00:03 -05:00
|
|
|
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));
|
2011-10-05 01:12:46 -05:00
|
|
|
|
2013-05-03 18:47:53 -05:00
|
|
|
let rpaths = get_rpaths(os, sysroot, output, libs,
|
2013-03-20 00:17:42 -05:00
|
|
|
sess.opts.target_triple);
|
2011-10-05 01:36:06 -05:00
|
|
|
rpaths_to_flags(rpaths)
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2012-10-15 16:56:42 -05:00
|
|
|
fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
|
2012-08-24 17:28:43 -05:00
|
|
|
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
|
|
|
|
sess.filesearch.sysroot().push_rel(&r).push(os::dll_filename("rustrt"))
|
2011-10-05 01:12:46 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn rpaths_to_flags(rpaths: &[Path]) -> ~[~str] {
|
2012-08-24 17:28:43 -05:00
|
|
|
vec::map(rpaths, |rpath| fmt!("-Wl,-rpath,%s",rpath.to_str()))
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:28:43 -05:00
|
|
|
fn get_rpaths(os: session::os,
|
|
|
|
sysroot: &Path,
|
|
|
|
output: &Path,
|
|
|
|
libs: &[Path],
|
|
|
|
target_triple: &str) -> ~[Path] {
|
|
|
|
debug!("sysroot: %s", sysroot.to_str());
|
|
|
|
debug!("output: %s", output.to_str());
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("libs:");
|
2012-06-30 18:19:07 -05:00
|
|
|
for libs.each |libpath| {
|
2012-08-24 17:28:43 -05:00
|
|
|
debug!(" %s", libpath.to_str());
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("target_triple: %s", target_triple);
|
2011-10-04 17:23:32 -05:00
|
|
|
|
|
|
|
// Use relative paths to the libraries. Binaries can be moved
|
|
|
|
// as long as they maintain the relative relationship to the
|
|
|
|
// crates they depend on.
|
2012-08-24 17:28:43 -05:00
|
|
|
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);
|
2011-10-04 17:23:32 -05:00
|
|
|
|
|
|
|
// Make backup absolute paths to the libraries. Binaries can
|
|
|
|
// be moved as long as the crates they link against don't move.
|
2012-08-24 17:28:43 -05:00
|
|
|
let abs_rpaths = get_absolute_rpaths(libs);
|
2011-10-04 17:23:32 -05:00
|
|
|
|
|
|
|
// And a final backup rpath to the global library location.
|
2012-08-24 17:28:43 -05:00
|
|
|
let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];
|
2011-10-05 00:40:38 -05:00
|
|
|
|
2012-08-24 17:28:43 -05:00
|
|
|
fn log_rpaths(desc: &str, rpaths: &[Path]) {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("%s rpaths:", desc);
|
2012-06-30 18:19:07 -05:00
|
|
|
for rpaths.each |rpath| {
|
2012-08-24 17:28:43 -05:00
|
|
|
debug!(" %s", rpath.to_str());
|
2011-10-05 00:40:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
log_rpaths("relative", rel_rpaths);
|
|
|
|
log_rpaths("absolute", abs_rpaths);
|
|
|
|
log_rpaths("fallback", fallback_rpaths);
|
2011-10-05 00:40:38 -05:00
|
|
|
|
2012-06-28 17:00:03 -05:00
|
|
|
let mut rpaths = rel_rpaths;
|
2012-09-26 19:33:34 -05:00
|
|
|
rpaths.push_all(abs_rpaths);
|
|
|
|
rpaths.push_all(fallback_rpaths);
|
2011-10-04 17:23:32 -05:00
|
|
|
|
|
|
|
// Remove duplicates
|
|
|
|
let rpaths = minimize_rpaths(rpaths);
|
2012-08-01 19:30:05 -05:00
|
|
|
return rpaths;
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2011-10-06 16:28:52 -05:00
|
|
|
fn get_rpaths_relative_to_output(os: session::os,
|
2012-08-24 17:28:43 -05:00
|
|
|
output: &Path,
|
|
|
|
libs: &[Path]) -> ~[Path] {
|
2012-06-30 18:19:07 -05:00
|
|
|
vec::map(libs, |a| {
|
2012-09-21 20:43:30 -05:00
|
|
|
get_rpath_relative_to_output(os, output, a)
|
2012-06-19 21:34:01 -05:00
|
|
|
})
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn get_rpath_relative_to_output(os: session::os,
|
|
|
|
output: &Path,
|
|
|
|
lib: &Path)
|
|
|
|
-> Path {
|
2012-12-27 17:49:26 -06:00
|
|
|
use core::os;
|
|
|
|
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(not_win32(os));
|
2012-07-13 20:43:52 -05:00
|
|
|
|
2011-10-06 16:28:52 -05:00
|
|
|
// Mac doesn't appear to support $ORIGIN
|
2012-08-06 14:34:08 -05:00
|
|
|
let prefix = match os {
|
2012-11-29 18:21:49 -06:00
|
|
|
session::os_android |session::os_linux | session::os_freebsd
|
|
|
|
=> "$ORIGIN",
|
2012-08-24 17:28:43 -05:00
|
|
|
session::os_macos => "@executable_path",
|
2012-12-23 16:41:37 -06:00
|
|
|
session::os_win32 => util::unreachable()
|
2011-10-06 16:28:52 -05:00
|
|
|
};
|
|
|
|
|
2012-08-24 17:28:43 -05:00
|
|
|
Path(prefix).push_rel(&get_relative_to(&os::make_absolute(output),
|
|
|
|
&os::make_absolute(lib)))
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the relative path from one file to another
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(abs1.is_absolute);
|
|
|
|
assert!(abs2.is_absolute);
|
2012-08-29 15:59:02 -05:00
|
|
|
let abs1 = abs1.normalize();
|
|
|
|
let abs2 = abs2.normalize();
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("finding relative path from %s to %s",
|
2012-08-24 17:28:43 -05:00
|
|
|
abs1.to_str(), abs2.to_str());
|
2013-03-20 00:17:42 -05:00
|
|
|
let split1: &[~str] = abs1.components;
|
|
|
|
let split2: &[~str] = abs2.components;
|
2013-05-14 04:52:12 -05:00
|
|
|
let len1 = split1.len();
|
|
|
|
let len2 = split2.len();
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(len1 > 0);
|
|
|
|
assert!(len2 > 0);
|
2011-10-04 22:07:18 -05:00
|
|
|
|
2012-08-30 14:54:50 -05:00
|
|
|
let max_common_path = uint::min(len1, len2) - 1;
|
|
|
|
let mut start_idx = 0;
|
2011-10-04 22:07:18 -05:00
|
|
|
while start_idx < max_common_path
|
|
|
|
&& split1[start_idx] == split2[start_idx] {
|
2012-08-30 14:54:50 -05:00
|
|
|
start_idx += 1;
|
2011-10-04 22:07:18 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut path = ~[];
|
2012-09-26 19:33:34 -05:00
|
|
|
for uint::range(start_idx, len1 - 1) |_i| { path.push(~".."); };
|
2011-10-04 22:07:18 -05:00
|
|
|
|
2013-02-08 13:28:20 -06:00
|
|
|
path.push_all(vec::slice(split2, start_idx, len2 - 1));
|
2011-10-04 22:07:18 -05:00
|
|
|
|
2013-01-24 22:24:57 -06:00
|
|
|
if !path.is_empty() {
|
2012-08-24 17:28:43 -05:00
|
|
|
return Path("").push_many(path);
|
2011-10-05 00:40:38 -05:00
|
|
|
} else {
|
2012-08-24 17:28:43 -05:00
|
|
|
return Path(".");
|
2011-10-05 00:40:38 -05:00
|
|
|
}
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:28:43 -05:00
|
|
|
fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
|
2012-09-21 20:43:30 -05:00
|
|
|
vec::map(libs, |a| get_absolute_rpath(a) )
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn get_absolute_rpath(lib: &Path) -> Path {
|
2012-08-24 17:28:43 -05:00
|
|
|
os::make_absolute(lib).dir_path()
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
|
2012-08-22 19:24:52 -05:00
|
|
|
let install_prefix = env!("CFG_PREFIX");
|
2011-10-04 17:23:32 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if install_prefix == ~"" {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("rustc compiled without CFG_PREFIX environment variable");
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:28:43 -05:00
|
|
|
let tlib = filesearch::relative_target_lib_path(target_triple);
|
|
|
|
os::make_absolute(&Path(install_prefix).push_rel(&tlib))
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
|
2013-04-03 08:28:36 -05:00
|
|
|
let mut set = HashSet::new();
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut minimized = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for rpaths.each |rpath| {
|
2013-02-08 20:04:28 -06:00
|
|
|
if set.insert(rpath.to_str()) {
|
|
|
|
minimized.push(copy *rpath);
|
2011-10-05 00:40:38 -05:00
|
|
|
}
|
|
|
|
}
|
2013-02-08 20:04:28 -06:00
|
|
|
minimized
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2012-06-07 23:38:25 -05:00
|
|
|
#[cfg(unix)]
|
2011-10-04 17:23:32 -05:00
|
|
|
mod test {
|
2013-02-28 01:27:18 -06:00
|
|
|
// FIXME(#2119): the outer attribute should be #[cfg(unix, test)], then
|
|
|
|
// these redundant #[cfg(test)] blocks can be removed
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
2013-01-08 21:37:25 -06:00
|
|
|
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
|
2013-02-28 01:27:18 -06:00
|
|
|
#[cfg(test)]
|
2013-01-08 21:37:25 -06:00
|
|
|
use back::rpath::{get_relative_to, get_rpath_relative_to_output};
|
2013-02-28 01:27:18 -06:00
|
|
|
#[cfg(test)]
|
2013-01-08 21:37:25 -06:00
|
|
|
use back::rpath::{minimize_rpaths, rpaths_to_flags};
|
2013-02-28 10:57:33 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
use driver::session;
|
2012-12-27 17:49:26 -06:00
|
|
|
|
2011-10-04 17:23:32 -05:00
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_rpaths_to_flags() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let flags = rpaths_to_flags(~[Path("path1"),
|
|
|
|
Path("path2")]);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(flags, ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_prefix_rpath() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let res = get_install_prefix_rpath("triple");
|
|
|
|
let d = Path(env!("CFG_PREFIX"))
|
|
|
|
.push_rel(&Path("lib/rustc/triple/lib"));
|
|
|
|
debug!("test_prefix_path: %s vs. %s",
|
|
|
|
res.to_str(),
|
|
|
|
d.to_str());
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(str::ends_with(res.to_str(), d.to_str()));
|
2011-10-06 18:12:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_prefix_rpath_abs() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let res = get_install_prefix_rpath("triple");
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(res.is_absolute);
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_minimize1() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let res = minimize_rpaths([Path("rpath1"),
|
|
|
|
Path("rpath2"),
|
|
|
|
Path("rpath1")]);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, ~[Path("rpath1"), Path("rpath2")]);
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
2011-10-05 00:40:38 -05:00
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_minimize2() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let res = minimize_rpaths(~[Path("1a"), Path("2"), Path("2"),
|
|
|
|
Path("1a"), Path("4a"),Path("1a"),
|
|
|
|
Path("2"), Path("3"), Path("4a"),
|
|
|
|
Path("3")]);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
|
2011-10-05 00:40:38 -05:00
|
|
|
}
|
|
|
|
|
2011-10-04 17:23:32 -05:00
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to1() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/usr/bin/rustc");
|
|
|
|
let p2 = Path("/usr/lib/mylib");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("../lib"));
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to2() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/usr/bin/rustc");
|
|
|
|
let p2 = Path("/usr/bin/../lib/mylib");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("../lib"));
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to3() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/usr/bin/whatever/rustc");
|
|
|
|
let p2 = Path("/usr/lib/whatever/mylib");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("../../lib/whatever"));
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to4() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/usr/bin/whatever/../rustc");
|
|
|
|
let p2 = Path("/usr/lib/whatever/mylib");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("../lib/whatever"));
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to5() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/usr/bin/whatever/../rustc");
|
|
|
|
let p2 = Path("/usr/lib/whatever/../mylib");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("../lib"));
|
2011-10-04 22:07:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to6() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/1");
|
|
|
|
let p2 = Path("/2/3");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("2"));
|
2011-10-04 22:07:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to7() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/1/2");
|
|
|
|
let p2 = Path("/3");
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path(".."));
|
2011-10-04 22:07:18 -05:00
|
|
|
}
|
|
|
|
|
2011-10-05 00:40:38 -05:00
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_relative_to8() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let p1 = Path("/home/brian/Dev/rust/build/").push_rel(
|
|
|
|
&Path("stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so"));
|
|
|
|
let p2 = Path("/home/brian/Dev/rust/build/stage2/bin/..").push_rel(
|
|
|
|
&Path("lib/rustc/i686-unknown-linux-gnu/lib/libstd.so"));
|
|
|
|
let res = get_relative_to(&p1, &p2);
|
|
|
|
debug!("test_relative_tu8: %s vs. %s",
|
|
|
|
res.to_str(),
|
|
|
|
Path(".").to_str());
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, Path("."));
|
2011-10-05 00:40:38 -05:00
|
|
|
}
|
|
|
|
|
2011-10-04 22:07:18 -05:00
|
|
|
#[test]
|
2011-10-06 16:28:52 -05:00
|
|
|
#[cfg(target_os = "linux")]
|
2012-11-29 18:21:49 -06:00
|
|
|
#[cfg(target_os = "andorid")]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_rpath_relative() {
|
2012-07-13 20:43:52 -05:00
|
|
|
let o = session::os_linux;
|
|
|
|
let res = get_rpath_relative_to_output(o,
|
2012-08-24 17:28:43 -05:00
|
|
|
&Path("bin/rustc"), &Path("lib/libstd.so"));
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res.to_str(), ~"$ORIGIN/../lib");
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|
2011-10-05 00:40:38 -05:00
|
|
|
|
2011-12-30 02:18:55 -06:00
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "freebsd")]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_rpath_relative() {
|
2012-07-14 12:27:09 -05:00
|
|
|
let o = session::os_freebsd;
|
|
|
|
let res = get_rpath_relative_to_output(o,
|
2012-08-24 17:28:43 -05:00
|
|
|
&Path("bin/rustc"), &Path("lib/libstd.so"));
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res.to_str(), ~"$ORIGIN/../lib");
|
2011-12-30 02:18:55 -06:00
|
|
|
}
|
|
|
|
|
2011-10-06 16:28:52 -05:00
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "macos")]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_rpath_relative() {
|
2012-07-14 12:27:09 -05:00
|
|
|
// this is why refinements would be nice
|
|
|
|
let o = session::os_macos;
|
2012-08-24 17:28:43 -05:00
|
|
|
let res = get_rpath_relative_to_output(o,
|
|
|
|
&Path("bin/rustc"),
|
|
|
|
&Path("lib/libstd.so"));
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res.to_str(), ~"@executable_path/../lib");
|
2011-10-06 16:28:52 -05:00
|
|
|
}
|
|
|
|
|
2011-10-05 00:40:38 -05:00
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_get_absolute_rpath() {
|
2012-08-24 17:28:43 -05:00
|
|
|
let res = get_absolute_rpath(&Path("lib/libstd.so"));
|
|
|
|
debug!("test_get_absolute_rpath: %s vs. %s",
|
|
|
|
res.to_str(),
|
|
|
|
os::make_absolute(&Path("lib")).to_str());
|
|
|
|
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(res, os::make_absolute(&Path("lib")));
|
2011-10-05 00:40:38 -05:00
|
|
|
}
|
2011-10-04 17:23:32 -05:00
|
|
|
}
|