sagiegurari / cargo-make
1
//! # toolchain
2
//!
3
//! Toolchain related utilify functions.
4
//!
5

6
#[cfg(test)]
7
#[path = "./toolchain_test.rs"]
8
mod toolchain_test;
9

10
use crate::types::CommandSpec;
11
use std::process::{Command, Stdio};
12

13
#[cfg(test)]
14 8
fn should_validate_installed_toolchain() -> bool {
15
    use crate::test;
16

17 8
    return test::is_not_rust_stable();
18 8
}
19

20
#[cfg(not(test))]
21 0
fn should_validate_installed_toolchain() -> bool {
22
    return true;
23 0
}
24

25 8
pub(crate) fn wrap_command(
26
    toolchain: &str,
27
    command: &str,
28
    args: &Option<Vec<String>>,
29
) -> CommandSpec {
30 8
    let validate = should_validate_installed_toolchain();
31

32 8
    if validate && !has_toolchain(toolchain) {
33 4
        error!(
34 0
            "Missing toolchain {}! Please install it using rustup.",
35 4
            &toolchain
36
        );
37
    }
38

39 8
    let mut rustup_args = vec![
40 8
        "run".to_string(),
41 8
        toolchain.to_string(),
42 8
        command.to_string(),
43
    ];
44

45 8
    match args {
46 8
        Some(array) => {
47 8
            for arg in array.iter() {
48 8
                rustup_args.push(arg.to_string());
49
            }
50
        }
51
        None => (),
52
    };
53

54 8
    CommandSpec {
55 8
        command: "rustup".to_string(),
56 8
        args: Some(rustup_args),
57
    }
58 8
}
59

60 4
fn has_toolchain(toolchain: &str) -> bool {
61 4
    Command::new("rustup")
62 4
        .args(&["run", toolchain, "rustc"])
63 4
        .stderr(Stdio::null())
64 4
        .stdout(Stdio::null())
65
        .status()
66
        .expect("Failed to check rustup toolchain")
67
        .success()
68 4
}

Read our documentation on viewing source code .

Loading