From 14858732330380e488ffb406d4a537bf133d90f9 Mon Sep 17 00:00:00 2001 From: Shunpoco Date: Sun, 25 Jan 2026 10:13:48 +0000 Subject: [PATCH] set long variants for required args Currently some required arguments (like path of the root dir) are ordered, but it causes an user (mainly bootstrap) needs to remember the order. This commit introduces long arguments (e.g., --root-path) for required args. --- src/bootstrap/src/core/build_steps/test.rs | 12 ++++++------ src/tools/tidy/src/arg_parser.rs | 14 ++++++++++++-- src/tools/tidy/src/arg_parser/tests.rs | 20 +++++++++++++------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 52b38421eec2..ca70a7758d58 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1293,19 +1293,19 @@ fn make_run(run: RunConfig<'_>) { /// for the `dev` or `nightly` channels. fn run(self, builder: &Builder<'_>) { let mut cmd = builder.tool_cmd(Tool::Tidy); - cmd.arg(&builder.src); - cmd.arg(&builder.initial_cargo); - cmd.arg(&builder.out); + cmd.arg(format!("--root-path={}", &builder.src.display())); + cmd.arg(format!("--cargo-path={}", &builder.initial_cargo.display())); + cmd.arg(format!("--output-dir={}", &builder.out.display())); // Tidy is heavily IO constrained. Still respect `-j`, but use a higher limit if `jobs` hasn't been configured. let jobs = builder.config.jobs.unwrap_or_else(|| { 8 * std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32 }); - cmd.arg(jobs.to_string()); + cmd.arg(format!("--concurrency={jobs}")); // pass the path to the yarn command used for installing js deps. if let Some(yarn) = &builder.config.yarn { - cmd.arg(yarn); + cmd.arg(format!("--npm-path={}", yarn.display())); } else { - cmd.arg("yarn"); + cmd.arg("--npm-path=yarn"); } if builder.is_verbose() { cmd.arg("--verbose"); diff --git a/src/tools/tidy/src/arg_parser.rs b/src/tools/tidy/src/arg_parser.rs index ca7ee04da8fb..8041f739308d 100644 --- a/src/tools/tidy/src/arg_parser.rs +++ b/src/tools/tidy/src/arg_parser.rs @@ -25,30 +25,40 @@ fn command() -> Command { .arg( Arg::new("root_path") .help("path of the root directory") + .long("root-path") .required(true) .value_parser(value_parser!(PathBuf)), ) .arg( Arg::new("cargo") .help("path of cargo") + .long("cargo-path") .required(true) .value_parser(value_parser!(PathBuf)), ) .arg( Arg::new("output_directory") .help("path of output directory") + .long("output-dir") .required(true) .value_parser(value_parser!(PathBuf)), ) - .arg(Arg::new("concurrency").required(true).value_parser(value_parser!(NonZeroUsize))) + .arg( + Arg::new("concurrency") + .help("number of threads working concurrently") + .long("concurrency") + .required(true) + .value_parser(value_parser!(NonZeroUsize)), + ) .arg( Arg::new("npm") .help("path of npm") + .long("npm-path") .required(true) .value_parser(value_parser!(PathBuf)), ) .arg(Arg::new("verbose").help("verbose").long("verbose").action(ArgAction::SetTrue)) - .arg(Arg::new("bless").help("bless").long("bless").action(ArgAction::SetTrue)) + .arg(Arg::new("bless").help("target files are modified").long("bless").action(ArgAction::SetTrue)) .arg( Arg::new("extra_checks") .help("extra checks") diff --git a/src/tools/tidy/src/arg_parser/tests.rs b/src/tools/tidy/src/arg_parser/tests.rs index 856e80279e27..c5e7aed21c1a 100644 --- a/src/tools/tidy/src/arg_parser/tests.rs +++ b/src/tools/tidy/src/arg_parser/tests.rs @@ -2,15 +2,21 @@ use crate::arg_parser::TidyArgParser; +// Test all arguments #[test] -fn test_tidy_parser() { +fn test_tidy_parser_full() { let args = vec![ "rust-tidy", - "/home/user/rust", // Root dir - "/home/user/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo", // Cardo location - "/home/user/rust/build", // Build dir - "16", // Number of concurrency - "/home/user/rust/build/misc-tools/bin/yarn", // Yarn location + "--root-path", + "/home/user/rust", + "--cargo-path", + "/home/user/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo", + "--output-dir", + "/home/user/rust/build", + "--concurrency", + "16", + "--npm-path", + "yarn", "--verbose", "--bless", "--extra-checks", @@ -29,7 +35,7 @@ fn test_tidy_parser() { ); assert_eq!(parsed_args.output_directory, PathBuf::from("/home/user/rust/build")); assert_eq!(parsed_args.concurrency.get(), 16); - assert_eq!(parsed_args.npm, PathBuf::from("/home/user/rust/build/misc-tools/bin/yarn")); + assert_eq!(parsed_args.npm, PathBuf::from("yarn")); assert!(parsed_args.verbose); assert!(parsed_args.bless); assert_eq!(