Teach rustdoc --test
about --sysroot
, pass it when testing rust
This permits rustdoc tests to work in stage0
This commit is contained in:
parent
17d873c2db
commit
babb7daf35
5 changed files with 26 additions and 14 deletions
|
@ -67,6 +67,7 @@ fn main() {
|
||||||
("RUSTC_REAL", "RUSTC_LIBDIR")
|
("RUSTC_REAL", "RUSTC_LIBDIR")
|
||||||
};
|
};
|
||||||
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
|
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
|
||||||
|
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
|
||||||
|
|
||||||
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
|
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
|
||||||
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
|
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
|
||||||
|
@ -83,7 +84,7 @@ fn main() {
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
// The stage0 compiler has a special sysroot distinct from what we
|
// The stage0 compiler has a special sysroot distinct from what we
|
||||||
// actually downloaded, so we just always pass the `--sysroot` option.
|
// actually downloaded, so we just always pass the `--sysroot` option.
|
||||||
cmd.arg("--sysroot").arg(env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"));
|
cmd.arg("--sysroot").arg(sysroot);
|
||||||
|
|
||||||
// When we build Rust dylibs they're all intended for intermediate
|
// When we build Rust dylibs they're all intended for intermediate
|
||||||
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
|
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
|
||||||
|
|
|
@ -25,6 +25,7 @@ fn main() {
|
||||||
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
|
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
|
||||||
let libdir = env::var_os("RUSTC_LIBDIR").expect("RUSTC_LIBDIR was not set");
|
let libdir = env::var_os("RUSTC_LIBDIR").expect("RUSTC_LIBDIR was not set");
|
||||||
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
|
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
|
||||||
|
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
|
||||||
|
|
||||||
let mut dylib_path = bootstrap::util::dylib_path();
|
let mut dylib_path = bootstrap::util::dylib_path();
|
||||||
dylib_path.insert(0, PathBuf::from(libdir));
|
dylib_path.insert(0, PathBuf::from(libdir));
|
||||||
|
@ -35,6 +36,8 @@ fn main() {
|
||||||
.arg(format!("stage{}", stage))
|
.arg(format!("stage{}", stage))
|
||||||
.arg("--cfg")
|
.arg("--cfg")
|
||||||
.arg("dox")
|
.arg("dox")
|
||||||
|
.arg("--sysroot")
|
||||||
|
.arg(sysroot)
|
||||||
.env(bootstrap::util::dylib_path_var(),
|
.env(bootstrap::util::dylib_path_var(),
|
||||||
env::join_paths(&dylib_path).unwrap());
|
env::join_paths(&dylib_path).unwrap());
|
||||||
std::process::exit(match cmd.status() {
|
std::process::exit(match cmd.status() {
|
||||||
|
|
|
@ -267,13 +267,14 @@ pub fn main_args(args: &[String]) -> isize {
|
||||||
};
|
};
|
||||||
let crate_name = matches.opt_str("crate-name");
|
let crate_name = matches.opt_str("crate-name");
|
||||||
let playground_url = matches.opt_str("playground-url");
|
let playground_url = matches.opt_str("playground-url");
|
||||||
|
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
|
||||||
|
|
||||||
match (should_test, markdown_input) {
|
match (should_test, markdown_input) {
|
||||||
(true, true) => {
|
(true, true) => {
|
||||||
return markdown::test(input, cfgs, libs, externs, test_args)
|
return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot)
|
||||||
}
|
}
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
return test::run(input, cfgs, libs, externs, test_args, crate_name)
|
return test::run(input, cfgs, libs, externs, test_args, crate_name, maybe_sysroot)
|
||||||
}
|
}
|
||||||
(false, true) => return markdown::render(input,
|
(false, true) => return markdown::render(input,
|
||||||
output.unwrap_or(PathBuf::from("doc")),
|
output.unwrap_or(PathBuf::from("doc")),
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
||||||
|
|
||||||
/// Run any tests/code examples in the markdown file `input`.
|
/// Run any tests/code examples in the markdown file `input`.
|
||||||
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||||
mut test_args: Vec<String>) -> isize {
|
mut test_args: Vec<String>, maybe_sysroot: Option<PathBuf>) -> isize {
|
||||||
let input_str = match load_string(input) {
|
let input_str = match load_string(input) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(LoadStringError::ReadFail) => return 1,
|
Err(LoadStringError::ReadFail) => return 1,
|
||||||
|
@ -154,7 +154,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||||
let mut opts = TestOptions::default();
|
let mut opts = TestOptions::default();
|
||||||
opts.no_crate_inject = true;
|
opts.no_crate_inject = true;
|
||||||
let mut collector = Collector::new(input.to_string(), cfgs, libs, externs,
|
let mut collector = Collector::new(input.to_string(), cfgs, libs, externs,
|
||||||
true, opts);
|
true, opts, maybe_sysroot);
|
||||||
find_testable_code(&input_str, &mut collector);
|
find_testable_code(&input_str, &mut collector);
|
||||||
test_args.insert(0, "rustdoctest".to_string());
|
test_args.insert(0, "rustdoctest".to_string());
|
||||||
testing::test_main(&test_args, collector.tests);
|
testing::test_main(&test_args, collector.tests);
|
||||||
|
|
|
@ -54,14 +54,15 @@ pub fn run(input: &str,
|
||||||
libs: SearchPaths,
|
libs: SearchPaths,
|
||||||
externs: Externs,
|
externs: Externs,
|
||||||
mut test_args: Vec<String>,
|
mut test_args: Vec<String>,
|
||||||
crate_name: Option<String>)
|
crate_name: Option<String>,
|
||||||
|
maybe_sysroot: Option<PathBuf>)
|
||||||
-> isize {
|
-> isize {
|
||||||
let input_path = PathBuf::from(input);
|
let input_path = PathBuf::from(input);
|
||||||
let input = config::Input::File(input_path.clone());
|
let input = config::Input::File(input_path.clone());
|
||||||
|
|
||||||
let sessopts = config::Options {
|
let sessopts = config::Options {
|
||||||
maybe_sysroot: Some(env::current_exe().unwrap().parent().unwrap()
|
maybe_sysroot: maybe_sysroot.clone().or_else(
|
||||||
.parent().unwrap().to_path_buf()),
|
|| Some(env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_path_buf())),
|
||||||
search_paths: libs.clone(),
|
search_paths: libs.clone(),
|
||||||
crate_types: vec![config::CrateTypeDylib],
|
crate_types: vec![config::CrateTypeDylib],
|
||||||
externs: externs.clone(),
|
externs: externs.clone(),
|
||||||
|
@ -99,7 +100,8 @@ pub fn run(input: &str,
|
||||||
libs,
|
libs,
|
||||||
externs,
|
externs,
|
||||||
false,
|
false,
|
||||||
opts);
|
opts,
|
||||||
|
maybe_sysroot);
|
||||||
|
|
||||||
{
|
{
|
||||||
let dep_graph = DepGraph::new(false);
|
let dep_graph = DepGraph::new(false);
|
||||||
|
@ -157,7 +159,8 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
|
||||||
fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
||||||
externs: Externs,
|
externs: Externs,
|
||||||
should_panic: bool, no_run: bool, as_test_harness: bool,
|
should_panic: bool, no_run: bool, as_test_harness: bool,
|
||||||
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions) {
|
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions,
|
||||||
|
maybe_sysroot: Option<PathBuf>) {
|
||||||
// the test harness wants its own `main` & top level functions, so
|
// the test harness wants its own `main` & top level functions, so
|
||||||
// never wrap the test in `fn main() { ... }`
|
// never wrap the test in `fn main() { ... }`
|
||||||
let test = maketest(test, Some(cratename), as_test_harness, opts);
|
let test = maketest(test, Some(cratename), as_test_harness, opts);
|
||||||
|
@ -168,8 +171,8 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
||||||
let outputs = OutputTypes::new(&[(OutputType::Exe, None)]);
|
let outputs = OutputTypes::new(&[(OutputType::Exe, None)]);
|
||||||
|
|
||||||
let sessopts = config::Options {
|
let sessopts = config::Options {
|
||||||
maybe_sysroot: Some(env::current_exe().unwrap().parent().unwrap()
|
maybe_sysroot: maybe_sysroot.or_else(
|
||||||
.parent().unwrap().to_path_buf()),
|
|| Some(env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_path_buf())),
|
||||||
search_paths: libs,
|
search_paths: libs,
|
||||||
crate_types: vec![config::CrateTypeExecutable],
|
crate_types: vec![config::CrateTypeExecutable],
|
||||||
output_types: outputs,
|
output_types: outputs,
|
||||||
|
@ -379,11 +382,12 @@ pub struct Collector {
|
||||||
current_header: Option<String>,
|
current_header: Option<String>,
|
||||||
cratename: String,
|
cratename: String,
|
||||||
opts: TestOptions,
|
opts: TestOptions,
|
||||||
|
maybe_sysroot: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collector {
|
impl Collector {
|
||||||
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||||
use_headers: bool, opts: TestOptions) -> Collector {
|
use_headers: bool, opts: TestOptions, maybe_sysroot: Option<PathBuf>) -> Collector {
|
||||||
Collector {
|
Collector {
|
||||||
tests: Vec::new(),
|
tests: Vec::new(),
|
||||||
names: Vec::new(),
|
names: Vec::new(),
|
||||||
|
@ -395,6 +399,7 @@ impl Collector {
|
||||||
current_header: None,
|
current_header: None,
|
||||||
cratename: cratename,
|
cratename: cratename,
|
||||||
opts: opts,
|
opts: opts,
|
||||||
|
maybe_sysroot: maybe_sysroot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,6 +418,7 @@ impl Collector {
|
||||||
let externs = self.externs.clone();
|
let externs = self.externs.clone();
|
||||||
let cratename = self.cratename.to_string();
|
let cratename = self.cratename.to_string();
|
||||||
let opts = self.opts.clone();
|
let opts = self.opts.clone();
|
||||||
|
let maybe_sysroot = self.maybe_sysroot.clone();
|
||||||
debug!("Creating test {}: {}", name, test);
|
debug!("Creating test {}: {}", name, test);
|
||||||
self.tests.push(testing::TestDescAndFn {
|
self.tests.push(testing::TestDescAndFn {
|
||||||
desc: testing::TestDesc {
|
desc: testing::TestDesc {
|
||||||
|
@ -432,7 +438,8 @@ impl Collector {
|
||||||
as_test_harness,
|
as_test_harness,
|
||||||
compile_fail,
|
compile_fail,
|
||||||
error_codes,
|
error_codes,
|
||||||
&opts);
|
&opts,
|
||||||
|
maybe_sysroot);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue