Skip to content

Commit

Permalink
Respect --no-run when using custom runner
Browse files Browse the repository at this point in the history
Also do some other small cleanups for minor optimizations
  • Loading branch information
ian-h-chamberlain committed Sep 29, 2023
1 parent aa0d754 commit 03124ea
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 92 deletions.
89 changes: 32 additions & 57 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 37 additions & 24 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,7 @@ impl CargoCmd {
match self {
CargoCmd::Build(build) => build.passthrough.cargo_args(),
CargoCmd::Run(run) => run.build_args.passthrough.cargo_args(),
CargoCmd::Test(test) => {
let mut cargo_args = test.run_args.build_args.passthrough.cargo_args();

// We can't run 3DS executables on the host, but we want to respect
// the user's "runner" configuration if set.
//
// If doctests were requested, `--no-run` will be rejected on the
// command line and must be set with RUSTDOCFLAGS instead:
// https://github.com/rust-lang/rust/issues/87022
if !test.run_args.use_custom_runner() && !test.doc {
cargo_args.push("--no-run".to_string());
}

if test.doc {
cargo_args.extend([
"--doc".into(),
// https://github.com/rust-lang/cargo/issues/7040
"-Z".into(),
"doctest-xcompile".into(),
]);
}

cargo_args
}
CargoCmd::Test(test) => test.cargo_args(),
CargoCmd::New(new) => {
// We push the original path in the new command (we captured it in [`New`] to learn about the context)
let mut cargo_args = new.cargo_args.cargo_args();
Expand Down Expand Up @@ -493,6 +470,42 @@ impl Test {
self.run_args.callback(config);
}
}

/// The args to pass to the underlying `cargo test` command.
fn cargo_args(&self) -> Vec<String> {
let mut cargo_args = self.run_args.build_args.passthrough.cargo_args();

// We can't run 3DS executables on the host, but we want to respect
// the user's "runner" configuration if set.
//
// If doctests were requested, `--no-run` will be rejected on the
// command line and must be set with RUSTDOCFLAGS instead:
// https://github.com/rust-lang/rust/issues/87022

if self.doc {
cargo_args.extend([
"--doc".into(),
// https://github.com/rust-lang/cargo/issues/7040
"-Z".into(),
"doctest-xcompile".into(),
]);
} else if self.no_run || !self.run_args.use_custom_runner() {
cargo_args.push("--no-run".into());
}

cargo_args
}

/// Flags to pass to rustdoc via RUSTDOCFLAGS
pub(crate) fn rustdocflags(&self) -> &'static str {
if self.run_args.use_custom_runner() && !self.no_run {
""
} else {
// We don't support running doctests by default, but cargo doesn't like
// --no-run for doctests, so we have to plumb it in via RUSTDOCFLAGS
" --no-run"
}
}
}

const TOML_CHANGES: &str = r#"ctru-rs = { git = "https://github.com/rust3ds/ctru-rs" }
Expand Down
14 changes: 3 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use cargo_metadata::{Message, MetadataCommand};
use command::{Input, Test};
use rustc_version::Channel;
use semver::Version;
use serde::Deserialize;
use tee::TeeReader;

use crate::command::{CargoCmd, Run};
Expand Down Expand Up @@ -98,16 +97,8 @@ pub fn make_cargo_command(input: &Input, message_format: &Option<String>) -> Com
}

if let CargoCmd::Test(test) = cargo_cmd {
let no_run_flag = if test.run_args.use_custom_runner() {
""
} else {
// We don't support running doctests by default, but cargo doesn't like
// --no-run for doctests, so we have to plumb it in via RUSTDOCFLAGS
" --no-run"
};

// RUSTDOCFLAGS is simply ignored if --doc wasn't passed, so we always set it.
let rustdoc_flags = std::env::var("RUSTDOCFLAGS").unwrap_or_default() + no_run_flag;
let rustdoc_flags = std::env::var("RUSTDOCFLAGS").unwrap_or_default() + test.rustdocflags();
command.env("RUSTDOCFLAGS", rustdoc_flags);
}

Expand Down Expand Up @@ -212,6 +203,7 @@ pub fn check_rust_version() {
/// in [`build_smdh`], [`build_3dsx`], and [`link`].
pub fn get_metadata(messages: &[Message]) -> CTRConfig {
let metadata = MetadataCommand::new()
.no_deps()
.exec()
.expect("Failed to get cargo metadata");

Expand Down Expand Up @@ -399,7 +391,7 @@ pub fn get_romfs_path(config: &CTRConfig) -> (PathBuf, bool) {
(romfs_path, is_default)
}

#[derive(Deserialize, Default)]
#[derive(Default)]
pub struct CTRConfig {
name: String,
author: String,
Expand Down

0 comments on commit 03124ea

Please sign in to comment.