diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 1326f7cc42..0049072713 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -43,6 +43,7 @@ use std::fs::{self, File}; use std::io::Read; use tempdir::TempDir; use term2; +use regex::Regex; pub struct InstallOpts { pub default_host_triple: String, @@ -1125,13 +1126,41 @@ pub fn update() -> Result<()> { } let setup_path = try!(prepare_update()); if let Some(ref p) = setup_path { - info!("rustup updated successfully"); + let version = match get_new_rustup_version(&p) { + Some(new_version) => parse_new_rustup_version(new_version), + None => { + err!("failed to get rustup version"); + process::exit(1); + } + }; + + info!("rustup updated successfully to {}", version); try!(run_update(p)); } Ok(()) } +fn get_new_rustup_version(path: &Path) -> Option { + match Command::new(path).arg("--version").output() { + Err(_) => None, + Ok(output) => match String::from_utf8(output.stdout) { + Ok(version) => Some(version), + Err(_) => None + } + } +} + +fn parse_new_rustup_version(version: String) -> String { + let re = Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap(); + let capture = re.captures(&version); + let matched_version = match capture { + Some(cap) => cap.at(0).unwrap(), + None => "(unknown)" + }; + String::from(matched_version) +} + pub fn prepare_update() -> Result> { let ref cargo_home = try!(utils::cargo_home()); let ref rustup_path = cargo_home.join(&format!("bin/rustup{}", EXE_SUFFIX)); diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 855601fd45..cd715187e1 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -456,14 +456,17 @@ fn install_doesnt_modify_path_if_passed_no_modify_path() { #[test] fn update_exact() { - update_setup(&|config, _| { - expect_ok(config, &["rustup-init", "-y"]); - expect_ok_ex(config, &["rustup", "self", "update"], -r"", + let version = env!("CARGO_PKG_VERSION"); + let expected_output = &( r"info: checking for self-updates info: downloading self-update -info: rustup updated successfully +info: rustup updated successfully to ".to_owned() + version + " "); + + update_setup(&|config, _| { + expect_ok(config, &["rustup-init", "-y"]); + expect_ok_ex(config, &["rustup", "self", "update"], + r"", expected_output) }); }