mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Fixing rustdoc stage1.
See #13983 and #14000. Fix was originally authored by alexcrichton and then rebased a couple times by pnkfelix, most recently atop PR 13954. ---- Regarding the change to librustdoc/lib.rs, to do `map_err` before unwrapping a `TqskResult`: I do not understand how master is passing without this change or something like it, since `Box<Any:Send>` does not implement `Show`. (Is this something that is only a problem for the snapshot stage0 compiler?) Still, the change I have put in here (which was added as part of a rebase after alex's review) seems harmless to me to apply to rustdoc at all stages, since a call to `unwrap` is just going to `fail!` on the err case anyway.
This commit is contained in:
parent
63287eef27
commit
eb6856c307
@ -11,54 +11,31 @@
|
|||||||
use std::os;
|
use std::os;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
|
use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
|
||||||
|
use std::unstable::dynamic_lib::DynamicLibrary;
|
||||||
|
|
||||||
#[cfg(target_os = "win32")]
|
|
||||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
|
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
|
||||||
let env = os::env();
|
let prog = if cfg!(windows) {prog.slice_to(prog.len() - 4)} else {prog};
|
||||||
|
|
||||||
// Make sure we include the aux directory in the path
|
|
||||||
assert!(prog.ends_with(".exe"));
|
|
||||||
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";
|
|
||||||
|
|
||||||
let mut new_env: Vec<_> = env.move_iter().map(|(k, v)| {
|
|
||||||
let new_v = if "PATH" == k {
|
|
||||||
format_strbuf!("{};{};{}", v, lib_path, aux_path)
|
|
||||||
} else {
|
|
||||||
v.to_strbuf()
|
|
||||||
};
|
|
||||||
(k.to_strbuf(), new_v)
|
|
||||||
}).collect();
|
|
||||||
if prog.ends_with("rustc.exe") {
|
|
||||||
new_env.push(("RUST_THREADS".to_strbuf(), "1".to_strbuf()));
|
|
||||||
}
|
|
||||||
return new_env;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
#[cfg(target_os = "freebsd")]
|
|
||||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf,StrBuf)> {
|
|
||||||
// Make sure we include the aux directory in the path
|
|
||||||
let aux_path = prog + ".libaux";
|
let aux_path = prog + ".libaux";
|
||||||
|
|
||||||
|
// Need to be sure to put both the lib_path and the aux path in the dylib
|
||||||
|
// search path for the child.
|
||||||
|
let mut path = DynamicLibrary::search_path();
|
||||||
|
path.insert(0, Path::new(aux_path));
|
||||||
|
path.insert(0, Path::new(lib_path));
|
||||||
|
|
||||||
|
// Remove the previous dylib search path var
|
||||||
|
let var = DynamicLibrary::envvar();
|
||||||
let mut env: Vec<(StrBuf,StrBuf)> =
|
let mut env: Vec<(StrBuf,StrBuf)> =
|
||||||
os::env().move_iter()
|
os::env().move_iter().map(|(a,b)|(a.to_strbuf(), b.to_strbuf())).collect();
|
||||||
.map(|(ref k, ref v)| (k.to_strbuf(), v.to_strbuf()))
|
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
|
||||||
.collect();
|
Some(i) => { env.remove(i); }
|
||||||
let var = if cfg!(target_os = "macos") {
|
None => {}
|
||||||
"DYLD_LIBRARY_PATH"
|
}
|
||||||
} else {
|
|
||||||
"LD_LIBRARY_PATH"
|
// Add the new dylib search path var
|
||||||
};
|
let newpath = DynamicLibrary::create_path(path.as_slice());
|
||||||
let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
|
env.push((var.to_strbuf(),
|
||||||
Some(i) => env.remove(i).unwrap().val1(),
|
str::from_utf8(newpath.as_slice()).unwrap().to_strbuf()));
|
||||||
None => "".to_strbuf(),
|
|
||||||
};
|
|
||||||
env.push((var.to_strbuf(), if prev.is_empty() {
|
|
||||||
format_strbuf!("{}:{}", lib_path, aux_path)
|
|
||||||
} else {
|
|
||||||
format_strbuf!("{}:{}:{}", lib_path, aux_path, prev)
|
|
||||||
}));
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ impl<'a> FileSearch<'a> {
|
|||||||
|
|
||||||
pub fn add_dylib_search_paths(&self) {
|
pub fn add_dylib_search_paths(&self) {
|
||||||
self.for_each_lib_search_path(|lib_search_path| {
|
self.for_each_lib_search_path(|lib_search_path| {
|
||||||
DynamicLibrary::add_search_path(lib_search_path);
|
DynamicLibrary::prepend_search_path(lib_search_path);
|
||||||
FileDoesntMatch
|
FileDoesntMatch
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
|
|||||||
core::run_core(libs.move_iter().map(|x| x.clone()).collect(),
|
core::run_core(libs.move_iter().map(|x| x.clone()).collect(),
|
||||||
cfgs.move_iter().map(|x| x.to_strbuf()).collect(),
|
cfgs.move_iter().map(|x| x.to_strbuf()).collect(),
|
||||||
&cr)
|
&cr)
|
||||||
}).unwrap();
|
}).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap();
|
||||||
info!("finished with rustc");
|
info!("finished with rustc");
|
||||||
analysiskey.replace(Some(analysis));
|
analysiskey.replace(Some(analysis));
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ use std::io::{Command, TempDir};
|
|||||||
use std::os;
|
use std::os;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::strbuf::StrBuf;
|
use std::strbuf::StrBuf;
|
||||||
|
use std::unstable::dynamic_lib::DynamicLibrary;
|
||||||
|
|
||||||
use collections::{HashSet, HashMap};
|
use collections::{HashSet, HashMap};
|
||||||
use testing;
|
use testing;
|
||||||
@ -150,12 +151,37 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
|||||||
let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");
|
let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");
|
||||||
let out = Some(outdir.path().clone());
|
let out = Some(outdir.path().clone());
|
||||||
let cfg = config::build_configuration(&sess);
|
let cfg = config::build_configuration(&sess);
|
||||||
|
let libdir = sess.target_filesearch().get_lib_path();
|
||||||
driver::compile_input(sess, cfg, &input, &out, &None);
|
driver::compile_input(sess, cfg, &input, &out, &None);
|
||||||
|
|
||||||
if no_run { return }
|
if no_run { return }
|
||||||
|
|
||||||
// Run the code!
|
// Run the code!
|
||||||
match Command::new(outdir.path().join("rust_out")).output() {
|
//
|
||||||
|
// We're careful to prepend the *target* dylib search path to the child's
|
||||||
|
// environment to ensure that the target loads the right libraries at
|
||||||
|
// runtime. It would be a sad day if the *host* libraries were loaded as a
|
||||||
|
// mistake.
|
||||||
|
let exe = outdir.path().join("rust_out");
|
||||||
|
let env = {
|
||||||
|
let mut path = DynamicLibrary::search_path();
|
||||||
|
path.insert(0, libdir.clone());
|
||||||
|
|
||||||
|
// Remove the previous dylib search path var
|
||||||
|
let var = DynamicLibrary::envvar();
|
||||||
|
let mut env: Vec<(~str,~str)> = os::env().move_iter().collect();
|
||||||
|
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
|
||||||
|
Some(i) => { env.remove(i); }
|
||||||
|
None => {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add the new dylib search path var
|
||||||
|
let newpath = DynamicLibrary::create_path(path.as_slice());
|
||||||
|
env.push((var.to_owned(),
|
||||||
|
str::from_utf8(newpath.as_slice()).unwrap().to_owned()));
|
||||||
|
env
|
||||||
|
};
|
||||||
|
match Command::new(exe).env(env.as_slice()).output() {
|
||||||
Err(e) => fail!("couldn't run the test: {}{}", e,
|
Err(e) => fail!("couldn't run the test: {}{}", e,
|
||||||
if e.kind == io::PermissionDenied {
|
if e.kind == io::PermissionDenied {
|
||||||
" - maybe your tempdir is mounted with noexec?"
|
" - maybe your tempdir is mounted with noexec?"
|
||||||
|
@ -16,16 +16,16 @@ A simple wrapper over the platform's dynamic library facilities
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use clone::Clone;
|
||||||
use c_str::ToCStr;
|
use c_str::ToCStr;
|
||||||
|
use iter::Iterator;
|
||||||
use mem;
|
use mem;
|
||||||
use ops::*;
|
use ops::*;
|
||||||
use option::*;
|
use option::*;
|
||||||
use os;
|
use os;
|
||||||
use path::GenericPath;
|
use path::{Path,GenericPath};
|
||||||
use path;
|
|
||||||
use result::*;
|
use result::*;
|
||||||
use slice::Vector;
|
use slice::{Vector,ImmutableVector};
|
||||||
use str;
|
use str;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
||||||
@ -76,22 +76,55 @@ impl DynamicLibrary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends a path to the system search path for dynamic libraries
|
/// Prepends a path to this process's search path for dynamic libraries
|
||||||
pub fn add_search_path(path: &path::Path) {
|
pub fn prepend_search_path(path: &Path) {
|
||||||
let (envvar, sep) = if cfg!(windows) {
|
let mut search_path = DynamicLibrary::search_path();
|
||||||
("PATH", ';' as u8)
|
search_path.insert(0, path.clone());
|
||||||
|
let newval = DynamicLibrary::create_path(search_path.as_slice());
|
||||||
|
os::setenv(DynamicLibrary::envvar(),
|
||||||
|
str::from_utf8(newval.as_slice()).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// From a slice of paths, create a new vector which is suitable to be an
|
||||||
|
/// environment variable for this platforms dylib search path.
|
||||||
|
pub fn create_path(path: &[Path]) -> Vec<u8> {
|
||||||
|
let mut newvar = Vec::new();
|
||||||
|
for (i, path) in path.iter().enumerate() {
|
||||||
|
if i > 0 { newvar.push(DynamicLibrary::separator()); }
|
||||||
|
newvar.push_all(path.as_vec());
|
||||||
|
}
|
||||||
|
return newvar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the environment variable for this process's dynamic library
|
||||||
|
/// search path
|
||||||
|
pub fn envvar() -> &'static str {
|
||||||
|
if cfg!(windows) {
|
||||||
|
"PATH"
|
||||||
} else if cfg!(target_os = "macos") {
|
} else if cfg!(target_os = "macos") {
|
||||||
("DYLD_LIBRARY_PATH", ':' as u8)
|
"DYLD_LIBRARY_PATH"
|
||||||
} else {
|
} else {
|
||||||
("LD_LIBRARY_PATH", ':' as u8)
|
"LD_LIBRARY_PATH"
|
||||||
};
|
}
|
||||||
let mut newenv = Vec::from_slice(path.as_vec());
|
}
|
||||||
newenv.push(sep);
|
|
||||||
match os::getenv_as_bytes(envvar) {
|
fn separator() -> u8 {
|
||||||
Some(bytes) => newenv.push_all(bytes),
|
if cfg!(windows) {';' as u8} else {':' as u8}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the current search path for dynamic libraries being used by this
|
||||||
|
/// process
|
||||||
|
pub fn search_path() -> Vec<Path> {
|
||||||
|
let mut ret = Vec::new();
|
||||||
|
match os::getenv_as_bytes(DynamicLibrary::envvar()) {
|
||||||
|
Some(env) => {
|
||||||
|
for portion in env.split(|a| *a == DynamicLibrary::separator()) {
|
||||||
|
ret.push(Path::new(portion));
|
||||||
|
}
|
||||||
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
os::setenv(envvar, str::from_utf8(newenv.as_slice()).unwrap());
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the value at the symbol of the dynamic library
|
/// Access the value at the symbol of the dynamic library
|
||||||
@ -168,11 +201,12 @@ mod test {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
pub mod dl {
|
pub mod dl {
|
||||||
|
use prelude::*;
|
||||||
|
|
||||||
use c_str::ToCStr;
|
use c_str::ToCStr;
|
||||||
use libc;
|
use libc;
|
||||||
use ptr;
|
use ptr;
|
||||||
use str;
|
use str;
|
||||||
use result::*;
|
|
||||||
|
|
||||||
pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 {
|
pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 {
|
||||||
filename.with_c_str(|raw_name| {
|
filename.with_c_str(|raw_name| {
|
||||||
|
Loading…
Reference in New Issue
Block a user