Skip to content

Commit

Permalink
Add unstable --test-builder to rustdoc
Browse files Browse the repository at this point in the history
This allows overriding the rustc binary used to build tests; it should
not generally be necessary as we fallback to the sysroot.
  • Loading branch information
Mark-Simulacrum committed Sep 10, 2019
1 parent 2fc32b9 commit 093cbd6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

// Options that affect the documentation process

/// The selected default set of passes to use.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -515,6 +520,7 @@ impl Options {
runtool,
runtool_args,
enable_per_target_ignores,
test_builder,
render_options: RenderOptions {
output,
external_html,
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ fn opts() -> Vec<RustcOptGroup> {
"",
"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")
}),
]
}

Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 093cbd6

Please sign in to comment.