Skip to content

Commit 6a86e76

Browse files
committed
rustdoc: add --test-builder-wrapper argument
Instead of executing the test builder directly, the test builder wrapper will be called with test builder as the first argument and subsequent arguments. This is similar to cargo's RUSTC_WRAPPER argument. The `--test-builder-wrapper` argument can be passed multiple times to allow "nesting" of wrappers.
1 parent 6ef7d16 commit 6a86e76

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/librustdoc/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ pub(crate) struct Options {
130130
/// default to loading from `$sysroot/bin/rustc`.
131131
pub(crate) test_builder: Option<PathBuf>,
132132

133+
/// Run these wrapper instead of rustc directly
134+
pub(crate) test_builder_wrappers: Vec<PathBuf>,
135+
133136
// Options that affect the documentation process
134137
/// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
135138
/// with and without documentation.
@@ -198,6 +201,7 @@ impl fmt::Debug for Options {
198201
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
199202
.field("run_check", &self.run_check)
200203
.field("no_run", &self.no_run)
204+
.field("test_builder_wrappers", &self.test_builder_wrappers)
201205
.field("nocapture", &self.nocapture)
202206
.field("scrape_examples_options", &self.scrape_examples_options)
203207
.field("unstable_features", &self.unstable_features)
@@ -516,6 +520,8 @@ impl Options {
516520
return Err(1);
517521
}
518522

523+
let test_builder_wrappers =
524+
matches.opt_strs("test-builder-wrapper").iter().map(PathBuf::from).collect();
519525
let out_dir = matches.opt_str("out-dir").map(|s| PathBuf::from(&s));
520526
let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
521527
let output = match (out_dir, output) {
@@ -735,6 +741,7 @@ impl Options {
735741
test_builder,
736742
run_check,
737743
no_run,
744+
test_builder_wrappers,
738745
nocapture,
739746
crate_name,
740747
output_format,

src/librustdoc/doctest.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use tempfile::Builder as TempFileBuilder;
2323
use std::env;
2424
use std::io::{self, Write};
2525
use std::panic;
26-
use std::path::PathBuf;
26+
use std::path::{Path, PathBuf};
2727
use std::process::{self, Command, Stdio};
2828
use std::str;
2929
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -303,6 +303,16 @@ fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
303303
input + &exe_suffix
304304
}
305305

306+
fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Command {
307+
let args: Vec<&Path> =
308+
rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter()).collect();
309+
let (exe, args) = args.split_first().expect("unable to create rustc command");
310+
311+
let mut command = Command::new(exe);
312+
command.args(args);
313+
command
314+
}
315+
306316
fn run_test(
307317
test: &str,
308318
crate_name: &str,
@@ -331,7 +341,7 @@ fn run_test(
331341
.test_builder
332342
.as_deref()
333343
.unwrap_or_else(|| rustc_interface::util::rustc_path().expect("found rustc"));
334-
let mut compiler = Command::new(&rustc_binary);
344+
let mut compiler = wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
335345
compiler.arg("--crate-type").arg("bin");
336346
for cfg in &rustdoc_options.cfgs {
337347
compiler.arg("--cfg").arg(&cfg);

src/librustdoc/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ fn opts() -> Vec<RustcOptGroup> {
551551
unstable("test-builder", |o| {
552552
o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH")
553553
}),
554+
unstable("test-builder-wrapper", |o| {
555+
o.optmulti(
556+
"",
557+
"test-builder-wrapper",
558+
"The wrapper program for running rustc",
559+
"WRAPPER",
560+
)
561+
}),
554562
unstable("check", |o| o.optflagmulti("", "check", "Run rustdoc checks")),
555563
unstable("generate-redirect-map", |o| {
556564
o.optflagmulti(

0 commit comments

Comments
 (0)