Skip to content

Commit

Permalink
add cargo xtask clippy (#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Jul 19, 2023
1 parent 1604e18 commit 09e9d8d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ rustdocflags = "--document-private-items"
rustflags = [
"-C", "link-arg=-Wl,-znocompstrtab"
]

# Set up `cargo xtask`.
[alias]
xtask = "run --package xtask -- "
3 changes: 1 addition & 2 deletions .github/buildomat/jobs/clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ banner prerequisites
ptime -m bash ./tools/install_builder_prerequisites.sh -y

banner clippy
# See the corresponding GitHub Actions job for more about these arguments.
ptime -m cargo clippy --all-targets -- --deny warnings --allow clippy::style
ptime -m cargo xtask clippy
7 changes: 1 addition & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ jobs:
- name: Install Pre-Requisites
run: ./tools/install_builder_prerequisites.sh -y
- name: Run Clippy Lints
#
# Clippy's style nits are useful, but not worth keeping in CI. This
# override belongs in src/lib.rs, and it is there, but that doesn't
# reliably work due to rust-lang/rust-clippy#6610.
#
run: cargo clippy --all-targets -- --deny warnings --allow clippy::style
run: cargo xtask clippy

# This is just a test build of docs. Publicly available docs are built via
# the separate "rustdocs" repo.
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,61 @@ members = [
"certificates",
"common",
"ddm-admin-client",
"dpd-client",
"deploy",
"dev-tools",
"dns-server",
"dns-service-client",
"dpd-client",
"end-to-end-tests",
"gateway",
"gateway-cli",
"gateway-client",
"gateway-test-utils",
"gateway",
"illumos-utils",
"installinator",
"installinator-artifact-client",
"installinator-artifactd",
"installinator-common",
"internal-dns",
"installinator",
"internal-dns-cli",
"internal-dns",
"ipcc-key-value",
"key-manager",
"nexus",
"nexus-client",
"nexus",
"nexus/authz-macros",
"nexus/db-macros",
"nexus/db-model",
"nexus/db-queries",
"nexus/defaults",
"nexus/test-interface",
"nexus/test-utils",
"nexus/test-utils-macros",
"nexus/test-utils",
"nexus/types",
"oxide-client",
"oximeter-client",
"oximeter/collector",
"oximeter/db",
"oximeter/instruments",
"oximeter/oximeter",
"oximeter/oximeter-macro-impl",
"oximeter/oximeter",
"oximeter/producer",
"package",
"passwords",
"rpaths",
"sled-agent",
"sled-agent-client",
"sled-agent",
"sled-hardware",
"sp-sim",
"test-utils",
"tufaceous",
"tufaceous-lib",
"tufaceous",
"update-engine",
"wicket",
"wicket-common",
"wicket-dbg",
"wicketd",
"wicket",
"wicketd-client",
"wicketd",
"xtask",
]

default-members = [
Expand Down Expand Up @@ -120,6 +121,7 @@ default-members = [
"wicket-dbg",
"wicketd",
"wicketd-client",
"xtask",
]
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ To build and run the non-simulated version of Omicron, see: xref:docs/how-to-run

You can **format the code** using `cargo fmt`. Make sure to run this before pushing changes. The CI checks that the code is correctly formatted.

You can **run the https://github.com/rust-lang/rust-clippy[Clippy linter]** using `cargo clippy --all-targets \-- --deny warnings --allow clippy::style`. Make sure to run this before pushing changes. The CI checks that the code is clippy-clean.
You can **run the https://github.com/rust-lang/rust-clippy[Clippy linter]** using `cargo xtask clippy`. CI checks that code is clippy-clean.

== Working in Omicron

Expand Down
8 changes: 8 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow.workspace = true
clap.workspace = true
72 changes: 72 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Workspace-related developer tools
//!
//! See <https://github.com/matklad/cargo-xtask>.
use anyhow::{bail, Context, Result};
use clap::{Parser, Subcommand};
use std::process::Command;

#[derive(Parser)]
#[command(name = "cargo xtask", about = "Workspace-related developer tools")]
struct Args {
#[command(subcommand)]
cmd: Cmds,
}

#[derive(Subcommand)]
enum Cmds {
/// Run configured clippy checks
Clippy,
}

fn main() -> Result<()> {
let args = Args::parse();
match args.cmd {
Cmds::Clippy => cmd_clippy(),
}
}

fn cmd_clippy() -> Result<()> {
let cargo =
std::env::var("CARGO").unwrap_or_else(|_| String::from("cargo"));
let mut command = Command::new(&cargo);
command
.arg("clippy")
// Make sure we check everything.
.arg("--all-targets")
.arg("--")
// We disallow warnings by default.
.arg("--deny")
.arg("warnings")
// Clippy's style nits are useful, but not worth keeping in CI. This
// override belongs in src/lib.rs, and it is there, but that doesn't
// reliably work due to rust-lang/rust-clippy#6610.
.arg("--allow")
.arg("clippy::style");

eprintln!(
"running: {:?} {}",
&cargo,
command
.get_args()
.map(|arg| format!("{:?}", arg.to_str().unwrap()))
.collect::<Vec<_>>()
.join(" ")
);

let exit_status = command
.spawn()
.context("failed to spawn child process")?
.wait()
.context("failed to wait for child process")?;

if !exit_status.success() {
bail!("clippy failed: {}", exit_status);
}

Ok(())
}

0 comments on commit 09e9d8d

Please sign in to comment.