Skip to content

Commit

Permalink
Remove global options from IndividualTestOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed May 31, 2024
1 parent 7854e6f commit e809fba
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ fn run_test(
test: &str,
crate_name: &str,
line: usize,
rustdoc_options: IndividualTestOptions,
rustdoc_options: &RustdocOptions,
test_options: IndividualTestOptions,
mut lang_string: LangString,
no_run: bool,
opts: &GlobalTestOptions,
Expand All @@ -379,20 +380,20 @@ fn run_test(
lang_string.test_harness,
opts,
edition,
Some(&rustdoc_options.test_id),
Some(&test_options.test_id),
);

// Make sure we emit well-formed executable names for our target.
let rust_out = add_exe_suffix("rust_out".to_owned(), &rustdoc_options.target);
let output_file = rustdoc_options.outdir.path().join(rust_out);
let output_file = test_options.outdir.path().join(rust_out);

let rustc_binary = rustdoc_options
.test_builder
.as_deref()
.unwrap_or_else(|| rustc_interface::util::rustc_path().expect("found rustc"));
let mut compiler = wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);

compiler.arg(&format!("@{}", rustdoc_options.arg_file.display()));
compiler.arg(&format!("@{}", test_options.arg_file.display()));

if let Some(sysroot) = &rustdoc_options.maybe_sysroot {
compiler.arg(format!("--sysroot={}", sysroot.display()));
Expand All @@ -405,20 +406,21 @@ fn run_test(
if lang_string.test_harness {
compiler.arg("--test");
}
if rustdoc_options.is_json_unused_externs_enabled && !lang_string.compile_fail {
if rustdoc_options.json_unused_externs.is_enabled() && !lang_string.compile_fail {
compiler.arg("--error-format=json");
compiler.arg("--json").arg("unused-externs");
compiler.arg("-W").arg("unused_crate_dependencies");
compiler.arg("-Z").arg("unstable-options");
}

if no_run && !lang_string.compile_fail && rustdoc_options.should_persist_doctests {
if no_run && !lang_string.compile_fail && rustdoc_options.persist_doctests.is_some() {
// FIXME!!! previously the code checked persisted_doctest.is_none(), but that doesn't make sense
compiler.arg("--emit=metadata");
}
compiler.arg("--target").arg(match rustdoc_options.target {
compiler.arg("--target").arg(match &rustdoc_options.target {
TargetTriple::TargetTriple(s) => s,
TargetTriple::TargetJson { path_for_rustdoc, .. } => {
path_for_rustdoc.to_str().expect("target path must be valid unicode").to_string()
path_for_rustdoc.to_str().expect("target path must be valid unicode")
}
});
if let ErrorOutputType::HumanReadable(kind) = rustdoc_options.error_format {
Expand Down Expand Up @@ -511,15 +513,15 @@ fn run_test(
let mut cmd;

let output_file = make_maybe_absolute_path(output_file);
if let Some(tool) = rustdoc_options.runtool {
if let Some(tool) = &rustdoc_options.runtool {
let tool = make_maybe_absolute_path(tool.into());
cmd = Command::new(tool);
cmd.args(rustdoc_options.runtool_args);
cmd.args(&rustdoc_options.runtool_args);
cmd.arg(output_file);
} else {
cmd = Command::new(output_file);
}
if let Some(run_directory) = rustdoc_options.test_run_directory {
if let Some(run_directory) = &rustdoc_options.test_run_directory {
cmd.current_dir(run_directory);
}

Expand Down Expand Up @@ -924,20 +926,9 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) {
}

pub(crate) struct IndividualTestOptions {
test_builder: Option<PathBuf>,
test_builder_wrappers: Vec<PathBuf>,
is_json_unused_externs_enabled: bool,
should_persist_doctests: bool,
error_format: ErrorOutputType,
test_run_directory: Option<PathBuf>,
nocapture: bool,
arg_file: PathBuf,
outdir: DirState,
runtool: Option<String>,
runtool_args: Vec<String>,
target: TargetTriple,
test_id: String,
maybe_sysroot: Option<PathBuf>,
}

impl IndividualTestOptions {
Expand All @@ -956,22 +947,7 @@ impl IndividualTestOptions {
DirState::Temp(get_doctest_dir().expect("rustdoc needs a tempdir"))
};

Self {
test_builder: options.test_builder.clone(),
test_builder_wrappers: options.test_builder_wrappers.clone(),
is_json_unused_externs_enabled: options.json_unused_externs.is_enabled(),
should_persist_doctests: options.persist_doctests.is_none(),
error_format: options.error_format,
test_run_directory: options.test_run_directory.clone(),
nocapture: options.nocapture,
arg_file: arg_file.into(),
outdir,
runtool: options.runtool.clone(),
runtool_args: options.runtool_args.clone(),
target: options.target.clone(),
test_id,
maybe_sysroot: options.maybe_sysroot.clone(),
}
Self { arg_file: arg_file.into(), outdir, test_id }
}
}

Expand All @@ -995,7 +971,7 @@ pub(crate) trait DoctestVisitor {
pub(crate) struct CreateRunnableDoctests {
pub(crate) tests: Vec<test::TestDescAndFn>,

rustdoc_options: RustdocOptions,
rustdoc_options: Arc<RustdocOptions>,
crate_name: String,
opts: GlobalTestOptions,
visited_tests: FxHashMap<(String, usize), usize>,
Expand All @@ -1013,7 +989,7 @@ impl CreateRunnableDoctests {
) -> CreateRunnableDoctests {
CreateRunnableDoctests {
tests: Vec::new(),
rustdoc_options,
rustdoc_options: Arc::new(rustdoc_options),
crate_name,
opts,
visited_tests: FxHashMap::default(),
Expand Down Expand Up @@ -1078,6 +1054,7 @@ impl CreateRunnableDoctests {
},
);

let rustdoc_options = self.rustdoc_options.clone();
let rustdoc_test_options =
IndividualTestOptions::new(&self.rustdoc_options, &self.arg_file, test_id);

Expand Down Expand Up @@ -1113,6 +1090,7 @@ impl CreateRunnableDoctests {
path,
scraped_test: test,
},
rustdoc_options,
unused_externs,
)
})),
Expand All @@ -1133,6 +1111,7 @@ struct RunnableDoctest {

fn doctest_run_fn(
runnable_test: RunnableDoctest,
rustdoc_options: Arc<RustdocOptions>,
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,
) -> Result<(), String> {
let report_unused_externs = |uext| {
Expand All @@ -1142,6 +1121,7 @@ fn doctest_run_fn(
&runnable_test.scraped_test.text,
&runnable_test.crate_name,
runnable_test.scraped_test.line,
&rustdoc_options,
runnable_test.rustdoc_test_options,
runnable_test.scraped_test.langstr,
runnable_test.no_run,
Expand Down

0 comments on commit e809fba

Please sign in to comment.