aboutsummaryrefslogtreecommitdiff
path: root/mingling_ci/src/task/cmd_clippy.rs
blob: 0a4282bd7076fc3b5aa3e20286dc85122d2833c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::ffi::OsString;
use std::path::Path;

use mingling::{
    Grouped, Routable,
    macros::{buffer, command, renderer},
    res::ResExitCode,
};

use crate::Next;
use crate::res::Manifests;
use crate::task::run::run_parallel_checks;

#[command(node = "clippy-all")]
pub async fn clippy_all(manifests: &Manifests) -> Next {
    let tasks = manifests
        .package_dirs
        .iter()
        .map(|(name, path)| (name.clone(), clippy_args(path)))
        .collect();
    let fail_count = run_parallel_checks("Clippy-All", "Clippy", tasks).await;
    ResultClippyAll { fail_count }.to_chain()
}

/// `cargo clippy --manifest-path <path> -- -D warnings`
fn clippy_args(path: &Path) -> Vec<OsString> {
    vec![
        "cargo".into(),
        "clippy".into(),
        "--manifest-path".into(),
        path.as_os_str().to_os_string(),
        "--".into(),
        "-D".into(),
        "warnings".into(),
    ]
}

/// Number of packages that failed clippy.
#[derive(Grouped)]
pub struct ResultClippyAll {
    pub fail_count: usize,
}

/// Silently sets a non-zero exit code when any clippy check failed.
#[renderer(buffer)]
pub fn render_clippy_all(r: ResultClippyAll, exit_code: &mut ResExitCode) {
    if r.fail_count > 0 {
        exit_code.exit_code = 1;
    }
}