Skip to content

Commit 9133c55

Browse files
committed
---
yaml --- r: 113632 b: refs/heads/snap-stage3 c: eb6856c h: refs/heads/master v: v3
1 parent 6d5dc7c commit 9133c55

File tree

8 files changed

+106
-111
lines changed

8 files changed

+106
-111
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ea87f126bdf8de4acc4f74c14ac0ae10d95a2472
4+
refs/heads/snap-stage3: eb6856c307ae8cff97c57f11be2cf04561e7f2eb
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/compiletest/procsrv.rs

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,31 @@
1111
use std::os;
1212
use std::str;
1313
use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
14+
use std::unstable::dynamic_lib::DynamicLibrary;
1415

15-
#[cfg(target_os = "win32")]
1616
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
17-
let env = os::env();
17+
let prog = if cfg!(windows) {prog.slice_to(prog.len() - 4)} else {prog};
18+
let aux_path = prog + ".libaux";
1819

19-
// Make sure we include the aux directory in the path
20-
assert!(prog.ends_with(".exe"));
21-
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";
20+
// Need to be sure to put both the lib_path and the aux path in the dylib
21+
// search path for the child.
22+
let mut path = DynamicLibrary::search_path();
23+
path.insert(0, Path::new(aux_path));
24+
path.insert(0, Path::new(lib_path));
2225

23-
let mut new_env: Vec<_> = env.move_iter().map(|(k, v)| {
24-
let new_v = if "PATH" == k {
25-
format_strbuf!("{};{};{}", v, lib_path, aux_path)
26-
} else {
27-
v.to_strbuf()
28-
};
29-
(k.to_strbuf(), new_v)
30-
}).collect();
31-
if prog.ends_with("rustc.exe") {
32-
new_env.push(("RUST_THREADS".to_strbuf(), "1".to_strbuf()));
26+
// Remove the previous dylib search path var
27+
let var = DynamicLibrary::envvar();
28+
let mut env: Vec<(StrBuf,StrBuf)> =
29+
os::env().move_iter().map(|(a,b)|(a.to_strbuf(), b.to_strbuf())).collect();
30+
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
31+
Some(i) => { env.remove(i); }
32+
None => {}
3333
}
34-
return new_env;
35-
}
3634

37-
#[cfg(target_os = "linux")]
38-
#[cfg(target_os = "macos")]
39-
#[cfg(target_os = "freebsd")]
40-
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf,StrBuf)> {
41-
// Make sure we include the aux directory in the path
42-
let aux_path = prog + ".libaux";
43-
44-
let mut env: Vec<(StrBuf,StrBuf)> =
45-
os::env().move_iter()
46-
.map(|(ref k, ref v)| (k.to_strbuf(), v.to_strbuf()))
47-
.collect();
48-
let var = if cfg!(target_os = "macos") {
49-
"DYLD_LIBRARY_PATH"
50-
} else {
51-
"LD_LIBRARY_PATH"
52-
};
53-
let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
54-
Some(i) => env.remove(i).unwrap().val1(),
55-
None => "".to_strbuf(),
56-
};
57-
env.push((var.to_strbuf(), if prev.is_empty() {
58-
format_strbuf!("{}:{}", lib_path, aux_path)
59-
} else {
60-
format_strbuf!("{}:{}:{}", lib_path, aux_path, prev)
61-
}));
35+
// Add the new dylib search path var
36+
let newpath = DynamicLibrary::create_path(path.as_slice());
37+
env.push((var.to_strbuf(),
38+
str::from_utf8(newpath.as_slice()).unwrap().to_strbuf()));
6239
return env;
6340
}
6441

branches/snap-stage3/src/librustc/metadata/filesearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a> FileSearch<'a> {
136136

137137
pub fn add_dylib_search_paths(&self) {
138138
self.for_each_lib_search_path(|lib_search_path| {
139-
DynamicLibrary::add_search_path(lib_search_path);
139+
DynamicLibrary::prepend_search_path(lib_search_path);
140140
FileDoesntMatch
141141
})
142142
}

branches/snap-stage3/src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
284284
core::run_core(libs.move_iter().map(|x| x.clone()).collect(),
285285
cfgs.move_iter().map(|x| x.to_strbuf()).collect(),
286286
&cr)
287-
}).unwrap();
287+
}).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap();
288288
info!("finished with rustc");
289289
analysiskey.replace(Some(analysis));
290290

branches/snap-stage3/src/librustdoc/test.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::io::{Command, TempDir};
1515
use std::os;
1616
use std::str;
1717
use std::strbuf::StrBuf;
18+
use std::unstable::dynamic_lib::DynamicLibrary;
1819

1920
use collections::{HashSet, HashMap};
2021
use testing;
@@ -150,12 +151,37 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
150151
let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");
151152
let out = Some(outdir.path().clone());
152153
let cfg = config::build_configuration(&sess);
154+
let libdir = sess.target_filesearch().get_lib_path();
153155
driver::compile_input(sess, cfg, &input, &out, &None);
154156

155157
if no_run { return }
156158

157159
// Run the code!
158-
match Command::new(outdir.path().join("rust_out")).output() {
160+
//
161+
// We're careful to prepend the *target* dylib search path to the child's
162+
// environment to ensure that the target loads the right libraries at
163+
// runtime. It would be a sad day if the *host* libraries were loaded as a
164+
// mistake.
165+
let exe = outdir.path().join("rust_out");
166+
let env = {
167+
let mut path = DynamicLibrary::search_path();
168+
path.insert(0, libdir.clone());
169+
170+
// Remove the previous dylib search path var
171+
let var = DynamicLibrary::envvar();
172+
let mut env: Vec<(~str,~str)> = os::env().move_iter().collect();
173+
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
174+
Some(i) => { env.remove(i); }
175+
None => {}
176+
};
177+
178+
// Add the new dylib search path var
179+
let newpath = DynamicLibrary::create_path(path.as_slice());
180+
env.push((var.to_owned(),
181+
str::from_utf8(newpath.as_slice()).unwrap().to_owned()));
182+
env
183+
};
184+
match Command::new(exe).env(env.as_slice()).output() {
159185
Err(e) => fail!("couldn't run the test: {}{}", e,
160186
if e.kind == io::PermissionDenied {
161187
" - maybe your tempdir is mounted with noexec?"

branches/snap-stage3/src/libstd/unstable/dynamic_lib.rs

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ A simple wrapper over the platform's dynamic library facilities
1616
1717
*/
1818

19-
19+
use clone::Clone;
2020
use c_str::ToCStr;
21+
use iter::Iterator;
2122
use mem;
2223
use ops::*;
2324
use option::*;
2425
use os;
25-
use path::GenericPath;
26-
use path;
26+
use path::{Path,GenericPath};
2727
use result::*;
28-
use slice::Vector;
28+
use slice::{Vector,ImmutableVector};
2929
use str;
3030
use vec::Vec;
3131

@@ -76,22 +76,55 @@ impl DynamicLibrary {
7676
}
7777
}
7878

79-
/// Appends a path to the system search path for dynamic libraries
80-
pub fn add_search_path(path: &path::Path) {
81-
let (envvar, sep) = if cfg!(windows) {
82-
("PATH", ';' as u8)
79+
/// Prepends a path to this process's search path for dynamic libraries
80+
pub fn prepend_search_path(path: &Path) {
81+
let mut search_path = DynamicLibrary::search_path();
82+
search_path.insert(0, path.clone());
83+
let newval = DynamicLibrary::create_path(search_path.as_slice());
84+
os::setenv(DynamicLibrary::envvar(),
85+
str::from_utf8(newval.as_slice()).unwrap());
86+
}
87+
88+
/// From a slice of paths, create a new vector which is suitable to be an
89+
/// environment variable for this platforms dylib search path.
90+
pub fn create_path(path: &[Path]) -> Vec<u8> {
91+
let mut newvar = Vec::new();
92+
for (i, path) in path.iter().enumerate() {
93+
if i > 0 { newvar.push(DynamicLibrary::separator()); }
94+
newvar.push_all(path.as_vec());
95+
}
96+
return newvar;
97+
}
98+
99+
/// Returns the environment variable for this process's dynamic library
100+
/// search path
101+
pub fn envvar() -> &'static str {
102+
if cfg!(windows) {
103+
"PATH"
83104
} else if cfg!(target_os = "macos") {
84-
("DYLD_LIBRARY_PATH", ':' as u8)
105+
"DYLD_LIBRARY_PATH"
85106
} else {
86-
("LD_LIBRARY_PATH", ':' as u8)
87-
};
88-
let mut newenv = Vec::from_slice(path.as_vec());
89-
newenv.push(sep);
90-
match os::getenv_as_bytes(envvar) {
91-
Some(bytes) => newenv.push_all(bytes),
107+
"LD_LIBRARY_PATH"
108+
}
109+
}
110+
111+
fn separator() -> u8 {
112+
if cfg!(windows) {';' as u8} else {':' as u8}
113+
}
114+
115+
/// Returns the current search path for dynamic libraries being used by this
116+
/// process
117+
pub fn search_path() -> Vec<Path> {
118+
let mut ret = Vec::new();
119+
match os::getenv_as_bytes(DynamicLibrary::envvar()) {
120+
Some(env) => {
121+
for portion in env.split(|a| *a == DynamicLibrary::separator()) {
122+
ret.push(Path::new(portion));
123+
}
124+
}
92125
None => {}
93126
}
94-
os::setenv(envvar, str::from_utf8(newenv.as_slice()).unwrap());
127+
return ret;
95128
}
96129

97130
/// Access the value at the symbol of the dynamic library
@@ -168,11 +201,12 @@ mod test {
168201
#[cfg(target_os = "macos")]
169202
#[cfg(target_os = "freebsd")]
170203
pub mod dl {
204+
use prelude::*;
205+
171206
use c_str::ToCStr;
172207
use libc;
173208
use ptr;
174209
use str;
175-
use result::*;
176210

177211
pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 {
178212
filename.with_c_str(|raw_name| {

branches/snap-stage3/src/libsyntax/ext/bytes.rs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
2525
Some(e) => e,
2626
};
2727
let mut bytes = Vec::new();
28-
let mut err = false;
2928

3029
for expr in exprs.iter() {
3130
match expr.node {
@@ -41,8 +40,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4140
// u8 literal, push to vector expression
4241
ast::LitUint(v, ast::TyU8) => {
4342
if v > 0xFF {
44-
cx.span_err(expr.span, "too large u8 literal in bytes!");
45-
err = true;
43+
cx.span_err(expr.span, "too large u8 literal in bytes!")
4644
} else {
4745
bytes.push(cx.expr_u8(expr.span, v as u8));
4846
}
@@ -51,11 +49,9 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
5149
// integer literal, push to vector expression
5250
ast::LitIntUnsuffixed(v) => {
5351
if v > 0xFF {
54-
cx.span_err(expr.span, "too large integer literal in bytes!");
55-
err = true;
52+
cx.span_err(expr.span, "too large integer literal in bytes!")
5653
} else if v < 0 {
57-
cx.span_err(expr.span, "negative integer literal in bytes!");
58-
err = true;
54+
cx.span_err(expr.span, "negative integer literal in bytes!")
5955
} else {
6056
bytes.push(cx.expr_u8(expr.span, v as u8));
6157
}
@@ -66,34 +62,17 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
6662
if v.is_ascii() {
6763
bytes.push(cx.expr_u8(expr.span, v as u8));
6864
} else {
69-
cx.span_err(expr.span, "non-ascii char literal in bytes!");
70-
err = true;
65+
cx.span_err(expr.span, "non-ascii char literal in bytes!")
7166
}
7267
}
7368

74-
_ => {
75-
cx.span_err(expr.span, "unsupported literal in bytes!");
76-
err = true;
77-
}
69+
_ => cx.span_err(expr.span, "unsupported literal in bytes!")
7870
},
7971

80-
_ => {
81-
cx.span_err(expr.span, "non-literal in bytes!");
82-
err = true;
83-
}
72+
_ => cx.span_err(expr.span, "non-literal in bytes!")
8473
}
8574
}
8675

87-
// For some reason using quote_expr!() here aborts if we threw an error.
88-
// I'm assuming that the end of the recursive parse tricks the compiler
89-
// into thinking this is a good time to stop. But we'd rather keep going.
90-
if err {
91-
// Since the compiler will stop after the macro expansion phase anyway, we
92-
// don't need type info, so we can just return a DummyResult
93-
return DummyResult::expr(sp);
94-
}
95-
9676
let e = cx.expr_vec_slice(sp, bytes);
97-
let e = quote_expr!(cx, { static BYTES: &'static [u8] = $e; BYTES});
9877
MacExpr::new(e)
9978
}

branches/snap-stage3/src/test/run-pass/bytes-macro-static.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)