Auto merge of #38589 - aidanhs:aphs-stage0-rustdoc-test, r=alexcrichton
Teach `rustdoc --test` about `--sysroot`, pass it when testing rust This permits rustdoc tests to work in stage0. Logical continuation of #36586. Snippet from https://github.com/rust-lang/rust/issues/38575#issuecomment-269090724: > it should actually be possible to run all the libstd tests immediately after creating std of stage0-out - there's no reason to build librustc at all if you've just made a change to (for example) libcollections, `./x.py test src/libcollections --stage 0 -v --incremental` should just work This PR makes it so (or appears to in my testing). r? @alexcrichton
This commit is contained in:
commit
17f1fba353
@ -67,6 +67,7 @@ fn main() {
|
||||
("RUSTC_REAL", "RUSTC_LIBDIR")
|
||||
};
|
||||
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 libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
|
||||
@ -83,7 +84,7 @@ fn main() {
|
||||
if let Some(target) = target {
|
||||
// The stage0 compiler has a special sysroot distinct from what we
|
||||
// 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
|
||||
// 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 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 sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
|
||||
|
||||
let mut dylib_path = bootstrap::util::dylib_path();
|
||||
dylib_path.insert(0, PathBuf::from(libdir));
|
||||
@ -35,6 +36,8 @@ fn main() {
|
||||
.arg(format!("stage{}", stage))
|
||||
.arg("--cfg")
|
||||
.arg("dox")
|
||||
.arg("--sysroot")
|
||||
.arg(sysroot)
|
||||
.env(bootstrap::util::dylib_path_var(),
|
||||
env::join_paths(&dylib_path).unwrap());
|
||||
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 playground_url = matches.opt_str("playground-url");
|
||||
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
|
||||
|
||||
match (should_test, markdown_input) {
|
||||
(true, true) => {
|
||||
return markdown::test(input, cfgs, libs, externs, test_args)
|
||||
return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot)
|
||||
}
|
||||
(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,
|
||||
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`.
|
||||
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) {
|
||||
Ok(s) => s,
|
||||
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();
|
||||
opts.no_crate_inject = true;
|
||||
let mut collector = Collector::new(input.to_string(), cfgs, libs, externs,
|
||||
true, opts);
|
||||
true, opts, maybe_sysroot);
|
||||
find_testable_code(&input_str, &mut collector);
|
||||
test_args.insert(0, "rustdoctest".to_string());
|
||||
testing::test_main(&test_args, collector.tests);
|
||||
|
@ -54,14 +54,15 @@ pub fn run(input: &str,
|
||||
libs: SearchPaths,
|
||||
externs: Externs,
|
||||
mut test_args: Vec<String>,
|
||||
crate_name: Option<String>)
|
||||
crate_name: Option<String>,
|
||||
maybe_sysroot: Option<PathBuf>)
|
||||
-> isize {
|
||||
let input_path = PathBuf::from(input);
|
||||
let input = config::Input::File(input_path.clone());
|
||||
|
||||
let sessopts = config::Options {
|
||||
maybe_sysroot: Some(env::current_exe().unwrap().parent().unwrap()
|
||||
.parent().unwrap().to_path_buf()),
|
||||
maybe_sysroot: maybe_sysroot.clone().or_else(
|
||||
|| Some(env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_path_buf())),
|
||||
search_paths: libs.clone(),
|
||||
crate_types: vec![config::CrateTypeDylib],
|
||||
externs: externs.clone(),
|
||||
@ -99,7 +100,8 @@ pub fn run(input: &str,
|
||||
libs,
|
||||
externs,
|
||||
false,
|
||||
opts);
|
||||
opts,
|
||||
maybe_sysroot);
|
||||
|
||||
{
|
||||
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,
|
||||
externs: Externs,
|
||||
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
|
||||
// never wrap the test in `fn main() { ... }`
|
||||
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 sessopts = config::Options {
|
||||
maybe_sysroot: Some(env::current_exe().unwrap().parent().unwrap()
|
||||
.parent().unwrap().to_path_buf()),
|
||||
maybe_sysroot: maybe_sysroot.or_else(
|
||||
|| Some(env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_path_buf())),
|
||||
search_paths: libs,
|
||||
crate_types: vec![config::CrateTypeExecutable],
|
||||
output_types: outputs,
|
||||
@ -379,11 +382,12 @@ pub struct Collector {
|
||||
current_header: Option<String>,
|
||||
cratename: String,
|
||||
opts: TestOptions,
|
||||
maybe_sysroot: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Collector {
|
||||
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 {
|
||||
tests: Vec::new(),
|
||||
names: Vec::new(),
|
||||
@ -395,6 +399,7 @@ impl Collector {
|
||||
current_header: None,
|
||||
cratename: cratename,
|
||||
opts: opts,
|
||||
maybe_sysroot: maybe_sysroot,
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,6 +418,7 @@ impl Collector {
|
||||
let externs = self.externs.clone();
|
||||
let cratename = self.cratename.to_string();
|
||||
let opts = self.opts.clone();
|
||||
let maybe_sysroot = self.maybe_sysroot.clone();
|
||||
debug!("Creating test {}: {}", name, test);
|
||||
self.tests.push(testing::TestDescAndFn {
|
||||
desc: testing::TestDesc {
|
||||
@ -432,7 +438,8 @@ impl Collector {
|
||||
as_test_harness,
|
||||
compile_fail,
|
||||
error_codes,
|
||||
&opts);
|
||||
&opts,
|
||||
maybe_sysroot);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user