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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::env;

use anyhow::Result;

use crate::{app, util::CargoToml};

const CARGO: &str = "cargo";
const BASE_ARGS: [&str; 5] = [
    "check",
    "--tests",
    "--bin",
    "vector",
    "--no-default-features",
];
const PARALLEL_ARGS: [&str; 7] = [
    "--group",
    "--verbose",
    "--retries",
    "2",
    "scripts/check-one-feature",
    "{}",
    ":::",
];

/// Check that all component features are set up properly
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {}

impl Cli {
    #[allow(clippy::dbg_macro)]
    pub fn exec(self) -> Result<()> {
        app::set_repo_dir()?;

        let features = extract_features()?;

        // Prime the pump to build most of the artifacts
        app::exec(CARGO, BASE_ARGS, true)?;
        app::exec(
            CARGO,
            BASE_ARGS.into_iter().chain(["--features", "default"]),
            true,
        )?;
        app::exec(
            CARGO,
            BASE_ARGS
                .into_iter()
                .chain(["--features", "all-integration-tests"]),
            true,
        )?;

        // The feature builds already run in parallel below, so don't overload the parallelism
        env::set_var("CARGO_BUILD_JOBS", "1");

        app::exec(
            "parallel",
            PARALLEL_ARGS
                .into_iter()
                .chain(features.iter().map(String::as_str)),
            true,
        )
    }
}

fn extract_features() -> Result<Vec<String>> {
    Ok(CargoToml::load()?
        .features
        .into_keys()
        .filter(|feature| {
            !feature.contains("-utils")
                && feature != "default"
                && feature != "all-integration-tests"
        })
        .collect())
}