Skip to content

Commit 2931e56

Browse files
Respect --no-run when using custom runner
Also do some other small cleanups for minor optimizations
1 parent aa0d754 commit 2931e56

File tree

3 files changed

+76
-92
lines changed

3 files changed

+76
-92
lines changed

Cargo.lock

Lines changed: 32 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/command.rs

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,30 +160,7 @@ impl CargoCmd {
160160
match self {
161161
CargoCmd::Build(build) => build.passthrough.cargo_args(),
162162
CargoCmd::Run(run) => run.build_args.passthrough.cargo_args(),
163-
CargoCmd::Test(test) => {
164-
let mut cargo_args = test.run_args.build_args.passthrough.cargo_args();
165-
166-
// We can't run 3DS executables on the host, but we want to respect
167-
// the user's "runner" configuration if set.
168-
//
169-
// If doctests were requested, `--no-run` will be rejected on the
170-
// command line and must be set with RUSTDOCFLAGS instead:
171-
// https://github.com/rust-lang/rust/issues/87022
172-
if !test.run_args.use_custom_runner() && !test.doc {
173-
cargo_args.push("--no-run".to_string());
174-
}
175-
176-
if test.doc {
177-
cargo_args.extend([
178-
"--doc".into(),
179-
// https://github.com/rust-lang/cargo/issues/7040
180-
"-Z".into(),
181-
"doctest-xcompile".into(),
182-
]);
183-
}
184-
185-
cargo_args
186-
}
163+
CargoCmd::Test(test) => test.cargo_args(),
187164
CargoCmd::New(new) => {
188165
// We push the original path in the new command (we captured it in [`New`] to learn about the context)
189166
let mut cargo_args = new.cargo_args.cargo_args();
@@ -493,6 +470,46 @@ impl Test {
493470
self.run_args.callback(config);
494471
}
495472
}
473+
474+
fn should_run(&self) -> bool {
475+
self.run_args.use_custom_runner() && !self.no_run
476+
}
477+
478+
/// The args to pass to the underlying `cargo test` command.
479+
fn cargo_args(&self) -> Vec<String> {
480+
let mut cargo_args = self.run_args.build_args.passthrough.cargo_args();
481+
482+
// We can't run 3DS executables on the host, but we want to respect
483+
// the user's "runner" configuration if set.
484+
//
485+
// If doctests were requested, `--no-run` will be rejected on the
486+
// command line and must be set with RUSTDOCFLAGS instead:
487+
// https://github.com/rust-lang/rust/issues/87022
488+
489+
if self.doc {
490+
cargo_args.extend([
491+
"--doc".into(),
492+
// https://github.com/rust-lang/cargo/issues/7040
493+
"-Z".into(),
494+
"doctest-xcompile".into(),
495+
]);
496+
} else if !self.should_run() {
497+
cargo_args.push("--no-run".into());
498+
}
499+
500+
cargo_args
501+
}
502+
503+
/// Flags to pass to rustdoc via RUSTDOCFLAGS
504+
pub(crate) fn rustdocflags(&self) -> &'static str {
505+
if self.should_run() {
506+
""
507+
} else {
508+
// We don't support running doctests by default, but cargo doesn't like
509+
// --no-run for doctests, so we have to plumb it in via RUSTDOCFLAGS
510+
" --no-run"
511+
}
512+
}
496513
}
497514

498515
const TOML_CHANGES: &str = r#"ctru-rs = { git = "https://github.com/rust3ds/ctru-rs" }

src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use cargo_metadata::{Message, MetadataCommand};
1010
use command::{Input, Test};
1111
use rustc_version::Channel;
1212
use semver::Version;
13-
use serde::Deserialize;
1413
use tee::TeeReader;
1514

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

10099
if let CargoCmd::Test(test) = cargo_cmd {
101-
let no_run_flag = if test.run_args.use_custom_runner() {
102-
""
103-
} else {
104-
// We don't support running doctests by default, but cargo doesn't like
105-
// --no-run for doctests, so we have to plumb it in via RUSTDOCFLAGS
106-
" --no-run"
107-
};
108-
109100
// RUSTDOCFLAGS is simply ignored if --doc wasn't passed, so we always set it.
110-
let rustdoc_flags = std::env::var("RUSTDOCFLAGS").unwrap_or_default() + no_run_flag;
101+
let rustdoc_flags = std::env::var("RUSTDOCFLAGS").unwrap_or_default() + test.rustdocflags();
111102
command.env("RUSTDOCFLAGS", rustdoc_flags);
112103
}
113104

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

@@ -399,7 +391,7 @@ pub fn get_romfs_path(config: &CTRConfig) -> (PathBuf, bool) {
399391
(romfs_path, is_default)
400392
}
401393

402-
#[derive(Deserialize, Default)]
394+
#[derive(Default)]
403395
pub struct CTRConfig {
404396
name: String,
405397
author: String,

0 commit comments

Comments
 (0)