Skip to content

Commit

Permalink
Merge #1342
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and Emilgardis authored Oct 12, 2023
2 parents 3c21f9e + a15bbc5 commit a537585
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .changes/1342.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"description": "fix `--list` showing cross commands for the host",
"type": "fixed"
},
{
"description": "add `rustdoc` as a supported cargo subcommand",
"type": "added"
}
]
2 changes: 1 addition & 1 deletion src/bin/cross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn main() -> cross::Result<()> {

let target_list = rustc::target_list(&mut Verbosity::Quiet.into())?;
let args = cli::parse(&target_list)?;
let subcommand = args.subcommand;
let subcommand = args.subcommand.clone();
let mut msg_info = shell::MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?;
let status = match cross::run(args, target_list, &mut msg_info)? {
Some(status) => status,
Expand Down
10 changes: 6 additions & 4 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ use crate::errors::*;
use crate::extensions::CommandExt;
use crate::shell::{self, MessageInfo};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Subcommand {
Build,
Check,
Doc,
Other,
Run,
Rustdoc,
Rustc,
Test,
Bench,
Clippy,
Metadata,
List,
Clean,
Other(String),
}

impl Subcommand {
#[must_use]
pub fn needs_docker(self, is_remote: bool) -> bool {
match self {
Subcommand::Other | Subcommand::List => false,
Subcommand::Other(_) | Subcommand::List => false,
Subcommand::Clean if !is_remote => false,
_ => true,
}
Expand Down Expand Up @@ -58,12 +59,13 @@ impl<'a> From<&'a str> for Subcommand {
"doc" => Subcommand::Doc,
"r" | "run" => Subcommand::Run,
"rustc" => Subcommand::Rustc,
"rustdoc" => Subcommand::Rustdoc,
"t" | "test" => Subcommand::Test,
"bench" => Subcommand::Bench,
"clippy" => Subcommand::Clippy,
"metadata" => Subcommand::Metadata,
"--list" => Subcommand::List,
_ => Subcommand::Other,
command => Subcommand::Other(command.to_owned()),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn group_subcommands(stdout: &str) -> (Vec<&str>, Vec<&str>) {
let first = line.split_whitespace().next();
if let Some(command) = first {
match Subcommand::from(command) {
Subcommand::Other => host.push(line),
Subcommand::Other(_) => host.push(line),
_ => cross.push(line),
}
}
Expand All @@ -55,7 +55,7 @@ pub fn fmt_subcommands(stdout: &str, msg_info: &mut MessageInfo) -> Result<()> {
}
if !host.is_empty() {
msg_info.print("Host Commands:")?;
for line in &cross {
for line in &host {
msg_info.print(line)?;
}
}
Expand Down
29 changes: 25 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ pub fn run(
))?;
}

if let Some(Subcommand::Other(command)) = &args.subcommand {
msg_info.warn(format_args!(
"specified cargo subcommand `{command}` is not supported by `cross`."
))?;
return Ok(None);
}

let host_version_meta = rustc::version_meta()?;

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

let needs_docker = args
.subcommand
.clone()
.map_or(false, |sc| sc.needs_docker(is_remote));
if target.needs_docker() && needs_docker {
let paths = docker::DockerPaths::create(
Expand All @@ -623,8 +631,14 @@ pub fn run(
&options,
msg_info,
)?;
let status = docker::run(options, paths, &filtered_args, args.subcommand, msg_info)
.wrap_err("could not run container")?;
let status = docker::run(
options,
paths,
&filtered_args,
args.subcommand.clone(),
msg_info,
)
.wrap_err("could not run container")?;
let needs_host = args.subcommand.map_or(false, |sc| sc.needs_host(is_remote));
if !status.success() {
warn_on_failure(&target, &toolchain, msg_info)?;
Expand All @@ -646,7 +660,10 @@ pub fn install_interpreter_if_needed(
options: &docker::DockerOptions,
msg_info: &mut MessageInfo,
) -> Result<(), color_eyre::Report> {
let needs_interpreter = args.subcommand.map_or(false, |sc| sc.needs_interpreter());
let needs_interpreter = args
.subcommand
.clone()
.map_or(false, |sc| sc.needs_interpreter());

if host_version_meta.needs_interpreter()
&& needs_interpreter
Expand All @@ -670,6 +687,7 @@ pub fn get_filtered_args(
let add_libc = |triple: &str| add_libc_version(triple, zig_version.as_deref());
let mut filtered_args = if args
.subcommand
.clone()
.map_or(false, |s| !s.needs_target_in_command())
{
let mut filtered_args = Vec::new();
Expand Down Expand Up @@ -710,7 +728,10 @@ pub fn get_filtered_args(
args.cargo_args.clone()
};

let is_test = args.subcommand.map_or(false, |sc| sc == Subcommand::Test);
let is_test = args
.subcommand
.clone()
.map_or(false, |sc| sc == Subcommand::Test);
if is_test && config.doctests().unwrap_or_default() && is_nightly {
filtered_args.push("-Zdoctest-xcompile".to_owned());
}
Expand Down
1 change: 1 addition & 0 deletions src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ pub fn setup_components(
}
if args
.subcommand
.clone()
.map_or(false, |sc| sc == crate::Subcommand::Clippy)
&& !component_is_installed("clippy", toolchain, msg_info)?
{
Expand Down

0 comments on commit a537585

Please sign in to comment.