Skip to content

Commit

Permalink
Auto merge of #1337 - nrc:ui-missing-tool, r=alexcrichton
Browse files Browse the repository at this point in the history
Warn when tools are missing and allow to override

Closes #1277

Idea here is to not update if the RLS is missing (for example). There was actually functionality to do this already, but it was not catching the RLS and Rustfmt since they were missing in an unexpected way.

The second commit adds `rustup update --force` to update even if some components are missing

r? @alexcrichton
  • Loading branch information
bors committed Jan 15, 2018
2 parents 38e1d3a + dcf0f9d commit 22f1569
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 190 deletions.
4 changes: 2 additions & 2 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ fn show_channel_updates(cfg: &Cfg, toolchains: Vec<(String, rustup::Result<Updat
Ok(())
}

pub fn update_all_channels(cfg: &Cfg, self_update: bool) -> Result<()> {
pub fn update_all_channels(cfg: &Cfg, self_update: bool, force_update: bool) -> Result<()> {

let toolchains = try!(cfg.update_all_channels());
let toolchains = try!(cfg.update_all_channels(force_update));

if toolchains.is_empty() {
info!("no updatable toolchains installed");
Expand Down
14 changes: 11 additions & 3 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ pub fn cli() -> App<'static, 'static> {
.help("Don't perform self update when running the `rustup` command")
.long("no-self-update")
.takes_value(false)
.hidden(true)))
.hidden(true))
.arg(Arg::with_name("force")
.help("Force an update, even if some components are missing")
.long("force")
.takes_value(false)))
.subcommand(SubCommand::with_name("default")
.about("Set the default toolchain")
.after_help(DEFAULT_HELP)
Expand Down Expand Up @@ -462,7 +466,7 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
let toolchain = try!(cfg.get_toolchain(name, false));

let status = if !toolchain.is_custom() {
Some(try!(toolchain.install_from_dist()))
Some(try!(toolchain.install_from_dist(m.is_present("force"))))
} else if !toolchain.exists() {
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
} else {
Expand All @@ -475,7 +479,11 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
}
}
} else {
try!(common::update_all_channels(cfg, !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE));
try!(common::update_all_channels(
cfg,
!m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE,
m.is_present("force"),
));
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ fn maybe_install_rust(toolchain_str: &str, default_host_triple: &str, verbose: b
// Set host triple first as it will affect resolution of toolchain_str
try!(cfg.set_default_host_triple(default_host_triple));
let toolchain = try!(cfg.get_toolchain(toolchain_str, false));
let status = try!(toolchain.install_from_dist());
let status = try!(toolchain.install_from_dist(false));
try!(cfg.set_default(toolchain_str));
println!("");
try!(common::show_channel_update(cfg, toolchain_str, Ok(status)));
Expand Down
20 changes: 12 additions & 8 deletions src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
toolchain: &ToolchainDesc,
prefix: &InstallPrefix,
add: &[Component],
remove: &[Component])
remove: &[Component],
force_update: bool)
-> Result<Option<String>> {

let fresh_install = !prefix.path().exists();
Expand All @@ -472,7 +473,8 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
toolchain,
prefix,
add,
remove);
remove,
force_update);

// Don't leave behind an empty / broken installation directory
if res.is_err() && fresh_install {
Expand All @@ -485,12 +487,13 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
}

pub fn update_from_dist_<'a>(download: DownloadCfg<'a>,
update_hash: Option<&Path>,
toolchain: &ToolchainDesc,
prefix: &InstallPrefix,
add: &[Component],
remove: &[Component])
-> Result<Option<String>> {
update_hash: Option<&Path>,
toolchain: &ToolchainDesc,
prefix: &InstallPrefix,
add: &[Component],
remove: &[Component],
force_update: bool)
-> Result<Option<String>> {

let toolchain_str = toolchain.to_string();
let manifestation = try!(Manifestation::open(prefix.clone(), toolchain.target.clone()));
Expand All @@ -507,6 +510,7 @@ pub fn update_from_dist_<'a>(download: DownloadCfg<'a>,
(download.notify_handler)(Notification::DownloadedManifest(&m.date, m.get_rust_version().ok()));
return match try!(manifestation.update(&m,
changes,
force_update,
&download,
download.notify_handler.clone())) {
UpdateStatus::Unchanged => Ok(None),
Expand Down

0 comments on commit 22f1569

Please sign in to comment.