From b5c7c915298dd87194bcddc91a6e6dc636c8057f Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Fri, 19 Jul 2024 14:46:11 +0100 Subject: [PATCH] Move style checks up to top-level fmt xtask. I'm in the CI weeds anyway, better make something that fails extraordinarily quickly. --- .github/buildomat/jobs/lint.sh | 17 +++++++++++++++++ .github/buildomat/jobs/opte-api.sh | 3 --- .github/buildomat/jobs/opte-ioctl.sh | 3 --- .github/buildomat/jobs/opte.sh | 3 --- .github/buildomat/jobs/opteadm.sh | 3 --- .github/buildomat/jobs/oxide-vpc.sh | 3 --- .github/buildomat/jobs/xde.sh | 3 --- xtask/src/main.rs | 21 +++++++++++++++------ 8 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 .github/buildomat/jobs/lint.sh diff --git a/.github/buildomat/jobs/lint.sh b/.github/buildomat/jobs/lint.sh new file mode 100644 index 00000000..b5c12454 --- /dev/null +++ b/.github/buildomat/jobs/lint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#: +#: name = "lint" +#: variety = "basic" +#: target = "helios-2.0" +#: rust_toolchain = "nightly-2024-05-12" +#: access_repos = [ +#: "oxidecomputer/illumos-rs", +#: ] +#: + +set -o errexit +set -o pipefail +set -o xtrace + +header "check style" +ptime -m cargo xtask fmt --check diff --git a/.github/buildomat/jobs/opte-api.sh b/.github/buildomat/jobs/opte-api.sh index c9f1625f..25885fd4 100755 --- a/.github/buildomat/jobs/opte-api.sh +++ b/.github/buildomat/jobs/opte-api.sh @@ -26,9 +26,6 @@ cd crates/opte-api header "check API_VERSION" ./check-api-version.sh -header "check style" -ptime -m cargo +nightly-2024-05-12 fmt -- --check - header "analyze std" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte-ioctl.sh b/.github/buildomat/jobs/opte-ioctl.sh index 238d627c..c90088c3 100755 --- a/.github/buildomat/jobs/opte-ioctl.sh +++ b/.github/buildomat/jobs/opte-ioctl.sh @@ -23,8 +23,5 @@ rustc --version cd lib/opte-ioctl -header "check style" -ptime -m cargo +nightly-2024-05-12 fmt -- --check - header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte.sh b/.github/buildomat/jobs/opte.sh index 3fe3d9fc..803fef4d 100755 --- a/.github/buildomat/jobs/opte.sh +++ b/.github/buildomat/jobs/opte.sh @@ -25,9 +25,6 @@ rustc --version cd lib/opte -header "check style" -ptime -m cargo +nightly-2024-05-12 fmt -- --check - header "check docs" # # I believe this means any doc warnings in deps will cause this to diff --git a/.github/buildomat/jobs/opteadm.sh b/.github/buildomat/jobs/opteadm.sh index bc6bb983..a40a14a9 100755 --- a/.github/buildomat/jobs/opteadm.sh +++ b/.github/buildomat/jobs/opteadm.sh @@ -28,9 +28,6 @@ rustc --version pushd bin/opteadm -header "check style" -ptime -m cargo +nightly-2024-05-12 fmt -- --check - header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/oxide-vpc.sh b/.github/buildomat/jobs/oxide-vpc.sh index 0d65a653..1a85ad8e 100755 --- a/.github/buildomat/jobs/oxide-vpc.sh +++ b/.github/buildomat/jobs/oxide-vpc.sh @@ -25,9 +25,6 @@ rustc --version cd lib/oxide-vpc -header "check style" -ptime -m cargo +nightly-2024-05-12 fmt -- --check - header "check docs" # # I believe this means any doc warnings in deps will cause this to diff --git a/.github/buildomat/jobs/xde.sh b/.github/buildomat/jobs/xde.sh index f6a7646b..028a6c6b 100755 --- a/.github/buildomat/jobs/xde.sh +++ b/.github/buildomat/jobs/xde.sh @@ -78,9 +78,6 @@ pushd xde cp xde.conf /work/xde.conf -header "check style" -ptime -m cargo +nightly-2024-05-12 fmt -p xde -p xde-link -- --check - header "analyze" ptime -m cargo clippy -- \ --allow clippy::uninlined-format-args --allow clippy::bad_bit_mask diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 46fca60f..d966593c 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -61,7 +61,11 @@ enum Xtask { }, /// Format the repository with `rustfmt`. - Fmt, + Fmt { + /// Run rustfmt in check mode. + #[arg(long)] + check: bool, + }, } #[derive(Debug, Args)] @@ -140,17 +144,22 @@ fn main() -> anyhow::Result<()> { Ok(()) } - Xtask::Fmt => { + Xtask::Fmt { check } => { let meta = cargo_meta(); // This is explicitly `cargo` rather than CARGO as we might // be swapping toolchains to do this from the current cargo. - Command::new("cargo") - .arg(format!("+{}", get_current_nightly_toolchain()?)) + let mut c = Command::new("cargo"); + c.arg(format!("+{}", get_current_nightly_toolchain()?)) .args(["fmt", "--all"]) .env_remove("RUSTUP_TOOLCHAIN") - .current_dir(&meta.workspace_root) - .output_nocapture()?; + .current_dir(&meta.workspace_root); + + if check { + c.arg("--check"); + } + + c.output_nocapture()?; Ok(()) }