Skip to content

Commit 578023f

Browse files
committed
---
yaml --- r: 131835 b: refs/heads/dist-snap c: c5a2ac1 h: refs/heads/master i: 131833: 3ff78bb 131831: 2cd7807 v: v3
1 parent c29c7b6 commit 578023f

File tree

3 files changed

+78
-86
lines changed

3 files changed

+78
-86
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: cf360f328aad26bd19490270aa9716645aa4d4cf
9+
refs/heads/dist-snap: c5a2ac10972092c9610f4f0727e53c1a6782961e
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/back/link.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use super::archive::{Archive, METADATA_FILENAME};
1212
use super::rpath;
13+
use super::rpath::RPathConfig;
1314
use super::svh::Svh;
1415
use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput};
1516
use driver::config::NoDebugInfo;
@@ -1385,7 +1386,24 @@ fn link_args(cmd: &mut Command,
13851386
// where extern libraries might live, based on the
13861387
// addl_lib_search_paths
13871388
if sess.opts.cg.rpath {
1388-
cmd.args(rpath::get_rpath_flags(sess, out_filename).as_slice());
1389+
let sysroot = sess.sysroot();
1390+
let target_triple = sess.opts.target_triple.as_slice();
1391+
let get_install_prefix_lib_path = || {
1392+
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
1393+
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
1394+
let mut path = Path::new(install_prefix);
1395+
path.push(&tlib);
1396+
1397+
path
1398+
};
1399+
let rpath_config = RPathConfig {
1400+
os: sess.targ_cfg.os,
1401+
used_crates: sess.cstore.get_used_crates(cstore::RequireDynamic),
1402+
out_filename: out_filename.clone(),
1403+
get_install_prefix_lib_path: get_install_prefix_lib_path,
1404+
realpath: ::util::fs::realpath
1405+
};
1406+
cmd.args(rpath::get_rpath_flags(rpath_config).as_slice());
13891407
}
13901408

13911409
// compiler-rt contains implementations of low-level LLVM helpers. This is

branches/dist-snap/src/librustc/back/rpath.rs

Lines changed: 58 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,81 +9,70 @@
99
// except according to those terms.
1010

1111

12-
use driver::session::Session;
13-
use metadata::cstore;
14-
use metadata::filesearch;
15-
use util::fs;
16-
1712
use std::collections::HashSet;
1813
use std::os;
14+
use std::io::IoError;
1915
use syntax::abi;
20-
21-
fn not_win32(os: abi::Os) -> bool {
22-
os != abi::OsWin32
16+
use syntax::ast;
17+
18+
pub struct RPathConfig<'a> {
19+
pub os: abi::Os,
20+
pub used_crates: Vec<(ast::CrateNum, Option<Path>)>,
21+
pub out_filename: Path,
22+
pub get_install_prefix_lib_path: ||:'a -> Path,
23+
pub realpath: |&Path|:'a -> Result<Path, IoError>
2324
}
2425

25-
pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<String> {
26-
let os = sess.targ_cfg.os;
26+
pub fn get_rpath_flags(config: RPathConfig) -> Vec<String> {
2727

2828
// No rpath on windows
29-
if os == abi::OsWin32 {
29+
if config.os == abi::OsWin32 {
3030
return Vec::new();
3131
}
3232

3333
let mut flags = Vec::new();
3434

35-
if sess.targ_cfg.os == abi::OsFreebsd {
35+
if config.os == abi::OsFreebsd {
3636
flags.push_all(["-Wl,-rpath,/usr/local/lib/gcc46".to_string(),
3737
"-Wl,-rpath,/usr/local/lib/gcc44".to_string(),
3838
"-Wl,-z,origin".to_string()]);
3939
}
4040

4141
debug!("preparing the RPATH!");
4242

43-
let sysroot = sess.sysroot();
44-
let output = out_filename;
45-
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
43+
let libs = config.used_crates.clone();
4644
let libs = libs.move_iter().filter_map(|(_, l)| {
4745
l.map(|p| p.clone())
4846
}).collect::<Vec<_>>();
4947

50-
let rpaths = get_rpaths(os,
51-
sysroot,
52-
output,
53-
libs.as_slice(),
54-
sess.opts.target_triple.as_slice());
48+
let rpaths = get_rpaths(config, libs.as_slice());
5549
flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice());
5650
flags
5751
}
5852

59-
pub fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
53+
fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
6054
let mut ret = Vec::new();
6155
for rpath in rpaths.iter() {
6256
ret.push(format!("-Wl,-rpath,{}", (*rpath).as_slice()));
6357
}
6458
return ret;
6559
}
6660

67-
fn get_rpaths(os: abi::Os,
68-
sysroot: &Path,
69-
output: &Path,
70-
libs: &[Path],
71-
target_triple: &str) -> Vec<String> {
72-
debug!("sysroot: {}", sysroot.display());
73-
debug!("output: {}", output.display());
61+
fn get_rpaths(mut config: RPathConfig,
62+
libs: &[Path]) -> Vec<String> {
63+
debug!("output: {}", config.out_filename.display());
7464
debug!("libs:");
7565
for libpath in libs.iter() {
7666
debug!(" {}", libpath.display());
7767
}
78-
debug!("target_triple: {}", target_triple);
7968

8069
// Use relative paths to the libraries. Binaries can be moved
8170
// as long as they maintain the relative relationship to the
8271
// crates they depend on.
83-
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);
72+
let rel_rpaths = get_rpaths_relative_to_output(&mut config, libs);
8473

8574
// And a final backup rpath to the global library location.
86-
let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple));
75+
let fallback_rpaths = vec!(get_install_prefix_rpath(config));
8776

8877
fn log_rpaths(desc: &str, rpaths: &[String]) {
8978
debug!("{} rpaths:", desc);
@@ -103,31 +92,28 @@ fn get_rpaths(os: abi::Os,
10392
return rpaths;
10493
}
10594

106-
fn get_rpaths_relative_to_output(os: abi::Os,
107-
output: &Path,
95+
fn get_rpaths_relative_to_output(config: &mut RPathConfig,
10896
libs: &[Path]) -> Vec<String> {
109-
libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect()
97+
libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect()
11098
}
11199

112-
pub fn get_rpath_relative_to_output(os: abi::Os,
113-
output: &Path,
114-
lib: &Path)
115-
-> String {
100+
fn get_rpath_relative_to_output(config: &mut RPathConfig,
101+
lib: &Path) -> String {
116102
use std::os;
117103

118-
assert!(not_win32(os));
104+
assert!(config.os != abi::OsWin32);
119105

120106
// Mac doesn't appear to support $ORIGIN
121-
let prefix = match os {
107+
let prefix = match config.os {
122108
abi::OsAndroid | abi::OsLinux | abi::OsFreebsd
123109
=> "$ORIGIN",
124110
abi::OsMacos => "@loader_path",
125111
abi::OsWin32 | abi::OsiOS => unreachable!()
126112
};
127113

128-
let mut lib = fs::realpath(&os::make_absolute(lib)).unwrap();
114+
let mut lib = (config.realpath)(&os::make_absolute(lib)).unwrap();
129115
lib.pop();
130-
let mut output = fs::realpath(&os::make_absolute(output)).unwrap();
116+
let mut output = (config.realpath)(&os::make_absolute(&config.out_filename)).unwrap();
131117
output.pop();
132118
let relative = lib.path_relative_from(&output);
133119
let relative = relative.expect("could not create rpath relative to output");
@@ -137,18 +123,14 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
137123
relative.as_str().expect("non-utf8 component in path"))
138124
}
139125

140-
pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> String {
141-
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
142-
143-
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
144-
let mut path = Path::new(install_prefix);
145-
path.push(&tlib);
126+
fn get_install_prefix_rpath(config: RPathConfig) -> String {
127+
let path = (config.get_install_prefix_lib_path)();
146128
let path = os::make_absolute(&path);
147129
// FIXME (#9639): This needs to handle non-utf8 paths
148130
path.as_str().expect("non-utf8 component in rpath").to_string()
149131
}
150132

151-
pub fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
133+
fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
152134
let mut set = HashSet::new();
153135
let mut minimized = Vec::new();
154136
for rpath in rpaths.iter() {
@@ -161,10 +143,9 @@ pub fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
161143

162144
#[cfg(unix, test)]
163145
mod test {
164-
use back::rpath::get_install_prefix_rpath;
165-
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
146+
use super::{RPathConfig};
147+
use super::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
166148
use syntax::abi;
167-
use metadata::filesearch;
168149

169150
#[test]
170151
fn test_rpaths_to_flags() {
@@ -177,27 +158,6 @@ mod test {
177158
"-Wl,-rpath,path2".to_string()));
178159
}
179160

180-
#[test]
181-
fn test_prefix_rpath() {
182-
let sysroot = filesearch::get_or_default_sysroot();
183-
let res = get_install_prefix_rpath(&sysroot, "triple");
184-
let mut d = Path::new((option_env!("CFG_PREFIX")).expect("CFG_PREFIX"));
185-
d.push("lib");
186-
d.push(filesearch::rustlibdir());
187-
d.push("triple/lib");
188-
debug!("test_prefix_path: {} vs. {}",
189-
res,
190-
d.display());
191-
assert!(res.as_bytes().ends_with(d.as_vec()));
192-
}
193-
194-
#[test]
195-
fn test_prefix_rpath_abs() {
196-
let sysroot = filesearch::get_or_default_sysroot();
197-
let res = get_install_prefix_rpath(&sysroot, "triple");
198-
assert!(Path::new(res).is_absolute());
199-
}
200-
201161
#[test]
202162
fn test_minimize1() {
203163
let res = minimize_rpaths([
@@ -237,28 +197,42 @@ mod test {
237197
#[cfg(target_os = "linux")]
238198
#[cfg(target_os = "android")]
239199
fn test_rpath_relative() {
240-
let o = abi::OsLinux;
241-
let res = get_rpath_relative_to_output(o,
242-
&Path::new("bin/rustc"), &Path::new("lib/libstd.so"));
243-
assert_eq!(res.as_slice(), "$ORIGIN/../lib");
200+
let config = &mut RPathConfig {
201+
os: abi::OsLinux,
202+
used_crates: Vec::new(),
203+
out_filename: Path::new("bin/rustc"),
204+
get_install_prefix_lib_path: || fail!(),
205+
realpath: |p| Ok(p.clone())
206+
};
207+
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
208+
assert_eq!(res.as_slice(), "$ORIGIN/../lib");
244209
}
245210

246211
#[test]
247212
#[cfg(target_os = "freebsd")]
248213
fn test_rpath_relative() {
249-
let o = abi::OsFreebsd;
250-
let res = get_rpath_relative_to_output(o,
251-
&Path::new("bin/rustc"), &Path::new("lib/libstd.so"));
214+
let config = &mut RPathConfig {
215+
os: abi::OsFreebsd,
216+
used_crates: Vec::new(),
217+
out_filename: Path::new("bin/rustc"),
218+
get_install_prefix_lib_path: || fail!(),
219+
realpath: |p| Ok(p.clone())
220+
};
221+
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
252222
assert_eq!(res.as_slice(), "$ORIGIN/../lib");
253223
}
254224

255225
#[test]
256226
#[cfg(target_os = "macos")]
257227
fn test_rpath_relative() {
258-
let o = abi::OsMacos;
259-
let res = get_rpath_relative_to_output(o,
260-
&Path::new("bin/rustc"),
261-
&Path::new("lib/libstd.so"));
228+
let config = &mut RPathConfig {
229+
os: abi::OsMacos,
230+
used_crates: Vec::new(),
231+
out_filename: Path::new("bin/rustc"),
232+
get_install_prefix_lib_path: || fail!(),
233+
realpath: |p| p.clone()
234+
};
235+
let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so"));
262236
assert_eq!(res.as_slice(), "@loader_path/../lib");
263237
}
264238
}

0 commit comments

Comments
 (0)