Skip to content

Commit 4627f5a

Browse files
committed
Update all tracking toolchains on multirust update
Fixes #8
1 parent 239f6ae commit 4627f5a

File tree

9 files changed

+75
-36
lines changed

9 files changed

+75
-36
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ regex = "0.1.41"
2222
rand = "0.3.11"
2323
hyper = "0.6.14"
2424
term = "0.2.11"
25+
itertools = "0.4.1"
2526

2627
[target.x86_64-pc-windows-gnu.dependencies]
2728
winapi = "0.2.4"

rust-install/src/dist.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ impl ToolchainDesc {
103103
format!("{}-{} (tracking)", triple, &self.channel)
104104
}
105105
}
106+
107+
pub fn is_tracking(&self) -> bool {
108+
self.date.is_none()
109+
}
106110
}
107111

108112
pub struct Manifest<'a>(temp::File<'a>, String);

rust-install/src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum Notification<'a> {
3434
UpdateHashMatches(&'a str),
3535
CantReadUpdateHash(&'a Path),
3636
NoUpdateHash(&'a Path),
37+
NonFatalError(&'a Error),
3738
}
3839

3940
pub enum Error {
@@ -110,6 +111,8 @@ impl<'a> Notification<'a> {
110111
NotificationLevel::Info,
111112
NoCanonicalPath(_) | CantReadUpdateHash(_) =>
112113
NotificationLevel::Warn,
114+
NonFatalError(_) =>
115+
NotificationLevel::Error,
113116
}
114117
}
115118
}
@@ -163,6 +166,8 @@ impl<'a> Display for Notification<'a> {
163166
write!(f, "can't read update hash file: '{}', can't skip update...", path.display()),
164167
NoUpdateHash(path) =>
165168
write!(f, "no update hash at: '{}'", path.display()),
169+
NonFatalError(e) =>
170+
write!(f, "{}", e),
166171
}
167172
}
168173
}

rust-install/src/notify.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ pub enum NotificationLevel {
3030
Normal,
3131
Info,
3232
Warn,
33+
Error,
3334
}

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To remove an existing override use `multirust remove-override`."
5454
.after_help(
5555
r"With no toolchain specified, the update command updates each of the
5656
stable, beta, and nightly toolchains from the official release
57-
channels."
57+
channels, plus any other installed toolchains."
5858
)
5959
.arg(Arg::with_name("toolchain").required(false))
6060
.args(install_args())

src/config.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::fs;
66
use std::process::Command;
77
use std::fmt::{self, Display};
88

9+
use itertools::Itertools;
10+
911
use rust_install::*;
1012
use override_db::OverrideDB;
1113
use toolchain::Toolchain;
@@ -239,12 +241,19 @@ impl Cfg {
239241
}
240242
}
241243

242-
pub fn update_all_channels(&self) -> [Result<()>; 3] {
243-
let stable_result = self.get_toolchain("stable", true).and_then(|t| t.install_from_dist());
244-
let beta_result = self.get_toolchain("beta", true).and_then(|t| t.install_from_dist());
245-
let nightly_result = self.get_toolchain("nightly", true).and_then(|t| t.install_from_dist());
244+
pub fn update_all_channels(&self) -> Result<Vec<(String, Result<()>)>> {
245+
let mut toolchains = try!(self.list_toolchains());
246+
toolchains.sort();
246247

247-
[stable_result, beta_result, nightly_result]
248+
Ok(toolchains.into_iter()
249+
.merge(["beta", "nightly", "stable"].into_iter().map(|s| (*s).to_owned()))
250+
.dedup()
251+
.filter(|name| dist::ToolchainDesc::from_str(&name).map(|d| d.is_tracking()) == Some(true))
252+
.map(|name| {
253+
let result = self.get_toolchain(&name, true).and_then(|t| t.install_from_dist());
254+
(name, result)
255+
})
256+
.collect())
248257
}
249258

250259
pub fn check_metadata_version(&self) -> Result<bool> {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extern crate rust_install;
33
extern crate rand;
44
extern crate hyper;
55
extern crate regex;
6+
extern crate itertools;
67

78
pub use rust_install::*;
89
pub use config::*;

src/main.rs

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::process::{Command, Stdio};
2222
use std::process;
2323
use std::ffi::OsStr;
2424
use std::fmt;
25+
use std::iter;
2526
use multirust::*;
2627

2728
mod cli;
@@ -79,7 +80,10 @@ fn set_globals(m: Option<&ArgMatches>) -> Result<Cfg> {
7980
},
8081
NotificationLevel::Warn => {
8182
warn!("{}", n);
82-
}
83+
},
84+
NotificationLevel::Error => {
85+
err!("{}", n);
86+
},
8387
}
8488
}))
8589

@@ -497,18 +501,22 @@ fn show_tool_versions(toolchain: &Toolchain) -> Result<()> {
497501

498502
try!(toolchain.prefix().with_ldpath(|| {
499503
if utils::is_file(&rustc_path) {
500-
Command::new(&rustc_path)
501-
.arg("--version")
502-
.status()
503-
.ok().expect("failed to run rustc");
504+
let mut cmd = Command::new(&rustc_path);
505+
cmd.arg("--version");
506+
507+
if utils::cmd_status("rustc", cmd).is_err() {
508+
println!("(failed to run rustc)");
509+
}
504510
} else {
505511
println!("(no rustc command in toolchain?)");
506512
}
507513
if utils::is_file(&cargo_path) {
508-
Command::new(&cargo_path)
509-
.arg("--version")
510-
.status()
511-
.ok().expect("failed to run cargo");
514+
let mut cmd = Command::new(&cargo_path);
515+
cmd.arg("--version");
516+
517+
if utils::cmd_status("cargo", cmd).is_err() {
518+
println!("(failed to run cargo)");
519+
}
512520
} else {
513521
println!("(no cargo command in toolchain?)");
514522
}
@@ -577,30 +585,37 @@ fn list_toolchains(cfg: &Cfg) -> Result<()> {
577585
}
578586

579587
fn update_all_channels(cfg: &Cfg) -> Result<()> {
580-
let result = cfg.update_all_channels();
588+
let toolchains = try!(cfg.update_all_channels());
581589

582-
if result[0].is_ok() {
583-
println!("'stable' update succeeded");
584-
} else {
585-
println!("'stable' update FAILED");
586-
}
587-
if result[1].is_ok() {
588-
println!("'beta' update succeeded");
589-
} else {
590-
println!("'beta' update FAILED");
591-
}
592-
if result[2].is_ok() {
593-
println!("'nightly' update succeeded");
594-
} else {
595-
println!("'nightly' update FAILED");
590+
let max_name_length = toolchains.iter().map(|&(ref n,_)| n.len()).max().unwrap_or(0);
591+
let padding_str: String = iter::repeat(' ').take(max_name_length).collect();
592+
593+
println!("");
594+
let mut t = term::stdout().unwrap();
595+
for &(ref name, ref result) in &toolchains {
596+
let _ = t.fg(term::color::BRIGHT_WHITE);
597+
let _ = write!(t, "{}{}", &padding_str[0..(max_name_length-name.len())], name);
598+
let _ = t.fg(term::color::WHITE);
599+
let _ = write!(t, " update ");
600+
if result.is_ok() {
601+
let _ = t.fg(term::color::BRIGHT_GREEN);
602+
let _ = writeln!(t, "succeeded");
603+
let _ = t.fg(term::color::WHITE);
604+
} else {
605+
let _ = t.fg(term::color::BRIGHT_RED);
606+
let _ = writeln!(t, "FAILED");
607+
let _ = t.fg(term::color::WHITE);
608+
}
596609
}
610+
println!("");
597611

598-
println!("stable revision:");
599-
try!(show_tool_versions(&try!(cfg.get_toolchain("stable", false))));
600-
println!("beta revision:");
601-
try!(show_tool_versions(&try!(cfg.get_toolchain("beta", false))));
602-
println!("nightly revision:");
603-
try!(show_tool_versions(&try!(cfg.get_toolchain("nightly", false))));
612+
for (name, _) in toolchains {
613+
let _ = t.fg(term::color::BRIGHT_WHITE);
614+
let _ = write!(t, "{}", name);
615+
let _ = t.fg(term::color::WHITE);
616+
let _ = writeln!(t, " revision:");
617+
try!(show_tool_versions(&try!(cfg.get_toolchain(&name, false))));
618+
}
604619
Ok(())
605620
}
606621

src/toolchain.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ impl<'a> Toolchain<'a> {
105105
pub fn is_custom(&self) -> bool {
106106
dist::ToolchainDesc::from_str(&self.name).is_none()
107107
}
108+
pub fn is_tracking(&self) -> bool {
109+
dist::ToolchainDesc::from_str(&self.name).map(|d| d.is_tracking()) == Some(true)
110+
}
108111

109112
pub fn ensure_custom(&self) -> Result<()> {
110113
if !self.is_custom() {

0 commit comments

Comments
 (0)