Skip to content

Commit

Permalink
xtask: added extendrtests to the check-fmt.
Browse files Browse the repository at this point in the history
Added a `cargo extendr fmt` that formats `extendr`-crates
and `extendrtests`.
  • Loading branch information
CGMossa committed Feb 4, 2024
1 parent 388c125 commit a54c84b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions xtask/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
14 changes: 14 additions & 0 deletions xtask/src/commands/cargo_fmt.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
15 changes: 11 additions & 4 deletions xtask/src/commands/cargo_fmt_check.rs
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions xtask/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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,
Expand Down

0 comments on commit a54c84b

Please sign in to comment.