From 093cbd60fc331e9aab63fc4cdd8b8c9a043eaa3e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 9 Sep 2019 21:11:27 -0400 Subject: [PATCH] Add unstable --test-builder to rustdoc This allows overriding the rustc binary used to build tests; it should not generally be necessary as we fallback to the sysroot. --- src/librustdoc/config.rs | 6 ++++++ src/librustdoc/lib.rs | 5 +++++ src/librustdoc/test.rs | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 995a340143f78..19ea781430041 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -86,6 +86,10 @@ pub struct Options { /// contains "foo" as a substring pub enable_per_target_ignores: bool, + /// The path to a rustc-like binary to build tests with. If not set, we + /// default to loading from $sysroot/bin/rustc. + pub test_builder: Option, + // Options that affect the documentation process /// The selected default set of passes to use. @@ -476,6 +480,7 @@ impl Options { let generate_search_filter = !matches.opt_present("disable-per-crate-search"); let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from); let generate_redirect_pages = matches.opt_present("generate-redirect-pages"); + let test_builder = matches.opt_str("test-builder").map(PathBuf::from); let codegen_options_strs = matches.opt_strs("C"); let lib_strs = matches.opt_strs("L"); let extern_strs = matches.opt_strs("extern"); @@ -515,6 +520,7 @@ impl Options { runtool, runtool_args, enable_per_target_ignores, + test_builder, render_options: RenderOptions { output, external_html, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 88da1b16686b0..d77e790d4a481 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -373,6 +373,11 @@ fn opts() -> Vec { "", "One (of possibly many) arguments to pass to the runtool") }), + unstable("test-builder", |o| { + o.optflag("", + "test-builder", + "specified the rustc-like binary to use as the test builder") + }), ] } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 30ed725ad2089..816b7836fb12a 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -248,7 +248,10 @@ fn run_test( }; let output_file = outdir.path().join("rust_out"); - let mut compiler = Command::new(rustc_interface::util::rustc_path().expect("found rustc")); + let rustc_binary = options.test_builder.as_ref().map(|v| &**v).unwrap_or_else(|| { + rustc_interface::util::rustc_path().expect("found rustc") + }); + let mut compiler = Command::new(&rustc_binary); compiler.arg("--crate-type").arg("bin"); for cfg in &options.cfgs { compiler.arg("--cfg").arg(&cfg);