Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions prep/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]

### Added

* `--crates <main|aux|all>` option to the `clippy` command. ([#18] by [@xStrom])

### Changed

* `ci` `clippy` now uses `--crates all` by default and does two separate checks with `--crates main` and `--crates aux` in extended mode. ([#18] by [@xStrom])

## [0.1.0] - 2026-01-31

### Added
Expand All @@ -15,6 +23,7 @@
[#2]: https://github.com/Nevermore/prep/pull/2
[#3]: https://github.com/Nevermore/prep/pull/3
[#5]: https://github.com/Nevermore/prep/pull/5
[#18]: https://github.com/Nevermore/prep/pull/18

[Unreleased]: https://github.com/Nevermore/prep/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/Nevermore/prep/compare/v0.0.0...v0.1.0
15 changes: 12 additions & 3 deletions prep/src/cmd/ci.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2026 the Prep Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::cmd::{clippy, format};
use crate::cmd::{CargoTargets, clippy, format};

/// Runs CI verification.
///
/// Can be ran in `extended` mode for more thorough checks.
///
/// Set `fail_fast` to `false` to run the checks to the end regardless of failure.
pub fn run(_extended: bool, fail_fast: bool) -> anyhow::Result<()> {
pub fn run(extended: bool, fail_fast: bool) -> anyhow::Result<()> {
let mut errs: Vec<anyhow::Error> = Vec::new();
let mut step = |f: fn() -> anyhow::Result<()>| -> anyhow::Result<()> {
if let Err(e) = f() {
Expand All @@ -21,7 +21,16 @@ pub fn run(_extended: bool, fail_fast: bool) -> anyhow::Result<()> {
};

step(|| format::run(true))?;
step(|| clippy::run(true))?;

if extended {
// We need to avoid --all-targets because it will unify dev and regular dep features.
step(|| clippy::run(CargoTargets::Main, true))?;
step(|| clippy::run(CargoTargets::Auxiliary, true))?;
} else {
// Slightly faster due to shared build cache,
// but will miss unified feature bugs.
step(|| clippy::run(CargoTargets::All, true))?;
}

if errs.is_empty() {
Ok(())
Expand Down
10 changes: 6 additions & 4 deletions prep/src/cmd/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ use std::process::Command;

use anyhow::{Context, ensure};

use crate::cmd::CargoTargets;
use crate::ui;

/// Runs Clippy analysis.
/// Runs Clippy analysis on the given `targets`.
///
/// In `strict` mode warnings are treated as errors.
pub fn run(strict: bool) -> anyhow::Result<()> {
pub fn run(targets: CargoTargets, strict: bool) -> anyhow::Result<()> {
let mut cmd = Command::new("cargo");
let mut cmd = cmd
.arg("clippy")
.arg("--locked")
.arg("--workspace")
.arg("--all-features")
.arg("--locked");
.args(targets.as_args())
.arg("--all-features");
if strict {
cmd = cmd.args(["--", "-D", "warnings"]);
}
Expand Down
27 changes: 27 additions & 0 deletions prep/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
// Copyright 2026 the Prep Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use clap::ValueEnum;

pub mod ci;
pub mod clippy;
pub mod format;

/// Cargo targets.
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum CargoTargets {
/// All targets, i.e. `--lib --bins --examples --tests --benches`.
All,
/// Main targets are `--lib` and `--bins`.
Main,
/// Auxiliary targets are `--examples`, `--tests`, and `--benches`.
#[value(name = "aux")]
Auxiliary,
}

impl CargoTargets {
/// Returns the Cargo flag arguments corresponding to `self`.
pub fn as_args(&self) -> Vec<&str> {
match self {
Self::All => vec!["--all-targets"],
// --lib --bins would produce a Cargo error if there are no binary targets,
// but luckily providing no targets gives the same behavior without the error.
Self::Main => vec![],
Self::Auxiliary => vec!["--examples", "--tests", "--benches"],
}
}
}
6 changes: 5 additions & 1 deletion prep/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};

use ui::help;

use crate::cmd::CargoTargets;

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
Expand All @@ -28,6 +30,8 @@ enum Commands {
},
#[command(alias = "clp")]
Clippy {
#[arg(name = "crates", short, long, value_enum, default_value_t = CargoTargets::Main)]
targets: CargoTargets,
#[arg(short, long)]
strict: bool,
},
Expand All @@ -53,7 +57,7 @@ fn main() -> anyhow::Result<()> {
extended,
no_fail_fast,
} => cmd::ci::run(extended, !no_fail_fast),
Commands::Clippy { strict } => cmd::clippy::run(strict),
Commands::Clippy { targets, strict } => cmd::clippy::run(targets, strict),
Commands::Format { check } => cmd::format::run(check),
}
}
4 changes: 4 additions & 0 deletions prep/src/ui/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Analyze the Rust workspace with Clippy.
···· ······ {cb}prep clippy{cb:#} {bb}[options]{bb:#}

{gb}Options:{gb:#}
{cb}-c --crates <val> {cb:#}Target specified crates. Possible values:
···· ······{bb}main{bb:#} -> Binaries and the main library. (default)
···· ······{bb}aux{bb:#} -> Examples, tests, and benches.
···· ······{bb}all{bb:#} -> All of the above.
{cb}-s --strict {cb:#}Treat warnings as errors.
{cb}-h --help {cb:#}Print this help message.
"
Expand Down