Skip to content

Commit a537585

Browse files
Merge #1342
1342: Explain why fallback happened when subcommand is not supported, and fix rustdoc r=Emilgardis a=Emilgardis Resolves #1341 by adding rustdoc as a supported command. Also adds a explanation when a unsupported subcommand is used. This also fixes a bug with `--list` Co-authored-by: Emil Gardström <[email protected]>
2 parents 3c21f9e + a15bbc5 commit a537585

File tree

6 files changed

+45
-11
lines changed

6 files changed

+45
-11
lines changed

.changes/1342.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"description": "fix `--list` showing cross commands for the host",
4+
"type": "fixed"
5+
},
6+
{
7+
"description": "add `rustdoc` as a supported cargo subcommand",
8+
"type": "added"
9+
}
10+
]

src/bin/cross.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn main() -> cross::Result<()> {
1717

1818
let target_list = rustc::target_list(&mut Verbosity::Quiet.into())?;
1919
let args = cli::parse(&target_list)?;
20-
let subcommand = args.subcommand;
20+
let subcommand = args.subcommand.clone();
2121
let mut msg_info = shell::MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?;
2222
let status = match cross::run(args, target_list, &mut msg_info)? {
2323
Some(status) => status,

src/cargo.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@ use crate::errors::*;
77
use crate::extensions::CommandExt;
88
use crate::shell::{self, MessageInfo};
99

10-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10+
#[derive(Debug, Clone, PartialEq, Eq)]
1111
pub enum Subcommand {
1212
Build,
1313
Check,
1414
Doc,
15-
Other,
1615
Run,
16+
Rustdoc,
1717
Rustc,
1818
Test,
1919
Bench,
2020
Clippy,
2121
Metadata,
2222
List,
2323
Clean,
24+
Other(String),
2425
}
2526

2627
impl Subcommand {
2728
#[must_use]
2829
pub fn needs_docker(self, is_remote: bool) -> bool {
2930
match self {
30-
Subcommand::Other | Subcommand::List => false,
31+
Subcommand::Other(_) | Subcommand::List => false,
3132
Subcommand::Clean if !is_remote => false,
3233
_ => true,
3334
}
@@ -58,12 +59,13 @@ impl<'a> From<&'a str> for Subcommand {
5859
"doc" => Subcommand::Doc,
5960
"r" | "run" => Subcommand::Run,
6061
"rustc" => Subcommand::Rustc,
62+
"rustdoc" => Subcommand::Rustdoc,
6163
"t" | "test" => Subcommand::Test,
6264
"bench" => Subcommand::Bench,
6365
"clippy" => Subcommand::Clippy,
6466
"metadata" => Subcommand::Metadata,
6567
"--list" => Subcommand::List,
66-
_ => Subcommand::Other,
68+
command => Subcommand::Other(command.to_owned()),
6769
}
6870
}
6971
}

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn group_subcommands(stdout: &str) -> (Vec<&str>, Vec<&str>) {
3636
let first = line.split_whitespace().next();
3737
if let Some(command) = first {
3838
match Subcommand::from(command) {
39-
Subcommand::Other => host.push(line),
39+
Subcommand::Other(_) => host.push(line),
4040
_ => cross.push(line),
4141
}
4242
}
@@ -55,7 +55,7 @@ pub fn fmt_subcommands(stdout: &str, msg_info: &mut MessageInfo) -> Result<()> {
5555
}
5656
if !host.is_empty() {
5757
msg_info.print("Host Commands:")?;
58-
for line in &cross {
58+
for line in &host {
5959
msg_info.print(line)?;
6060
}
6161
}

src/lib.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ pub fn run(
524524
))?;
525525
}
526526

527+
if let Some(Subcommand::Other(command)) = &args.subcommand {
528+
msg_info.warn(format_args!(
529+
"specified cargo subcommand `{command}` is not supported by `cross`."
530+
))?;
531+
return Ok(None);
532+
}
533+
527534
let host_version_meta = rustc::version_meta()?;
528535

529536
let cwd = std::env::current_dir()?;
@@ -597,6 +604,7 @@ pub fn run(
597604

598605
let needs_docker = args
599606
.subcommand
607+
.clone()
600608
.map_or(false, |sc| sc.needs_docker(is_remote));
601609
if target.needs_docker() && needs_docker {
602610
let paths = docker::DockerPaths::create(
@@ -623,8 +631,14 @@ pub fn run(
623631
&options,
624632
msg_info,
625633
)?;
626-
let status = docker::run(options, paths, &filtered_args, args.subcommand, msg_info)
627-
.wrap_err("could not run container")?;
634+
let status = docker::run(
635+
options,
636+
paths,
637+
&filtered_args,
638+
args.subcommand.clone(),
639+
msg_info,
640+
)
641+
.wrap_err("could not run container")?;
628642
let needs_host = args.subcommand.map_or(false, |sc| sc.needs_host(is_remote));
629643
if !status.success() {
630644
warn_on_failure(&target, &toolchain, msg_info)?;
@@ -646,7 +660,10 @@ pub fn install_interpreter_if_needed(
646660
options: &docker::DockerOptions,
647661
msg_info: &mut MessageInfo,
648662
) -> Result<(), color_eyre::Report> {
649-
let needs_interpreter = args.subcommand.map_or(false, |sc| sc.needs_interpreter());
663+
let needs_interpreter = args
664+
.subcommand
665+
.clone()
666+
.map_or(false, |sc| sc.needs_interpreter());
650667

651668
if host_version_meta.needs_interpreter()
652669
&& needs_interpreter
@@ -670,6 +687,7 @@ pub fn get_filtered_args(
670687
let add_libc = |triple: &str| add_libc_version(triple, zig_version.as_deref());
671688
let mut filtered_args = if args
672689
.subcommand
690+
.clone()
673691
.map_or(false, |s| !s.needs_target_in_command())
674692
{
675693
let mut filtered_args = Vec::new();
@@ -710,7 +728,10 @@ pub fn get_filtered_args(
710728
args.cargo_args.clone()
711729
};
712730

713-
let is_test = args.subcommand.map_or(false, |sc| sc == Subcommand::Test);
731+
let is_test = args
732+
.subcommand
733+
.clone()
734+
.map_or(false, |sc| sc == Subcommand::Test);
714735
if is_test && config.doctests().unwrap_or_default() && is_nightly {
715736
filtered_args.push("-Zdoctest-xcompile".to_owned());
716737
}

src/rustup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ pub fn setup_components(
299299
}
300300
if args
301301
.subcommand
302+
.clone()
302303
.map_or(false, |sc| sc == crate::Subcommand::Clippy)
303304
&& !component_is_installed("clippy", toolchain, msg_info)?
304305
{

0 commit comments

Comments
 (0)