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
#[cfg(test)]
#[path = "./crate_installer_test.rs"]
mod crate_installer_test;
use crate::command;
use crate::installer::{cargo_plugin_installer, rustup_component_installer};
use crate::toolchain::wrap_command;
use crate::types::{CommandSpec, InstallCrateInfo, InstallRustupComponentInfo};
fn invoke_rustup_install(toolchain: &Option<String>, info: &InstallCrateInfo) -> bool {
match info.rustup_component_name {
Some(ref component) => {
let rustup_component_info = InstallRustupComponentInfo {
rustup_component_name: component.to_string(),
binary: Some(info.binary.clone()),
test_arg: Some(info.test_arg.clone()),
};
rustup_component_installer::invoke_rustup_install(&toolchain, &rustup_component_info)
}
None => false,
}
}
fn invoke_cargo_install(
toolchain: &Option<String>,
info: &InstallCrateInfo,
args: &Option<Vec<String>>,
validate: bool,
) {
let install_args =
cargo_plugin_installer::get_install_crate_args(&info.crate_name, true, &args);
let command_spec = match toolchain {
Some(ref toolchain_string) => wrap_command(toolchain_string, "cargo", &Some(install_args)),
None => CommandSpec {
command: "cargo".to_string(),
args: Some(install_args),
},
};
command::run_command(&command_spec.command, &command_spec.args, validate);
}
pub(crate) fn install(
toolchain: &Option<String>,
info: &InstallCrateInfo,
args: &Option<Vec<String>>,
validate: bool,
) {
if !rustup_component_installer::is_installed(&toolchain, &info.binary, &info.test_arg) {
debug!("Crate: {} not installed.", &info.crate_name);
if !invoke_rustup_install(&toolchain, &info) {
invoke_cargo_install(&toolchain, &info, &args, validate);
}
}
}