From 801b223135320415537d3693ec3a513672d30e1e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Aug 2023 20:34:42 -0500 Subject: [PATCH 1/7] test(cli): Show existing --target behavior --- tests/testsuite/list_availables.rs | 39 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/testsuite/list_availables.rs b/tests/testsuite/list_availables.rs index 6bbbeb160d5..a4a702c3f37 100644 --- a/tests/testsuite/list_availables.rs +++ b/tests/testsuite/list_availables.rs @@ -8,6 +8,7 @@ const BIN: u8 = 1 << 1; const TEST: u8 = 1 << 2; const BENCH: u8 = 1 << 3; const PACKAGE: u8 = 1 << 4; +const TARGET: u8 = 1 << 5; fn list_availables_test(command: &str, targets: u8) { let full_project = project() @@ -159,56 +160,70 @@ No tests available. .with_status(101) .run(); } + + if targets & TARGET != 0 { + empty_project + .cargo(&format!("{} --target", command)) + .with_stderr( + "\ +error: a value is required for '--target ' but none was supplied + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); + } } #[cargo_test] fn build_list_availables() { - list_availables_test("build", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("build", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] fn check_list_availables() { - list_availables_test("check", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("check", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] fn doc_list_availables() { - list_availables_test("doc", BIN | PACKAGE); + list_availables_test("doc", BIN | PACKAGE | TARGET); } #[cargo_test] fn fix_list_availables() { - list_availables_test("fix", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("fix", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] fn run_list_availables() { - list_availables_test("run", EXAMPLE | BIN | PACKAGE); + list_availables_test("run", EXAMPLE | BIN | PACKAGE | TARGET); } #[cargo_test] fn test_list_availables() { - list_availables_test("test", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("test", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] fn bench_list_availables() { - list_availables_test("bench", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("bench", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] fn install_list_availables() { - list_availables_test("install", EXAMPLE | BIN); + list_availables_test("install", EXAMPLE | BIN | TARGET); } #[cargo_test] fn rustdoc_list_availables() { - list_availables_test("rustdoc", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("rustdoc", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] fn rustc_list_availables() { - list_availables_test("rustc", EXAMPLE | BIN | TEST | BENCH | PACKAGE); + list_availables_test("rustc", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET); } #[cargo_test] @@ -218,12 +233,12 @@ fn pkgid_list_availables() { #[cargo_test] fn tree_list_availables() { - list_availables_test("tree", PACKAGE); + list_availables_test("tree", PACKAGE | TARGET); } #[cargo_test] fn clean_list_availables() { - list_availables_test("clean", PACKAGE); + list_availables_test("clean", PACKAGE | TARGET); } #[cargo_test] From 92e252bad83a2ee5aa54dd43356da9ad603a2633 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Aug 2023 20:36:24 -0500 Subject: [PATCH 2/7] refactor(cli): Allow --targets to fail --- src/bin/cargo/commands/clean.rs | 2 +- src/bin/cargo/commands/fetch.rs | 2 +- src/bin/cargo/commands/package.rs | 2 +- src/bin/cargo/commands/publish.rs | 2 +- src/cargo/util/command_prelude.rs | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index 9fa3c852700..c47e1670203 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -27,7 +27,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let opts = CleanOptions { config, spec: values(args, "package"), - targets: args.targets(), + targets: args.targets()?, requested_profile: args.get_profile_name(config, "dev", ProfileChecking::Custom)?, profile_specified: args.contains_id("profile") || args.flag("release"), doc: args.flag("doc"), diff --git a/src/bin/cargo/commands/fetch.rs b/src/bin/cargo/commands/fetch.rs index 4b1fcb40f25..ba9e8d82b9e 100644 --- a/src/bin/cargo/commands/fetch.rs +++ b/src/bin/cargo/commands/fetch.rs @@ -17,7 +17,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let opts = FetchOptions { config, - targets: args.targets(), + targets: args.targets()?, }; let _ = ops::fetch(&ws, &opts)?; Ok(()) diff --git a/src/bin/cargo/commands/package.rs b/src/bin/cargo/commands/package.rs index e87fb3ef8a7..7fa993f1dd3 100644 --- a/src/bin/cargo/commands/package.rs +++ b/src/bin/cargo/commands/package.rs @@ -58,7 +58,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { check_metadata: !args.flag("no-metadata"), allow_dirty: args.flag("allow-dirty"), to_package: specs, - targets: args.targets(), + targets: args.targets()?, jobs: args.jobs()?, keep_going: args.keep_going(), cli_features: args.cli_features()?, diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs index f30633e3de4..8a9175f6cd8 100644 --- a/src/bin/cargo/commands/publish.rs +++ b/src/bin/cargo/commands/publish.rs @@ -50,7 +50,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { verify: !args.flag("no-verify"), allow_dirty: args.flag("allow-dirty"), to_publish: args.packages_from_flags()?, - targets: args.targets(), + targets: args.targets()?, jobs: args.jobs()?, keep_going: args.keep_going(), dry_run: args.dry_run(), diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 2186b9f2900..b697e29b6b9 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -440,8 +440,8 @@ pub trait ArgMatchesExt { self.maybe_flag("keep-going") } - fn targets(&self) -> Vec { - self._values_of("target") + fn targets(&self) -> CargoResult> { + Ok(self._values_of("target")) } fn get_profile_name( @@ -590,7 +590,7 @@ pub trait ArgMatchesExt { config, self.jobs()?, self.keep_going(), - &self.targets(), + &self.targets()?, mode, )?; build_config.message_format = message_format.unwrap_or(MessageFormat::Human); From ca173bc32d419e20c34ad62941962d2cf60e3b45 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Aug 2023 20:41:45 -0500 Subject: [PATCH 3/7] refactor(tree): Lookup --target like other commands --- src/bin/cargo/commands/tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cargo/commands/tree.rs b/src/bin/cargo/commands/tree.rs index 4472765a92d..4657eafff96 100644 --- a/src/bin/cargo/commands/tree.rs +++ b/src/bin/cargo/commands/tree.rs @@ -136,7 +136,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { .warn("the --all-targets flag has been changed to --target=all")?; vec!["all".to_string()] } else { - args._values_of("target") + args.targets()? }; let target = tree::Target::from_cli(targets); From b87c9323bb137bea2b78bb9d15261d76a0be01be Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Aug 2023 20:42:45 -0500 Subject: [PATCH 4/7] refactor(cli): Manually implement missing arg error for --target --- src/cargo/util/command_prelude.rs | 8 +++++++- tests/testsuite/cargo_bench/help/stdout.log | 2 +- tests/testsuite/cargo_build/help/stdout.log | 2 +- tests/testsuite/cargo_check/help/stdout.log | 2 +- tests/testsuite/cargo_clean/help/stdout.log | 2 +- tests/testsuite/cargo_doc/help/stdout.log | 2 +- tests/testsuite/cargo_fetch/help/stdout.log | 2 +- tests/testsuite/cargo_fix/help/stdout.log | 2 +- tests/testsuite/cargo_install/help/stdout.log | 2 +- tests/testsuite/cargo_package/help/stdout.log | 2 +- tests/testsuite/cargo_publish/help/stdout.log | 2 +- tests/testsuite/cargo_run/help/stdout.log | 2 +- tests/testsuite/cargo_rustc/help/stdout.log | 2 +- tests/testsuite/cargo_rustdoc/help/stdout.log | 2 +- tests/testsuite/cargo_test/help/stdout.log | 2 +- tests/testsuite/cargo_tree/help/stdout.log | 4 ++-- tests/testsuite/list_availables.rs | 6 ++---- 17 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index b697e29b6b9..6ed1b8ed862 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -218,7 +218,10 @@ pub trait CommandExt: Sized { } fn arg_target_triple(self, target: &'static str) -> Self { - self._arg(multi_opt("target", "TRIPLE", target).help_heading(heading::COMPILATION_OPTIONS)) + self._arg( + optional_multi_opt("target", "TRIPLE", target) + .help_heading(heading::COMPILATION_OPTIONS), + ) } fn arg_target_dir(self) -> Self { @@ -441,6 +444,9 @@ pub trait ArgMatchesExt { } fn targets(&self) -> CargoResult> { + if self.is_present_with_zero_values("target") { + bail!("\"--target\" takes an argument."); + } Ok(self._values_of("target")) } diff --git a/tests/testsuite/cargo_bench/help/stdout.log b/tests/testsuite/cargo_bench/help/stdout.log index 5d9484df9ee..430d8be426f 100644 --- a/tests/testsuite/cargo_bench/help/stdout.log +++ b/tests/testsuite/cargo_bench/help/stdout.log @@ -45,7 +45,7 @@ Feature Selection: Compilation Options: -j, --jobs Number of parallel jobs, defaults to # of CPUs. --profile Build artifacts with the specified profile - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_build/help/stdout.log b/tests/testsuite/cargo_build/help/stdout.log index e51a3b177dc..56b934cd168 100644 --- a/tests/testsuite/cargo_build/help/stdout.log +++ b/tests/testsuite/cargo_build/help/stdout.log @@ -42,7 +42,7 @@ Compilation Options: --profile Build artifacts with the specified profile -j, --jobs Number of parallel jobs, defaults to # of CPUs. --keep-going Do not abort the build as soon as there is an error - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --out-dir Copy final artifacts to this directory (unstable) --build-plan Output the build plan in JSON (unstable) diff --git a/tests/testsuite/cargo_check/help/stdout.log b/tests/testsuite/cargo_check/help/stdout.log index 8aee0bcce86..92d44a6ded2 100644 --- a/tests/testsuite/cargo_check/help/stdout.log +++ b/tests/testsuite/cargo_check/help/stdout.log @@ -42,7 +42,7 @@ Compilation Options: --keep-going Do not abort the build as soon as there is an error -r, --release Check artifacts in release mode, with optimizations --profile Check artifacts with the specified profile - --target Check for the target triple + --target [] Check for the target triple --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_clean/help/stdout.log b/tests/testsuite/cargo_clean/help/stdout.log index fd3c8855c50..2074d9633a3 100644 --- a/tests/testsuite/cargo_clean/help/stdout.log +++ b/tests/testsuite/cargo_clean/help/stdout.log @@ -17,7 +17,7 @@ Package Selection: Compilation Options: -r, --release Whether or not to clean release artifacts --profile Clean artifacts of the specified profile - --target Target triple to clean output for + --target [] Target triple to clean output for --target-dir Directory for all generated artifacts Manifest Options: diff --git a/tests/testsuite/cargo_doc/help/stdout.log b/tests/testsuite/cargo_doc/help/stdout.log index d910c960a35..8ff5f9b72a7 100644 --- a/tests/testsuite/cargo_doc/help/stdout.log +++ b/tests/testsuite/cargo_doc/help/stdout.log @@ -39,7 +39,7 @@ Compilation Options: --keep-going Do not abort the build as soon as there is an error -r, --release Build artifacts in release mode, with optimizations --profile Build artifacts with the specified profile - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_fetch/help/stdout.log b/tests/testsuite/cargo_fetch/help/stdout.log index b9bd6c35bb1..32f29f1b39a 100644 --- a/tests/testsuite/cargo_fetch/help/stdout.log +++ b/tests/testsuite/cargo_fetch/help/stdout.log @@ -11,7 +11,7 @@ Options: -h, --help Print help Compilation Options: - --target Fetch dependencies for the target triple + --target [] Fetch dependencies for the target triple Manifest Options: --manifest-path Path to Cargo.toml diff --git a/tests/testsuite/cargo_fix/help/stdout.log b/tests/testsuite/cargo_fix/help/stdout.log index cfd76a4ff07..dbbd11b7752 100644 --- a/tests/testsuite/cargo_fix/help/stdout.log +++ b/tests/testsuite/cargo_fix/help/stdout.log @@ -47,7 +47,7 @@ Compilation Options: --keep-going Do not abort the build as soon as there is an error -r, --release Fix artifacts in release mode, with optimizations --profile Build artifacts with the specified profile - --target Fix for the target triple + --target [] Fix for the target triple --target-dir Directory for all generated artifacts --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_install/help/stdout.log b/tests/testsuite/cargo_install/help/stdout.log index de23100f42e..2267c5f6b01 100644 --- a/tests/testsuite/cargo_install/help/stdout.log +++ b/tests/testsuite/cargo_install/help/stdout.log @@ -44,7 +44,7 @@ Compilation Options: -j, --jobs Number of parallel jobs, defaults to # of CPUs. --keep-going Do not abort the build as soon as there is an error --profile Install artifacts with the specified profile - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_package/help/stdout.log b/tests/testsuite/cargo_package/help/stdout.log index 568cc5796c8..5079c2a6fa3 100644 --- a/tests/testsuite/cargo_package/help/stdout.log +++ b/tests/testsuite/cargo_package/help/stdout.log @@ -25,7 +25,7 @@ Feature Selection: --no-default-features Do not activate the `default` feature Compilation Options: - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts -j, --jobs Number of parallel jobs, defaults to # of CPUs. --keep-going Do not abort the build as soon as there is an error diff --git a/tests/testsuite/cargo_publish/help/stdout.log b/tests/testsuite/cargo_publish/help/stdout.log index 7f37ee56c09..313b937f91a 100644 --- a/tests/testsuite/cargo_publish/help/stdout.log +++ b/tests/testsuite/cargo_publish/help/stdout.log @@ -27,7 +27,7 @@ Feature Selection: Compilation Options: -j, --jobs Number of parallel jobs, defaults to # of CPUs. --keep-going Do not abort the build as soon as there is an error - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts Manifest Options: diff --git a/tests/testsuite/cargo_run/help/stdout.log b/tests/testsuite/cargo_run/help/stdout.log index c8777eaef56..4b39f30b3cf 100644 --- a/tests/testsuite/cargo_run/help/stdout.log +++ b/tests/testsuite/cargo_run/help/stdout.log @@ -33,7 +33,7 @@ Compilation Options: --keep-going Do not abort the build as soon as there is an error -r, --release Build artifacts in release mode, with optimizations --profile Build artifacts with the specified profile - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_rustc/help/stdout.log b/tests/testsuite/cargo_rustc/help/stdout.log index d6394effeab..9d43841fe2e 100644 --- a/tests/testsuite/cargo_rustc/help/stdout.log +++ b/tests/testsuite/cargo_rustc/help/stdout.log @@ -44,7 +44,7 @@ Compilation Options: --keep-going Do not abort the build as soon as there is an error -r, --release Build artifacts in release mode, with optimizations --profile Build artifacts with the specified profile - --target Target triple which compiles will be for + --target [] Target triple which compiles will be for --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_rustdoc/help/stdout.log b/tests/testsuite/cargo_rustdoc/help/stdout.log index 93c3ba85199..706072f24de 100644 --- a/tests/testsuite/cargo_rustdoc/help/stdout.log +++ b/tests/testsuite/cargo_rustdoc/help/stdout.log @@ -42,7 +42,7 @@ Compilation Options: --keep-going Do not abort the build as soon as there is an error -r, --release Build artifacts in release mode, with optimizations --profile Build artifacts with the specified profile - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_test/help/stdout.log b/tests/testsuite/cargo_test/help/stdout.log index d693dc3c92d..5df62d6bb17 100644 --- a/tests/testsuite/cargo_test/help/stdout.log +++ b/tests/testsuite/cargo_test/help/stdout.log @@ -48,7 +48,7 @@ Compilation Options: -j, --jobs Number of parallel jobs, defaults to # of CPUs. -r, --release Build artifacts in release mode, with optimizations --profile Build artifacts with the specified profile - --target Build for the target triple + --target [] Build for the target triple --target-dir Directory for all generated artifacts --unit-graph Output build graph in JSON (unstable) --timings[=] Timing output formats (unstable) (comma separated): html, json diff --git a/tests/testsuite/cargo_tree/help/stdout.log b/tests/testsuite/cargo_tree/help/stdout.log index 268b6b2ada6..4170583a854 100644 --- a/tests/testsuite/cargo_tree/help/stdout.log +++ b/tests/testsuite/cargo_tree/help/stdout.log @@ -33,8 +33,8 @@ Feature Selection: --no-default-features Do not activate the `default` feature Compilation Options: - --target Filter dependencies matching the given target-triple (default host - platform). Pass `all` to include all targets. + --target [] Filter dependencies matching the given target-triple (default host + platform). Pass `all` to include all targets. Manifest Options: --manifest-path Path to Cargo.toml diff --git a/tests/testsuite/list_availables.rs b/tests/testsuite/list_availables.rs index a4a702c3f37..ec2f9bfabb3 100644 --- a/tests/testsuite/list_availables.rs +++ b/tests/testsuite/list_availables.rs @@ -166,12 +166,10 @@ No tests available. .cargo(&format!("{} --target", command)) .with_stderr( "\ -error: a value is required for '--target ' but none was supplied - -For more information, try '--help'. +error: \"--target\" takes an argument. ", ) - .with_status(1) + .with_status(101) .run(); } } From fe37a3672c9746825c4989c2297685fe3339a779 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 31 Aug 2023 08:50:00 -0500 Subject: [PATCH 5/7] refactor(cli): Pull out rustup check --- src/bin/cargo/cli.rs | 7 ++----- src/cargo/util/mod.rs | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index ce6112817ec..d39dce754e5 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -12,6 +12,7 @@ use std::fmt::Write; use super::commands; use super::list_commands; use crate::command_prelude::*; +use crate::util::is_rustup; use cargo::core::features::HIDDEN; pub fn main(config: &mut LazyConfig) -> CliResult { @@ -511,11 +512,7 @@ impl GlobalArgs { } pub fn cli() -> Command { - // ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise - // other tools may point to executables from incompatible distributions. - #[allow(clippy::disallowed_methods)] - let is_rustup = std::env::var_os("RUSTUP_HOME").is_some(); - let usage = if is_rustup { + let usage = if is_rustup() { "cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] -Zscript [ARGS]..." } else { "cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript [ARGS]..." diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index af7dd368781..2c3e5a80274 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -66,6 +66,13 @@ pub mod toml_mut; mod vcs; mod workspace; +pub fn is_rustup() -> bool { + // ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise + // other tools may point to executables from incompatible distributions. + #[allow(clippy::disallowed_methods)] + std::env::var_os("RUSTUP_HOME").is_some() +} + pub fn elapsed(duration: Duration) -> String { let secs = duration.as_secs(); From adea3d148e06dd1c4828e491884a818bbefd88a4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 31 Aug 2023 08:55:36 -0500 Subject: [PATCH 6/7] fix(cli): Help people find possible --target values --- src/cargo/util/command_prelude.rs | 12 +++++++++++- tests/testsuite/list_availables.rs | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 6ed1b8ed862..d93fde207a7 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -4,6 +4,7 @@ use crate::core::{Edition, Workspace}; use crate::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; use crate::util::important_paths::find_root_manifest_for_wd; use crate::util::interning::InternedString; +use crate::util::is_rustup; use crate::util::restricted_names::is_glob_pattern; use crate::util::toml::{StringOrVec, TomlProfile}; use crate::util::validate_package_name; @@ -445,7 +446,16 @@ pub trait ArgMatchesExt { fn targets(&self) -> CargoResult> { if self.is_present_with_zero_values("target") { - bail!("\"--target\" takes an argument."); + let cmd = if is_rustup() { + "rustup target list" + } else { + "rustc --print target-list" + }; + bail!( + "\"--target\" takes an argument. + +Run `{cmd}` to see possible targets." + ); } Ok(self._values_of("target")) } diff --git a/tests/testsuite/list_availables.rs b/tests/testsuite/list_availables.rs index ec2f9bfabb3..add90a7da8a 100644 --- a/tests/testsuite/list_availables.rs +++ b/tests/testsuite/list_availables.rs @@ -167,6 +167,8 @@ No tests available. .with_stderr( "\ error: \"--target\" takes an argument. + +Run `[..]` to see possible targets. ", ) .with_status(101) From 802cb380edd093a952049e30ec70316f66792d89 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 31 Aug 2023 08:56:16 -0500 Subject: [PATCH 7/7] fix(cli): Be more specific in what is needed --- src/cargo/util/command_prelude.rs | 2 +- tests/testsuite/list_availables.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index d93fde207a7..f55e44f2c68 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -452,7 +452,7 @@ pub trait ArgMatchesExt { "rustc --print target-list" }; bail!( - "\"--target\" takes an argument. + "\"--target\" takes a target architecture as an argument. Run `{cmd}` to see possible targets." ); diff --git a/tests/testsuite/list_availables.rs b/tests/testsuite/list_availables.rs index add90a7da8a..fe635a19bd5 100644 --- a/tests/testsuite/list_availables.rs +++ b/tests/testsuite/list_availables.rs @@ -166,7 +166,7 @@ No tests available. .cargo(&format!("{} --target", command)) .with_stderr( "\ -error: \"--target\" takes an argument. +error: \"--target\" takes a target architecture as an argument. Run `[..]` to see possible targets. ",