From 9b483a8589f5071e70067652d51bed493ef018bd Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 30 Jun 2023 11:16:57 +0200 Subject: [PATCH] Rebased changes --- src/command.rs | 31 +++++++++++++++++++++++++------ src/lib.rs | 10 ++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/command.rs b/src/command.rs index 484d9c8..d8bc288 100644 --- a/src/command.rs +++ b/src/command.rs @@ -112,6 +112,11 @@ pub struct Test { #[arg(long)] pub no_run: bool, + /// If set, documentation tests will be built instead of unit tests. + /// This implies `--no-run`. + #[arg(long)] + pub doc: bool, + // The test command uses a superset of the same arguments as Run. #[command(flatten)] pub run_args: Run, @@ -135,10 +140,23 @@ impl CargoCmd { CargoCmd::Build(build) => build.cargo_args.cargo_args(), CargoCmd::Run(run) => run.build_args.cargo_args.cargo_args(), CargoCmd::Test(test) => { - // We can't run 3DS executables on the host, so pass "--no-run" here and - // send the executable with 3dslink later, if the user wants let mut cargo_args = test.run_args.build_args.cargo_args.cargo_args(); - cargo_args.push("--no-run".to_string()); + + // We can't run 3DS executables on the host, so unconditionally pass + // --no-run here and send the executable with 3dslink later, if the + // user wants + if test.doc { + eprintln!("Documentation tests requested, no 3dsx will be built or run"); + + // https://github.com/rust-lang/cargo/issues/7040 + cargo_args.append(&mut vec![ + "--doc".to_string(), + "-Z".to_string(), + "doctest-xcompile".to_string(), + ]); + } else { + cargo_args.push("--no-run".to_string()); + } cargo_args } @@ -198,10 +216,11 @@ impl CargoCmd { pub fn extract_message_format(&mut self) -> Result, String> { let cargo_args = match self { - Self::Build(args) => &mut args.args, - Self::Run(run) => &mut run.cargo_args.args, + Self::Build(build) => &mut build.cargo_args.args, + Self::Run(run) => &mut run.build_args.cargo_args.args, + Self::New(new) => &mut new.cargo_args.args, + Self::Test(test) => &mut test.run_args.build_args.cargo_args.args, Self::Passthrough(args) => args, - Self::Test(test) => &mut test.run_args.cargo_args.args, }; let format = Self::extract_message_format_from_args(cargo_args)?; diff --git a/src/lib.rs b/src/lib.rs index acdb129..0af6431 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,6 +84,16 @@ pub fn make_cargo_command(cmd: &CargoCmd, message_format: &Option) -> Co } } + if matches!(cmd, CargoCmd::Test(_)) { + // Cargo doesn't like --no-run for doctests: + // https://github.com/rust-lang/rust/issues/87022 + let rustdoc_flags = std::env::var("RUSTDOCFLAGS").unwrap_or_default() + // TODO: should we make this output directory depend on profile etc? + + " --no-run --persist-doctests target/doctests"; + + command.env("RUSTDOCFLAGS", rustdoc_flags); + } + let cargo_args = cmd.cargo_args(); command