Skip to content

Commit

Permalink
Make xtask-prepush configurably verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmooney committed Aug 28, 2024
1 parent 31feeca commit 1c4ff1d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ implementation details, consumed by Propolis components.
to the `propolis` library
- viona-api: API (ioctls & structs) for the illumos viona driver

## xtasks

Propolis uses the `cargo xtask` pattern in order to conveniently expose certain
tasks to developers.

- `clippy`: Run suite of clippy checks. This performs more than a simple
`cargo clippy`, since there are several combinations of feature flags which
must be checked.
- `fmt`: Check style according to `rustfmt`
- `license`: Check (crudely) that files bear appropriate license headers
- `phd`: Run the PHD test suite
- `style`: Perform miscellaneous style checks
- `prepush`: Preform pre-push checks (`clippy`, `fmt`, `license`, `style`) in a
manner which resembles (but does not exactly match) how they are run in CI.
Running tests (unit, integration, or phd) are not included and are left to
the user.

It is recommended that developers run the `prepush` test before pushing a
branch which will be subsequently checked by CI. Doing so currently requires
an x86\_64 UNIX/Linux machine.

## License

Unless otherwise noted, all components are licensed under the [Mozilla Public
Expand Down
10 changes: 7 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ enum Cmds {
/// (Crudely) Check for appropriate license headers
License,
/// Preform pre-push checks (clippy, license, fmt, etc)
Prepush,
Prepush {
/// Suppress non-essential output
#[arg(short, long)]
quiet: bool,
},
/// Run the PHD test suite
Phd {
#[clap(subcommand)]
Expand All @@ -61,8 +65,8 @@ fn main() -> Result<()> {
Ok(())
}
Cmds::Phd { cmd } => cmd.run(),
Cmds::Prepush => {
task_prepush::cmd_prepush()?;
Cmds::Prepush { quiet } => {
task_prepush::cmd_prepush(quiet)?;

println!("Pre-push checks pass");
Ok(())
Expand Down
27 changes: 15 additions & 12 deletions xtask/src/task_prepush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ use anyhow::{bail, Result};

use crate::{task_clippy, task_fmt, task_license, task_style};

pub(crate) fn cmd_prepush() -> Result<()> {
pub(crate) fn cmd_prepush(quiet: bool) -> Result<()> {
let mut errs = Vec::new();
if task_clippy::cmd_clippy(true, true).is_err() {
errs.push("clippy");
}
if task_fmt::cmd_fmt().is_err() {
errs.push("fmt");
}
if task_license::cmd_license().is_err() {
errs.push("license");
}
if task_style::cmd_style().is_err() {
errs.push("style");
let checks: [(&str, &dyn Fn() -> bool); 4] = [
("clippy", &|| task_clippy::cmd_clippy(true, quiet).is_err()),
("fmt", &|| task_fmt::cmd_fmt().is_err()),
("license", &|| task_license::cmd_license().is_err()),
("style", &|| task_style::cmd_style().is_err()),
];

for (name, func) in checks {
if !quiet {
println!("Checking {name}...");
}
if func() {
errs.push(name);
}
}

if !errs.is_empty() {
Expand Down

0 comments on commit 1c4ff1d

Please sign in to comment.