Skip to content

Commit

Permalink
Fixing rustdoc stage1.
Browse files Browse the repository at this point in the history
See rust-lang#13983 and rust-lang#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.
  • Loading branch information
pnkfelix committed May 18, 2014
1 parent 63287ee commit eb6856c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 62 deletions.
61 changes: 19 additions & 42 deletions src/compiletest/procsrv.rs
Expand Up @@ -11,54 +11,31 @@
use std::os;
use std::str;
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)> {
let env = os::env();
let prog = if cfg!(windows) {prog.slice_to(prog.len() - 4)} else {prog};
let aux_path = prog + ".libaux";

// 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";
// 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));

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()));
// Remove the previous dylib search path var
let var = DynamicLibrary::envvar();
let mut env: Vec<(StrBuf,StrBuf)> =
os::env().move_iter().map(|(a,b)|(a.to_strbuf(), b.to_strbuf())).collect();
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
Some(i) => { env.remove(i); }
None => {}
}
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 mut env: Vec<(StrBuf,StrBuf)> =
os::env().move_iter()
.map(|(ref k, ref v)| (k.to_strbuf(), v.to_strbuf()))
.collect();
let var = if cfg!(target_os = "macos") {
"DYLD_LIBRARY_PATH"
} else {
"LD_LIBRARY_PATH"
};
let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
Some(i) => env.remove(i).unwrap().val1(),
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)
}));
// Add the new dylib search path var
let newpath = DynamicLibrary::create_path(path.as_slice());
env.push((var.to_strbuf(),
str::from_utf8(newpath.as_slice()).unwrap().to_strbuf()));
return env;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/filesearch.rs
Expand Up @@ -136,7 +136,7 @@ impl<'a> FileSearch<'a> {

pub fn add_dylib_search_paths(&self) {
self.for_each_lib_search_path(|lib_search_path| {
DynamicLibrary::add_search_path(lib_search_path);
DynamicLibrary::prepend_search_path(lib_search_path);
FileDoesntMatch
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Expand Up @@ -284,7 +284,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
core::run_core(libs.move_iter().map(|x| x.clone()).collect(),
cfgs.move_iter().map(|x| x.to_strbuf()).collect(),
&cr)
}).unwrap();
}).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap();
info!("finished with rustc");
analysiskey.replace(Some(analysis));

Expand Down
28 changes: 27 additions & 1 deletion src/librustdoc/test.rs
Expand Up @@ -15,6 +15,7 @@ use std::io::{Command, TempDir};
use std::os;
use std::str;
use std::strbuf::StrBuf;
use std::unstable::dynamic_lib::DynamicLibrary;

use collections::{HashSet, HashMap};
use testing;
Expand Down Expand Up @@ -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 out = Some(outdir.path().clone());
let cfg = config::build_configuration(&sess);
let libdir = sess.target_filesearch().get_lib_path();
driver::compile_input(sess, cfg, &input, &out, &None);

if no_run { return }

// 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,
if e.kind == io::PermissionDenied {
" - maybe your tempdir is mounted with noexec?"
Expand Down
68 changes: 51 additions & 17 deletions src/libstd/unstable/dynamic_lib.rs
Expand Up @@ -16,16 +16,16 @@ A simple wrapper over the platform's dynamic library facilities
*/


use clone::Clone;
use c_str::ToCStr;
use iter::Iterator;
use mem;
use ops::*;
use option::*;
use os;
use path::GenericPath;
use path;
use path::{Path,GenericPath};
use result::*;
use slice::Vector;
use slice::{Vector,ImmutableVector};
use str;
use vec::Vec;

Expand Down Expand Up @@ -76,22 +76,55 @@ impl DynamicLibrary {
}
}

/// Appends a path to the system search path for dynamic libraries
pub fn add_search_path(path: &path::Path) {
let (envvar, sep) = if cfg!(windows) {
("PATH", ';' as u8)
/// Prepends a path to this process's search path for dynamic libraries
pub fn prepend_search_path(path: &Path) {
let mut search_path = DynamicLibrary::search_path();
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") {
("DYLD_LIBRARY_PATH", ':' as u8)
"DYLD_LIBRARY_PATH"
} else {
("LD_LIBRARY_PATH", ':' as u8)
};
let mut newenv = Vec::from_slice(path.as_vec());
newenv.push(sep);
match os::getenv_as_bytes(envvar) {
Some(bytes) => newenv.push_all(bytes),
"LD_LIBRARY_PATH"
}
}

fn separator() -> u8 {
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 => {}
}
os::setenv(envvar, str::from_utf8(newenv.as_slice()).unwrap());
return ret;
}

/// Access the value at the symbol of the dynamic library
Expand Down Expand Up @@ -168,11 +201,12 @@ mod test {
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod dl {
use prelude::*;

use c_str::ToCStr;
use libc;
use ptr;
use str;
use result::*;

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

0 comments on commit eb6856c

Please sign in to comment.