Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect --no-run when using custom runner #46

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

65 changes: 41 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,46 @@ impl Test {
self.run_args.callback(config);
}
}

fn should_run(&self) -> bool {
self.run_args.use_custom_runner() && !self.no_run
}

/// 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.should_run() {
cargo_args.push("--no-run".into());
}

cargo_args
}

/// Flags to pass to rustdoc via RUSTDOCFLAGS
pub(crate) fn rustdocflags(&self) -> &'static str {
if self.should_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
Loading