From ab9e2186633be6525edfcecbd798b29ce6479dec Mon Sep 17 00:00:00 2001 From: cgmossa Date: Sun, 4 Feb 2024 21:54:26 +0100 Subject: [PATCH] xtask: added `extendrtests` to the `check-fmt`. Added a `cargo extendr fmt` that formats `extendr`-crates and `extendrtests`. --- xtask/src/cli/mod.rs | 2 ++ xtask/src/commands/cargo_fmt.rs | 14 ++++++++++++++ xtask/src/commands/cargo_fmt_check.rs | 15 +++++++++++---- xtask/src/commands/mod.rs | 1 + xtask/src/main.rs | 1 + 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 xtask/src/commands/cargo_fmt.rs diff --git a/xtask/src/cli/mod.rs b/xtask/src/cli/mod.rs index a074082b08..51fb9b2d65 100644 --- a/xtask/src/cli/mod.rs +++ b/xtask/src/cli/mod.rs @@ -15,6 +15,8 @@ pub(crate) struct Cli { pub(crate) enum Commands { #[command(about = "Run cargo fmt on extendr")] CheckFmt, + #[command(about = "Run `cargo fmt` on extendr crates")] + Fmt, #[command(about = "Run R CMD check on {extendrtests}")] RCmdCheck(RCmdCheckArg), #[command(about = "Generate documentation for all features")] diff --git a/xtask/src/commands/cargo_fmt.rs b/xtask/src/commands/cargo_fmt.rs new file mode 100644 index 0000000000..4a499a153a --- /dev/null +++ b/xtask/src/commands/cargo_fmt.rs @@ -0,0 +1,14 @@ +use xshell::{cmd, Error, Shell}; + +pub(crate) fn run(shell: &Shell) -> Result<(), Error> { + // extendr-api, extendr-macros, extendr-engine, xtask + cmd!(shell, "cargo fmt --all").run()?; + // extendrtests + cmd!( + shell, + "cargo fmt --all --manifest-path tests/extendrtests/src/rust/Cargo.toml" + ) + .run()?; + + Ok(()) +} diff --git a/xtask/src/commands/cargo_fmt_check.rs b/xtask/src/commands/cargo_fmt_check.rs index ca0df58fd6..ebcbd0714e 100644 --- a/xtask/src/commands/cargo_fmt_check.rs +++ b/xtask/src/commands/cargo_fmt_check.rs @@ -1,12 +1,19 @@ use xshell::{cmd, Error, Shell}; pub(crate) fn run(shell: &Shell) -> Result<(), Error> { - let check_result = cmd!(shell, "cargo fmt -- --check").run(); - if check_result.is_err() { - println!("Please run `cargo fmt --all`"); + let check_extendr = cmd!(shell, "cargo fmt --all -- --check").run(); + + let check_extendrtests = cmd!( + shell, + "cargo fmt --all --manifest-path tests/extendrtests/src/rust/Cargo.toml -- --check" + ) + .run(); + + if check_extendr.is_err() || check_extendrtests.is_err() { + println!("Please run `cargo extendr fmt`"); } else { println!("Success!"); } - check_result + check_extendr } diff --git a/xtask/src/commands/mod.rs b/xtask/src/commands/mod.rs index 1c20dbbe61..39c8cde597 100644 --- a/xtask/src/commands/mod.rs +++ b/xtask/src/commands/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod cargo_fmt; pub(crate) mod cargo_fmt_check; pub(crate) mod cargo_msrv; pub(crate) mod devtools_test; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a8a1462786..a2a830e593 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -21,6 +21,7 @@ fn main() -> Result<(), Box> { .canonicalize()?, ); match cli.command { + cli::Commands::Fmt => commands::cargo_fmt::run(&shell)?, cli::Commands::CheckFmt => commands::cargo_fmt_check::run(&shell)?, cli::Commands::RCmdCheck(RCmdCheckArg { no_build_vignettes,