From 57f41e1c72cf481fd47a3825edb12c6ef1d48978 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Wed, 25 Sep 2024 23:13:37 -0400 Subject: [PATCH] Use more flexible slices instead of &Vec<&str> --- Cargo.lock | 4 ++-- crates/tracel-xtask/src/commands/build.rs | 4 ++-- crates/tracel-xtask/src/commands/bump.rs | 2 +- crates/tracel-xtask/src/commands/check.rs | 12 ++++++------ crates/tracel-xtask/src/commands/compile.rs | 4 ++-- crates/tracel-xtask/src/commands/dependencies.rs | 4 ++-- crates/tracel-xtask/src/commands/doc.rs | 8 ++++---- crates/tracel-xtask/src/commands/fix.rs | 12 ++++++------ crates/tracel-xtask/src/commands/publish.rs | 2 +- crates/tracel-xtask/src/commands/test.rs | 9 +++++---- crates/tracel-xtask/src/commands/vulnerabilities.rs | 4 ++-- crates/tracel-xtask/src/utils/process.rs | 8 ++++---- crates/tracel-xtask/src/utils/rustup.rs | 4 ++-- 13 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58cab01..832739f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,7 +686,7 @@ dependencies = [ [[package]] name = "tracel-xtask" -version = "1.0.7" +version = "1.0.8" dependencies = [ "anyhow", "clap", @@ -704,7 +704,7 @@ dependencies = [ [[package]] name = "tracel-xtask-macros" -version = "1.0.7" +version = "1.0.8" dependencies = [ "proc-macro2", "quote", diff --git a/crates/tracel-xtask/src/commands/build.rs b/crates/tracel-xtask/src/commands/build.rs index c5d165b..8c2879d 100644 --- a/crates/tracel-xtask/src/commands/build.rs +++ b/crates/tracel-xtask/src/commands/build.rs @@ -32,7 +32,7 @@ pub(crate) fn run_build( group!("Build Workspace"); run_process_for_workspace( "cargo", - vec!["build", "--workspace", "--color", "always"], + &["build", "--workspace", "--color", "always"], excluded, None, None, @@ -54,7 +54,7 @@ pub(crate) fn run_build( run_process_for_package( "cargo", &member.name, - &vec!["build", "-p", &member.name, "--color", "always"], + &["build", "-p", &member.name, "--color", "always"], excluded, only, &format!("Build command failed for {}", &member.name), diff --git a/crates/tracel-xtask/src/commands/bump.rs b/crates/tracel-xtask/src/commands/bump.rs index ca78546..37b58ad 100644 --- a/crates/tracel-xtask/src/commands/bump.rs +++ b/crates/tracel-xtask/src/commands/bump.rs @@ -17,7 +17,7 @@ fn bump(command: &BumpSubCommand) -> anyhow::Result<()> { ensure_cargo_crate_is_installed("cargo-edit", None, None, false)?; run_process( "cargo", - &vec!["set-version", "--bump", &command.to_string()], + &["set-version", "--bump", &command.to_string()], None, None, &format!("Error trying to bump {command} version"), diff --git a/crates/tracel-xtask/src/commands/check.rs b/crates/tracel-xtask/src/commands/check.rs index 6d4a0ba..26eb0ae 100644 --- a/crates/tracel-xtask/src/commands/check.rs +++ b/crates/tracel-xtask/src/commands/check.rs @@ -52,7 +52,7 @@ fn run_audit() -> anyhow::Result<()> { ensure_cargo_crate_is_installed("cargo-audit", Some("fix"), None, false)?; run_process( "cargo", - &vec!["audit", "-q", "--color", "always"], + &["audit", "-q", "--color", "always"], None, None, "Audit check execution failed", @@ -67,7 +67,7 @@ fn run_format(target: &Target, excluded: &[String], only: &[String]) -> anyhow:: group!("Format Workspace"); run_process_for_workspace( "cargo", - vec!["fmt", "--check"], + &["fmt", "--check"], &[], None, None, @@ -89,7 +89,7 @@ fn run_format(target: &Target, excluded: &[String], only: &[String]) -> anyhow:: run_process_for_package( "cargo", &member.name, - &vec!["fmt", "--check", "-p", &member.name], + &["fmt", "--check", "-p", &member.name], excluded, only, &format!("Format check execution failed for {}", &member.name), @@ -114,7 +114,7 @@ fn run_lint(target: &Target, excluded: &[String], only: &[String]) -> anyhow::Re group!("Lint Workspace"); run_process_for_workspace( "cargo", - vec![ + &[ "clippy", "--no-deps", "--color=always", @@ -143,7 +143,7 @@ fn run_lint(target: &Target, excluded: &[String], only: &[String]) -> anyhow::Re run_process_for_package( "cargo", &member.name, - &vec![ + &[ "clippy", "--no-deps", "--color=always", @@ -178,7 +178,7 @@ fn run_typos() -> anyhow::Result<()> { group!("Typos"); run_process( "typos", - &vec!["--diff", "--color", "always"], + &["--diff", "--color", "always"], None, None, "Typos check execution failed", diff --git a/crates/tracel-xtask/src/commands/compile.rs b/crates/tracel-xtask/src/commands/compile.rs index cedd19e..e0f06c5 100644 --- a/crates/tracel-xtask/src/commands/compile.rs +++ b/crates/tracel-xtask/src/commands/compile.rs @@ -32,7 +32,7 @@ pub(crate) fn run_compile( group!("Compile Workspace"); run_process_for_workspace( "cargo", - vec!["check", "--workspace"], + &["check", "--workspace"], excluded, None, None, @@ -54,7 +54,7 @@ pub(crate) fn run_compile( run_process_for_package( "cargo", &member.name, - &vec!["check", "-p", &member.name], + &["check", "-p", &member.name], excluded, only, &format!("Compilation failed for {}", &member.name), diff --git a/crates/tracel-xtask/src/commands/dependencies.rs b/crates/tracel-xtask/src/commands/dependencies.rs index 4cd0fde..42e81fc 100644 --- a/crates/tracel-xtask/src/commands/dependencies.rs +++ b/crates/tracel-xtask/src/commands/dependencies.rs @@ -26,7 +26,7 @@ fn run_cargo_deny() -> anyhow::Result<()> { group!("Cargo: run deny checks"); run_process( "cargo", - &vec!["deny", "check"], + &["deny", "check"], None, None, "Some dependencies don't meet the requirements!", @@ -42,7 +42,7 @@ fn run_cargo_machete() -> anyhow::Result<()> { group!("Cargo: run unused dependencies checks"); run_process( "cargo", - &vec!["machete"], + &["machete"], None, None, "Unused dependencies found!", diff --git a/crates/tracel-xtask/src/commands/doc.rs b/crates/tracel-xtask/src/commands/doc.rs index 63b0b55..627df86 100644 --- a/crates/tracel-xtask/src/commands/doc.rs +++ b/crates/tracel-xtask/src/commands/doc.rs @@ -35,7 +35,7 @@ fn run_documentation_build( group!("Build Workspace documentation"); run_process_for_workspace( "cargo", - vec!["doc", "--workspace", "--no-deps", "--color=always"], + &["doc", "--workspace", "--no-deps", "--color=always"], excluded, None, None, @@ -57,7 +57,7 @@ fn run_documentation_build( run_process_for_package( "cargo", &member.name, - &vec!["doc", "-p", &member.name, "--no-deps", "--color=always"], + &["doc", "-p", &member.name, "--no-deps", "--color=always"], excluded, only, &format!("Format check execution failed for {}", &member.name), @@ -86,7 +86,7 @@ pub(crate) fn run_documentation( group!("Workspace Documentation Tests"); run_process_for_workspace( "cargo", - vec!["test", "--workspace", "--doc", "--color", "always"], + &["test", "--workspace", "--doc", "--color", "always"], excluded, Some(r"Doc-tests (\w+)"), Some("Doc Tests"), @@ -125,7 +125,7 @@ fn run_doc_test( run_process_for_package( "cargo", &member.name, - &vec!["test", "--doc", "-p", &member.name], + &["test", "--doc", "-p", &member.name], excluded, only, &format!( diff --git a/crates/tracel-xtask/src/commands/fix.rs b/crates/tracel-xtask/src/commands/fix.rs index ec0ac1f..6b3497c 100644 --- a/crates/tracel-xtask/src/commands/fix.rs +++ b/crates/tracel-xtask/src/commands/fix.rs @@ -57,7 +57,7 @@ pub(crate) fn run_audit() -> anyhow::Result<()> { group!("Audit Rust Dependencies"); run_process( "cargo", - &vec!["audit", "-q", "--color", "always", "fix"], + &["audit", "-q", "--color", "always", "fix"], None, None, "Audit check execution failed", @@ -72,7 +72,7 @@ fn run_format(target: &Target, excluded: &Vec, only: &Vec) -> Re group!("Format Workspace"); run_process_for_workspace( "cargo", - vec!["fmt"], + &["fmt"], &[], None, None, @@ -93,7 +93,7 @@ fn run_format(target: &Target, excluded: &Vec, only: &Vec) -> Re run_process_for_package( "cargo", &member.name, - &vec!["fmt", "-p", &member.name], + &["fmt", "-p", &member.name], excluded, only, &format!("Format check execution failed for {}", &member.name), @@ -118,7 +118,7 @@ fn run_lint(target: &Target, excluded: &Vec, only: &Vec) -> anyh group!("Lint Workspace"); run_process_for_workspace( "cargo", - vec![ + &[ "clippy", "--no-deps", "--fix", @@ -149,7 +149,7 @@ fn run_lint(target: &Target, excluded: &Vec, only: &Vec) -> anyh run_process_for_package( "cargo", &member.name, - &vec![ + &[ "clippy", "--no-deps", "--fix", @@ -185,7 +185,7 @@ pub(crate) fn run_typos() -> anyhow::Result<()> { group!("Typos"); run_process( "typos", - &vec!["--write-changes", "--color", "always"], + &["--write-changes", "--color", "always"], None, None, "Some typos have been found and cannot be fixed.", diff --git a/crates/tracel-xtask/src/commands/publish.rs b/crates/tracel-xtask/src/commands/publish.rs index 2fd7f2f..2dbc90e 100644 --- a/crates/tracel-xtask/src/commands/publish.rs +++ b/crates/tracel-xtask/src/commands/publish.rs @@ -86,7 +86,7 @@ fn publish(crate_name: String) -> anyhow::Result<()> { // Perform dry-run to ensure everything is good for publishing run_process( "cargo", - &vec!["publish", "-p", &crate_name, "--dry-run"], + &["publish", "-p", &crate_name, "--dry-run"], None, None, &format!("Publish dry run failed for crate '{}'.", &crate_name), diff --git a/crates/tracel-xtask/src/commands/test.rs b/crates/tracel-xtask/src/commands/test.rs index 83edab7..0177410 100644 --- a/crates/tracel-xtask/src/commands/test.rs +++ b/crates/tracel-xtask/src/commands/test.rs @@ -66,9 +66,10 @@ pub fn run_unit(target: &Target, args: &TestCmdArgs) -> Result<()> { .map(|s| s.to_string()) .collect::>(); push_optional_args(&mut cmd_args, args); + // let cmd_args: Vec<&str> = cmd_args.iter().map(String::as_str).collect(); run_process_for_workspace( "cargo", - cmd_args.iter().map(String::as_str).collect(), + &cmd_args.iter().map(String::as_str).collect::>(), &args.exclude, Some(r".*target/[^/]+/deps/([^-\s]+)"), Some("Unit Tests"), @@ -115,7 +116,7 @@ fn run_unit_test(member: &WorkspaceMember, args: &TestCmdArgs) -> Result<(), any run_process_for_package( "cargo", &member.name, - &cmd_args.iter().map(String::as_str).collect(), + &cmd_args.iter().map(String::as_str).collect::>(), &args.exclude, &args.only, &format!("Failed to execute unit test for '{}'", &member.name), @@ -140,7 +141,7 @@ pub fn run_integration(target: &Target, args: &TestCmdArgs) -> anyhow::Result<() push_optional_args(&mut cmd_args, args); run_process_for_workspace( "cargo", - cmd_args.iter().map(String::as_str).collect(), + &cmd_args.iter().map(String::as_str).collect::>(), &args.exclude, Some(r".*target/[^/]+/deps/([^-\s]+)"), Some("Integration Tests"), @@ -187,7 +188,7 @@ fn run_integration_test(member: &WorkspaceMember, args: &TestCmdArgs) -> Result< run_process_for_package( "cargo", &member.name, - &cmd_args.iter().map(String::as_str).collect(), + &cmd_args.iter().map(String::as_str).collect::>(), &args.exclude, &args.only, &format!("Failed to execute integration test for '{}'", &member.name), diff --git a/crates/tracel-xtask/src/commands/vulnerabilities.rs b/crates/tracel-xtask/src/commands/vulnerabilities.rs index 306518c..3638ca8 100644 --- a/crates/tracel-xtask/src/commands/vulnerabilities.rs +++ b/crates/tracel-xtask/src/commands/vulnerabilities.rs @@ -57,7 +57,7 @@ fn run_cargo_careful() -> anyhow::Result<()> { group!("Cargo: careful setup"); run_process( "cargo", - &vec!["careful", "setup"], + &["careful", "setup"], None, None, "Error preparing cargo sysroot.", @@ -67,7 +67,7 @@ fn run_cargo_careful() -> anyhow::Result<()> { group!("Cargo: run careful checks"); run_process( "cargo", - &vec!["careful", "test"], + &["careful", "test"], None, None, "Cargo careful test has errors.", diff --git a/crates/tracel-xtask/src/utils/process.rs b/crates/tracel-xtask/src/utils/process.rs index b2af260..d063bb9 100644 --- a/crates/tracel-xtask/src/utils/process.rs +++ b/crates/tracel-xtask/src/utils/process.rs @@ -17,7 +17,7 @@ use crate::{endgroup, group}; /// Run a process pub fn run_process( name: &str, - args: &Vec<&str>, + args: &[&str], envs: Option>, path: Option<&Path>, error_msg: &str, @@ -50,7 +50,7 @@ pub fn run_process( #[allow(clippy::too_many_arguments)] pub fn run_process_for_workspace<'a>( name: &str, - args: Vec<&'a str>, + args: &[&'a str], excluded: &'a [String], group_regexp: Option<&str>, group_name: Option<&str>, @@ -61,7 +61,7 @@ pub fn run_process_for_workspace<'a>( let group_rx: Option = group_regexp.map(|r| Regex::new(r).unwrap()); // split the args between cargo args and binary args so that we can extend the cargo args // and then append the binary args back. - let (cargo_args, binary_args) = split_vector(&args, "--"); + let (cargo_args, binary_args) = split_vector(args, "--"); let mut cmd_args = cargo_args.to_owned(); excluded .iter() @@ -160,7 +160,7 @@ pub fn run_process_for_workspace<'a>( pub fn run_process_for_package( name: &str, package: &String, - args: &Vec<&str>, + args: &[&str], excluded: &[String], only: &[String], error_msg: &str, diff --git a/crates/tracel-xtask/src/utils/rustup.rs b/crates/tracel-xtask/src/utils/rustup.rs index 5db27f1..a580b2b 100644 --- a/crates/tracel-xtask/src/utils/rustup.rs +++ b/crates/tracel-xtask/src/utils/rustup.rs @@ -7,7 +7,7 @@ pub fn rustup_add_target(target: &str) -> anyhow::Result<()> { group!("Rustup: add target {}", target); run_process( "rustup", - &vec!["target", "add", target], + &["target", "add", target], None, None, &format!("Failed to add target {target}"), @@ -21,7 +21,7 @@ pub fn rustup_add_component(component: &str) -> anyhow::Result<()> { group!("Rustup: add component {}", component); run_process( "rustup", - &vec!["component", "add", component], + &["component", "add", component], None, None, &format!("Failed to add component {component}"),