Skip to content

Commit

Permalink
Try #246:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Jan 6, 2019
2 parents 72606e9 + 902b2e8 commit e950f67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{env, fs};
use errors::*;
use extensions::CommandExt;

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Subcommand {
Build,
Check,
Expand All @@ -15,6 +15,7 @@ pub enum Subcommand {
Test,
Bench,
Deb,
Clippy,
}

impl Subcommand {
Expand Down Expand Up @@ -43,6 +44,7 @@ impl<'a> From<&'a str> for Subcommand {
"test" => Subcommand::Test,
"bench" => Subcommand::Bench,
"deb" => Subcommand::Deb,
"clippy" => Subcommand::Clippy,
_ => Subcommand::Other,
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{env, io, process};

use toml::{Parser, Value};

use cargo::Root;
use cargo::{Root, Subcommand};
use errors::*;
use rustc::{TargetList, VersionMetaExt};

Expand Down Expand Up @@ -246,8 +246,14 @@ fn run() -> Result<ExitStatus> {

if !uses_xargo && !available_targets.is_installed(&target) {
rustup::install(&target, &toolchain, verbose)?;
} else if !rustup::rust_src_is_installed(verbose)? {
rustup::install_rust_src(verbose)?;
} else if !rustup::component_is_installed("rust-src", toolchain, verbose)? {
rustup::install_component("rust-src", toolchain, verbose)?;
}

if args.subcommand.map(|sc| sc == Subcommand::Clippy).unwrap_or(false) {
if !rustup::component_is_installed("clippy", toolchain, verbose)? {
rustup::install_component("clippy", toolchain, verbose)?;
}
}

let needs_interpreter = args.subcommand.map(|sc| sc.needs_interpreter()).unwrap_or(false);
Expand Down
12 changes: 6 additions & 6 deletions src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ pub fn install(target: &Target, toolchain: &str, verbose: bool) -> Result<()> {
.chain_err(|| format!("couldn't install `std` for {}", target))
}

pub fn install_rust_src(verbose: bool) -> Result<()> {
pub fn install_component(component: &str, toolchain: &str, verbose: bool) -> Result<()> {
Command::new("rustup")
.args(&["component", "add", "rust-src"])
.args(&["component", "add", component, "--toolchain", toolchain])
.run(verbose)
.chain_err(|| format!("couldn't install the `rust-src` component"))
.chain_err(|| format!("couldn't install the `{}` component", component))
}

pub fn rust_src_is_installed(verbose: bool) -> Result<bool> {
pub fn component_is_installed(component: &str, toolchain: &str, verbose: bool) -> Result<bool> {
Ok(Command::new("rustup")
.args(&["component", "list"])
.args(&["component", "list", "--toolchain", toolchain])
.run_and_get_stdout(verbose)?
.lines()
.any(|l| l.starts_with("rust-src") && l.contains("installed")))
.any(|l| l.starts_with(component) && l.contains("installed")))
}

0 comments on commit e950f67

Please sign in to comment.