diff --git a/src/download/src/lib.rs b/src/download/src/lib.rs index b8c0c75a04..9c99277a44 100644 --- a/src/download/src/lib.rs +++ b/src/download/src/lib.rs @@ -10,8 +10,8 @@ extern crate lazy_static; #[cfg(feature = "reqwest-backend")] extern crate reqwest; -use url::Url; use std::path::Path; +use url::Url; mod errors; pub use crate::errors::*; @@ -122,7 +122,7 @@ pub fn download_to_path_with_backend( Ok(()) }() - .map_err(|e| { + .map_err(|e| { // TODO is there any point clearing up here? What kind of errors will leave us with an unusable partial? e }) @@ -136,12 +136,12 @@ pub mod curl { extern crate curl; use self::curl::easy::Easy; + use super::Event; use crate::errors::*; use std::cell::RefCell; use std::str; use std::time::Duration; use url::Url; - use super::Event; pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> { // Fetch either a cached libcurl handle (which will preserve open @@ -254,12 +254,12 @@ pub mod curl { pub mod reqwest_be { extern crate env_proxy; + use super::Event; + use crate::errors::*; + use reqwest::{header, Client, Proxy, Response}; use std::io; use std::time::Duration; - use crate::errors::*; use url::Url; - use super::Event; - use reqwest::{header, Client, Proxy, Response}; pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> { // Short-circuit reqwest for the "file:" URL scheme @@ -339,7 +339,8 @@ pub mod reqwest_be { // The file scheme is mostly for use by tests to mock the dist server if url.scheme() == "file" { - let src = url.to_file_path() + let src = url + .to_file_path() .map_err(|_| Error::from(format!("bogus file url: '{}'", url)))?; if !src.is_file() { // Because some of rustup's logic depends on checking @@ -372,9 +373,9 @@ pub mod reqwest_be { #[cfg(not(feature = "curl-backend"))] pub mod curl { + use super::Event; use errors::*; use url::Url; - use super::Event; pub fn download( _url: &Url, @@ -388,9 +389,9 @@ pub mod curl { #[cfg(not(feature = "reqwest-backend"))] pub mod reqwest_be { + use super::Event; use errors::*; use url::Url; - use super::Event; pub fn download( _url: &Url, diff --git a/src/download/tests/download-curl-resume.rs b/src/download/tests/download-curl-resume.rs index 222ba4f8eb..a31b3c672f 100644 --- a/src/download/tests/download-curl-resume.rs +++ b/src/download/tests/download-curl-resume.rs @@ -59,14 +59,17 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { assert!(flag.is_none()); *flag = Some(len); } - Event::DownloadDataReceived(data) => for b in data.iter() { - received_in_callback.lock().unwrap().push(b.clone()); - }, + Event::DownloadDataReceived(data) => { + for b in data.iter() { + received_in_callback.lock().unwrap().push(b.clone()); + } + } } Ok(()) }), - ).expect("Test download failed"); + ) + .expect("Test download failed"); assert!(*callback_partial.lock().unwrap()); assert_eq!(*callback_len.lock().unwrap(), Some(5)); diff --git a/src/download/tests/download-reqwest-resume.rs b/src/download/tests/download-reqwest-resume.rs index bf66b436ed..6967b9c6b5 100644 --- a/src/download/tests/download-reqwest-resume.rs +++ b/src/download/tests/download-reqwest-resume.rs @@ -59,14 +59,17 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { assert!(flag.is_none()); *flag = Some(len); } - Event::DownloadDataReceived(data) => for b in data.iter() { - received_in_callback.lock().unwrap().push(b.clone()); - }, + Event::DownloadDataReceived(data) => { + for b in data.iter() { + received_in_callback.lock().unwrap().push(b.clone()); + } + } } Ok(()) }), - ).expect("Test download failed"); + ) + .expect("Test download failed"); assert!(*callback_partial.lock().unwrap()); assert_eq!(*callback_len.lock().unwrap(), Some(5)); diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index ab0fa8fdca..eb6f31777d 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -1,19 +1,19 @@ //! Just a dumping ground for cli stuff -use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus}; -use rustup::telemetry_analysis::TelemetryAnalysis; use crate::errors::*; -use rustup_utils::utils; -use rustup_utils::notify::NotificationLevel; use crate::self_update; +use crate::term2; +use rustup::telemetry_analysis::TelemetryAnalysis; +use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus}; +use rustup_utils::notify::NotificationLevel; +use rustup_utils::utils; +use std; use std::io::{BufRead, BufReader, Write}; -use std::process::{Command, Stdio}; use std::path::Path; -use std::{cmp, iter}; +use std::process::{Command, Stdio}; use std::sync::Arc; use std::time::Duration; -use std; -use crate::term2; +use std::{cmp, iter}; use wait_timeout::ChildExt; pub fn confirm(question: &str, default: bool) -> Result { @@ -178,7 +178,8 @@ fn show_channel_updates( let mut t = term2::stdout(); let data: Vec<_> = data.collect(); - let max_width = data.iter() + let max_width = data + .iter() .fold(0, |a, &(_, _, width, _, _)| cmp::max(a, width)); for (name, banner, width, color, version) in data { @@ -365,11 +366,8 @@ pub fn list_overrides(cfg: &Cfg) -> Result<()> { } println!( "{:<40}\t{:<20}", - utils::format_path_for_display(&k) + if dir_exists { - "" - } else { - " (not a directory)" - }, + utils::format_path_for_display(&k) + + if dir_exists { "" } else { " (not a directory)" }, v ) } diff --git a/src/rustup-cli/download_tracker.rs b/src/rustup-cli/download_tracker.rs index 6673d9c26f..370f98d304 100644 --- a/src/rustup-cli/download_tracker.rs +++ b/src/rustup-cli/download_tracker.rs @@ -1,11 +1,11 @@ +use rustup::Notification; +use rustup_dist::Notification as In; +use rustup_utils::tty; +use rustup_utils::Notification as Un; use std::collections::VecDeque; use std::fmt; use term; use time::precise_time_s; -use rustup::Notification; -use rustup_dist::Notification as In; -use rustup_utils::Notification as Un; -use rustup_utils::tty; /// Keep track of this many past download amounts const DOWNLOAD_TRACK_COUNT: usize = 5; @@ -123,7 +123,8 @@ impl DownloadTracker { /// Display the tracked download information to the terminal. fn display(&mut self) { let total_h = HumanReadable(self.total_downloaded as f64); - let sum = self.downloaded_last_few_secs + let sum = self + .downloaded_last_few_secs .iter() .fold(0., |a, &v| a + v as f64); let len = self.downloaded_last_few_secs.len(); diff --git a/src/rustup-cli/job.rs b/src/rustup-cli/job.rs index 5ee96ad63e..b47c582e91 100644 --- a/src/rustup-cli/job.rs +++ b/src/rustup-cli/job.rs @@ -44,8 +44,8 @@ mod imp { use self::winapi::um::handleapi::*; use self::winapi::um::jobapi2::*; use self::winapi::um::processthreadsapi::*; - use self::winapi::um::winnt::*; use self::winapi::um::winnt::HANDLE; + use self::winapi::um::winnt::*; pub struct Setup { job: Handle, diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index 03a1a1f12f..ad2fb7b1cd 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -46,21 +46,21 @@ extern crate winreg; mod log; mod common; mod download_tracker; +mod errors; +mod help; +mod job; mod proxy_mode; -mod setup_mode; mod rustup_mode; mod self_update; -mod job; +mod setup_mode; mod term2; -mod errors; -mod help; +use crate::errors::*; +use rustup::env_var::RUST_RECURSION_COUNT_MAX; +use rustup_dist::dist::TargetTriple; use std::alloc::System; use std::env; use std::path::PathBuf; -use crate::errors::*; -use rustup_dist::dist::TargetTriple; -use rustup::env_var::RUST_RECURSION_COUNT_MAX; // Always use the system allocator, to reduce binary size. #[global_allocator] @@ -83,14 +83,16 @@ fn run_rustup() -> Result<()> { // The name of arg0 determines how the program is going to behave let arg0 = env::args().next().map(PathBuf::from); - let name = arg0.as_ref() + let name = arg0 + .as_ref() .and_then(|a| a.file_stem()) .and_then(|a| a.to_str()); match name { Some("rustup") => rustup_mode::main(), Some(n) - if n.starts_with("multirust-setup") || n.starts_with("rustup-setup") + if n.starts_with("multirust-setup") + || n.starts_with("rustup-setup") || n.starts_with("rustup-init") => { // NB: The above check is only for the prefix of the file @@ -171,8 +173,8 @@ fn make_environment_compatible() { // REG_SZ type, when it should be REG_EXPAND_SZ. Silently fix it. #[cfg(windows)] fn fix_windows_reg_key() { - use winreg::RegKey; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; let root = RegKey::predef(HKEY_CURRENT_USER); let env = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE); diff --git a/src/rustup-cli/proxy_mode.rs b/src/rustup-cli/proxy_mode.rs index 54d2e5af91..b2c6349fab 100644 --- a/src/rustup-cli/proxy_mode.rs +++ b/src/rustup-cli/proxy_mode.rs @@ -1,13 +1,13 @@ use crate::common::set_globals; -use rustup::Cfg; use crate::errors::*; -use rustup_utils::utils::{self, ExitCode}; +use crate::job; use rustup::command::run_command_for_dir; +use rustup::Cfg; +use rustup_utils::utils::{self, ExitCode}; use std::env; use std::ffi::OsString; use std::path::PathBuf; use std::process; -use crate::job; pub fn main() -> Result<()> { crate::self_update::cleanup_self_updater()?; @@ -18,7 +18,8 @@ pub fn main() -> Result<()> { let mut args = env::args(); let arg0 = args.next().map(PathBuf::from); - let arg0 = arg0.as_ref() + let arg0 = arg0 + .as_ref() .and_then(|a| a.file_name()) .and_then(|a| a.to_str()); let ref arg0 = arg0.ok_or(ErrorKind::NoExeName)?; @@ -48,7 +49,12 @@ pub fn main() -> Result<()> { process::exit(c) } -fn direct_proxy(cfg: &Cfg, arg0: &str, toolchain: Option<&str>, args: &[OsString]) -> Result { +fn direct_proxy( + cfg: &Cfg, + arg0: &str, + toolchain: Option<&str>, + args: &[OsString], +) -> Result { let cmd = match toolchain { None => cfg.create_command_for_dir(&utils::current_dir()?, arg0)?, Some(tc) => cfg.create_command_for_toolchain(tc, false, arg0)?, diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index de159f8604..7a9ca215ed 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -1,19 +1,19 @@ -use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand}; use crate::common; -use rustup::{command, Cfg, Toolchain}; -use rustup::settings::TelemetryMode; use crate::errors::*; -use rustup_dist::manifest::Component; +use crate::help::*; +use crate::self_update; +use crate::term2; +use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand}; +use rustup::settings::TelemetryMode; +use rustup::{command, Cfg, Toolchain}; use rustup_dist::dist::{PartialTargetTriple, PartialToolchainDesc, TargetTriple}; +use rustup_dist::manifest::Component; use rustup_utils::utils::{self, ExitCode}; -use crate::self_update; -use std::path::Path; -use std::process::{self, Command}; -use std::iter; use std::error::Error; -use crate::term2; use std::io::{self, Write}; -use crate::help::*; +use std::iter; +use std::path::Path; +use std::process::{self, Command}; pub fn main() -> Result<()> { crate::self_update::cleanup_self_updater()?; @@ -31,7 +31,7 @@ pub fn main() -> Result<()> { match matches.subcommand() { ("show", Some(c)) => match c.subcommand() { ("active-toolchain", Some(_)) => show_active_toolchain(cfg)?, - (_, _) => show(cfg)? + (_, _) => show(cfg)?, }, ("install", Some(m)) => update(cfg, m)?, ("update", Some(m)) => update(cfg, m)?, @@ -116,29 +116,34 @@ pub fn cli() -> App<'static, 'static> { .after_help(SHOW_HELP) .setting(AppSettings::VersionlessSubcommands) .setting(AppSettings::DeriveDisplayOrder) - .subcommand(SubCommand::with_name("active-toolchain") - .about("Show the active toolchain") - .after_help(SHOW_ACTIVE_TOOLCHAIN_HELP) + .subcommand( + SubCommand::with_name("active-toolchain") + .about("Show the active toolchain") + .after_help(SHOW_ACTIVE_TOOLCHAIN_HELP), ), ) .subcommand( SubCommand::with_name("install") - .about("Update Rust toolchains") - .after_help(INSTALL_HELP) - .setting(AppSettings::Hidden) // synonym for 'toolchain install' - .arg(Arg::with_name("toolchain") - .help(TOOLCHAIN_ARG_HELP) - .required(true) - .multiple(true)), + .about("Update Rust toolchains") + .after_help(INSTALL_HELP) + .setting(AppSettings::Hidden) // synonym for 'toolchain install' + .arg( + Arg::with_name("toolchain") + .help(TOOLCHAIN_ARG_HELP) + .required(true) + .multiple(true), + ), ) .subcommand( SubCommand::with_name("uninstall") - .about("Uninstall Rust toolchains") - .setting(AppSettings::Hidden) // synonym for 'toolchain uninstall' - .arg(Arg::with_name("toolchain") - .help(TOOLCHAIN_ARG_HELP) - .required(true) - .multiple(true)), + .about("Uninstall Rust toolchains") + .setting(AppSettings::Hidden) // synonym for 'toolchain uninstall' + .arg( + Arg::with_name("toolchain") + .help(TOOLCHAIN_ARG_HELP) + .required(true) + .multiple(true), + ), ) .subcommand( SubCommand::with_name("update") @@ -429,34 +434,35 @@ pub fn cli() -> App<'static, 'static> { .subcommand( SubCommand::with_name("upgrade-data").about("Upgrade the internal data format."), ), - ).subcommand( - SubCommand::with_name("telemetry") - .about("rustup telemetry commands") - .setting(AppSettings::Hidden) - .setting(AppSettings::VersionlessSubcommands) - .setting(AppSettings::DeriveDisplayOrder) - .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand(SubCommand::with_name("enable").about("Enable rustup telemetry")) - .subcommand(SubCommand::with_name("disable").about("Disable rustup telemetry")) - .subcommand(SubCommand::with_name("analyze").about("Analyze stored telemetry")), - ) - .subcommand( - SubCommand::with_name("set") - .about("Alter rustup settings") - .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand( - SubCommand::with_name("default-host") - .about("The triple used to identify toolchains when not specified") - .arg(Arg::with_name("host_triple").required(true)), - ), - ) - .subcommand( - SubCommand::with_name("completions") - .about("Generate completion scripts for your shell") - .after_help(COMPLETIONS_HELP) - .setting(AppSettings::ArgRequiredElseHelp) - .arg(Arg::with_name("shell").possible_values(&Shell::variants())), - ) + ) + .subcommand( + SubCommand::with_name("telemetry") + .about("rustup telemetry commands") + .setting(AppSettings::Hidden) + .setting(AppSettings::VersionlessSubcommands) + .setting(AppSettings::DeriveDisplayOrder) + .setting(AppSettings::SubcommandRequiredElseHelp) + .subcommand(SubCommand::with_name("enable").about("Enable rustup telemetry")) + .subcommand(SubCommand::with_name("disable").about("Disable rustup telemetry")) + .subcommand(SubCommand::with_name("analyze").about("Analyze stored telemetry")), + ) + .subcommand( + SubCommand::with_name("set") + .about("Alter rustup settings") + .setting(AppSettings::SubcommandRequiredElseHelp) + .subcommand( + SubCommand::with_name("default-host") + .about("The triple used to identify toolchains when not specified") + .arg(Arg::with_name("host_triple").required(true)), + ), + ) + .subcommand( + SubCommand::with_name("completions") + .about("Generate completion scripts for your shell") + .after_help(COMPLETIONS_HELP) + .setting(AppSettings::ArgRequiredElseHelp) + .arg(Arg::with_name("shell").possible_values(&Shell::variants())), + ) } fn maybe_upgrade_data(cfg: &Cfg, m: &ArgMatches) -> Result { @@ -606,12 +612,7 @@ fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> { let args: Vec<_> = args.collect(); let cmd = cfg.create_command_for_toolchain(toolchain, m.is_present("install"), args[0])?; - let ExitCode(c) = command::run_command_for_dir( - cmd, - args[0], - &args[1..], - &cfg, - )?; + let ExitCode(c) = command::run_command_for_dir(cmd, args[0], &args[1..], &cfg)?; process::exit(c) } @@ -619,7 +620,8 @@ fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> { fn which(cfg: &Cfg, m: &ArgMatches) -> Result<()> { let binary = m.value_of("command").expect(""); - let binary_path = cfg.which_binary(&utils::current_dir()?, binary)? + let binary_path = cfg + .which_binary(&utils::current_dir()?, binary)? .expect("binary not found"); utils::assert_is_file(&binary_path)?; @@ -671,9 +673,11 @@ fn show(cfg: &Cfg) -> Result<()> { show_installed_toolchains, show_active_targets, show_active_toolchain, - ].iter() - .filter(|x| **x) - .count() > 1; + ] + .iter() + .filter(|x| **x) + .count() + > 1; if show_installed_toolchains { if show_headers { @@ -760,7 +764,7 @@ fn show_active_toolchain(cfg: &Cfg) -> Result<()> { match cfg.find_override_toolchain_or_default(cwd)? { Some((ref toolchain, _)) => { println!("{}", toolchain.name()); - }, + } None => { // Print nothing } @@ -778,7 +782,8 @@ fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; for target in m.values_of("target").expect("") { - let new_component = Component::new("rust-std".to_string(), Some(TargetTriple::from_str(target))); + let new_component = + Component::new("rust-std".to_string(), Some(TargetTriple::from_str(target))); toolchain.add_component(new_component)?; } @@ -790,7 +795,8 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; for target in m.values_of("target").expect("") { - let new_component = Component::new("rust-std".to_string(), Some(TargetTriple::from_str(target))); + let new_component = + Component::new("rust-std".to_string(), Some(TargetTriple::from_str(target))); toolchain.remove_component(new_component)?; } @@ -806,7 +812,8 @@ fn component_list(cfg: &Cfg, m: &ArgMatches) -> Result<()> { fn component_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; - let target = m.value_of("target") + let target = m + .value_of("target") .map(TargetTriple::from_str) .or_else(|| { toolchain @@ -827,7 +834,8 @@ fn component_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { fn component_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; - let target = m.value_of("target") + let target = m + .value_of("target") .map(TargetTriple::from_str) .or_else(|| { toolchain @@ -924,7 +932,8 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { }; for path in paths { - if cfg.settings_file + if cfg + .settings_file .with_mut(|s| Ok(s.remove_override(&Path::new(&path), cfg.notify_handler.as_ref())))? { info!("override toolchain for '{}' removed", path); diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index f642ee7d03..fb3cb30197 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -32,18 +32,18 @@ use crate::common::{self, Confirm}; use crate::errors::*; +use crate::term2; +use regex::Regex; +use rustup::{DUP_TOOLS, TOOLS}; use rustup_dist::dist; use rustup_utils::utils; -use rustup::{TOOLS, DUP_TOOLS}; use same_file::Handle; use std::env; use std::env::consts::EXE_SUFFIX; +use std::fs; use std::path::{Component, Path, PathBuf}; use std::process::{self, Command}; -use std::fs; use tempdir::TempDir; -use crate::term2; -use regex::Regex; pub struct InstallOpts { pub default_host_triple: String, @@ -61,8 +61,8 @@ pub const NEVER_SELF_UPDATE: bool = false; macro_rules! pre_install_msg_template { ($platform_msg: expr) => { -concat!( -r" + concat!( + r" # Welcome to Rust! This will download and install the official compiler for the Rust @@ -74,45 +74,48 @@ Cargo's bin directory, located at: {cargo_home_bin} ", -$platform_msg -, -r#" + $platform_msg, + r#" You can uninstall at any time with `rustup self uninstall` and these changes will be reverted. "# - )}; + ) + }; } macro_rules! pre_install_msg_unix { () => { -pre_install_msg_template!( -"This path will then be added to your `PATH` environment variable by + pre_install_msg_template!( + "This path will then be added to your `PATH` environment variable by modifying the profile file{plural} located at: {rcfiles}" - )}; + ) + }; } macro_rules! pre_install_msg_win { () => { -pre_install_msg_template!( -"This path will then be added to your `PATH` environment variable by + pre_install_msg_template!( + "This path will then be added to your `PATH` environment variable by modifying the `HKEY_CURRENT_USER/Environment/PATH` registry key." - )}; + ) + }; } macro_rules! pre_install_msg_no_modify_path { () => { -pre_install_msg_template!( -"This path needs to be in your `PATH` environment variable, + pre_install_msg_template!( + "This path needs to be in your `PATH` environment variable, but will not be added automatically." - )}; + ) + }; } macro_rules! post_install_msg_unix { () => { -r"# Rust is installed now. Great! + r"# Rust is installed now. Great! To get started you need Cargo's bin directory ({cargo_home}/bin) in your `PATH` environment variable. Next time you log in this will be done @@ -125,7 +128,7 @@ To configure your current shell run `source {cargo_home}/env` macro_rules! post_install_msg_win { () => { -r"# Rust is installed now. Great! + r"# Rust is installed now. Great! To get started you need Cargo's bin directory ({cargo_home}\bin) in your `PATH` environment variable. Future applications will automatically have the @@ -136,7 +139,7 @@ correct environment, but you may need to restart your current shell. macro_rules! post_install_msg_unix_no_modify_path { () => { -r"# Rust is installed now. Great! + r"# Rust is installed now. Great! To get started you need Cargo's bin directory ({cargo_home}/bin) in your `PATH` environment variable. @@ -148,7 +151,7 @@ To configure your current shell run `source {cargo_home}/env` macro_rules! post_install_msg_win_no_modify_path { () => { -r"# Rust is installed now. Great! + r"# Rust is installed now. Great! To get started you need Cargo's bin directory ({cargo_home}\bin) in your `PATH` environment variable. This has not been done automatically. @@ -158,13 +161,13 @@ environment variable. This has not been done automatically. macro_rules! pre_uninstall_msg { () => { -r"# Thanks for hacking in Rust! + r"# Thanks for hacking in Rust! This will uninstall all Rust toolchains and data, and remove `{cargo_home}/bin` from your `PATH` environment variable. " - } + }; } static MSVC_MESSAGE: &'static str = r#"# Rust Visual C++ prerequisites @@ -333,9 +336,11 @@ pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result< fn rustc_or_cargo_exists_in_path() -> Result<()> { // Ignore rustc and cargo if present in $HOME/.cargo/bin or a few other directories fn ignore_paths(path: &PathBuf) -> bool { - !path.components() + !path + .components() .any(|c| c == Component::Normal(".cargo".as_ref())) - && !path.components() + && !path + .components() .any(|c| c == Component::Normal(".multirust".as_ref())) } @@ -477,7 +482,8 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> { if env::var("RUSTUP_INIT_SKIP_SUDO_CHECK") .as_ref() .map(Deref::deref) - .ok() == Some("yes") + .ok() + == Some("yes") { return false; } @@ -890,8 +896,8 @@ fn get_msi_product_code() -> Result { #[cfg(feature = "msi-installed")] fn get_msi_product_code() -> Result { - use winreg::RegKey; use winreg::enums::{HKEY_CURRENT_USER, KEY_READ}; + use winreg::RegKey; let root = RegKey::predef(HKEY_CURRENT_USER); let environment = root.open_subkey_with_flags("SOFTWARE\\rustup", KEY_READ); @@ -965,16 +971,16 @@ fn delete_rustup_and_cargo_home() -> Result<()> { let numbah: u32 = rand::random(); let gc_exe = work_path.join(&format!("rustup-gc-{:x}.exe", numbah)); + use std::io; + use std::mem; + use std::os::windows::ffi::OsStrExt; + use std::ptr; + use winapi::shared::minwindef::DWORD; use winapi::um::fileapi::{CreateFileW, OPEN_EXISTING}; use winapi::um::handleapi::{CloseHandle, INVALID_HANDLE_VALUE}; use winapi::um::minwinbase::SECURITY_ATTRIBUTES; use winapi::um::winbase::FILE_FLAG_DELETE_ON_CLOSE; use winapi::um::winnt::{FILE_SHARE_DELETE, FILE_SHARE_READ, GENERIC_READ}; - use winapi::shared::minwindef::DWORD; - use std::os::windows::ffi::OsStrExt; - use std::ptr; - use std::io; - use std::mem; unsafe { // Copy rustup (probably this process's exe) to the gc exe @@ -1055,18 +1061,19 @@ pub fn complete_windows_uninstall() -> Result<()> { #[cfg(windows)] fn wait_for_parent() -> Result<()> { + use scopeguard; + use std::io; + use std::mem; + use std::ptr; use winapi::shared::minwindef::DWORD; use winapi::um::handleapi::{CloseHandle, INVALID_HANDLE_VALUE}; use winapi::um::processthreadsapi::{GetCurrentProcessId, OpenProcess}; use winapi::um::synchapi::WaitForSingleObject; - use winapi::um::tlhelp32::{CreateToolhelp32Snapshot, PROCESSENTRY32, Process32First, - Process32Next, TH32CS_SNAPPROCESS}; - use winapi::um::winbase::{WAIT_OBJECT_0, INFINITE}; + use winapi::um::tlhelp32::{ + CreateToolhelp32Snapshot, Process32First, Process32Next, PROCESSENTRY32, TH32CS_SNAPPROCESS, + }; + use winapi::um::winbase::{INFINITE, WAIT_OBJECT_0}; use winapi::um::winnt::SYNCHRONIZE; - use std::io; - use std::mem; - use std::ptr; - use scopeguard; unsafe { // Take a snapshot of system processes, one of which is ours @@ -1204,12 +1211,13 @@ fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> { fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> { assert!(methods.len() == 1 && methods[0] == PathUpdateMethod::Windows); - use winreg::{RegKey, RegValue}; - use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; - use winapi::shared::minwindef::*; - use winapi::um::winuser::{SendMessageTimeoutA, HWND_BROADCAST, SMTO_ABORTIFHUNG, - WM_SETTINGCHANGE}; use std::ptr; + use winapi::shared::minwindef::*; + use winapi::um::winuser::{ + SendMessageTimeoutA, HWND_BROADCAST, SMTO_ABORTIFHUNG, WM_SETTINGCHANGE, + }; + use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::{RegKey, RegValue}; let old_path = if let Some(s) = get_windows_path_var()? { s @@ -1232,7 +1240,8 @@ fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> { } let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .chain_err(|| ErrorKind::PermissionDenied)?; let reg_value = RegValue { @@ -1265,12 +1274,13 @@ fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> { // should not mess with it. #[cfg(windows)] fn get_windows_path_var() -> Result> { - use winreg::RegKey; - use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; use std::io; + use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .chain_err(|| ErrorKind::PermissionDenied)?; let reg_value = environment.get_raw_value("PATH"); @@ -1316,12 +1326,13 @@ fn get_remove_path_methods() -> Result> { fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> { assert!(methods.len() == 1 && methods[0] == PathUpdateMethod::Windows); + use std::ptr; use winapi::shared::minwindef::*; - use winapi::um::winuser::{SendMessageTimeoutA, HWND_BROADCAST, SMTO_ABORTIFHUNG, - WM_SETTINGCHANGE}; - use winreg::{RegKey, RegValue}; + use winapi::um::winuser::{ + SendMessageTimeoutA, HWND_BROADCAST, SMTO_ABORTIFHUNG, WM_SETTINGCHANGE, + }; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; - use std::ptr; + use winreg::{RegKey, RegValue}; let old_path = if let Some(s) = get_windows_path_var()? { s @@ -1351,7 +1362,8 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> { new_path.push_str(&old_path[idx + len..]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .chain_err(|| ErrorKind::PermissionDenied)?; if new_path.is_empty() { diff --git a/src/rustup-cli/setup_mode.rs b/src/rustup-cli/setup_mode.rs index e08268365e..aba56b8357 100644 --- a/src/rustup-cli/setup_mode.rs +++ b/src/rustup-cli/setup_mode.rs @@ -1,9 +1,9 @@ -use std::env; -use crate::self_update::{self, InstallOpts}; +use crate::common; use crate::errors::*; +use crate::self_update::{self, InstallOpts}; use clap::{App, AppSettings, Arg}; use rustup_dist::dist::TargetTriple; -use crate::common; +use std::env; pub fn main() -> Result<()> { let args: Vec<_> = env::args().collect(); diff --git a/src/rustup-cli/term2.rs b/src/rustup-cli/term2.rs index 4034bb8824..7933885f32 100644 --- a/src/rustup-cli/term2.rs +++ b/src/rustup-cli/term2.rs @@ -2,11 +2,11 @@ //! that does not fail if `StdoutTerminal` etc can't be constructed, which happens //! if TERM isn't defined. +use markdown::tokenize; +use markdown::{Block, ListItem, Span}; +use rustup_utils::tty; use std::io; use term; -use rustup_utils::tty; -use markdown::{Block, ListItem, Span}; -use markdown::tokenize; pub use term::color; pub use term::Attr; @@ -212,9 +212,11 @@ impl<'a, T: Instantiable + Isatty + io::Write + 'a> LineFormatter<'a, T> { ListItem::Simple(spans) => { self.do_spans(spans); } - ListItem::Paragraph(blocks) => for block in blocks { - self.do_block(block); - }, + ListItem::Paragraph(blocks) => { + for block in blocks { + self.do_block(block); + } + } } self.wrapper.write_line(); self.wrapper.indent -= 2; diff --git a/src/rustup-dist/src/component/components.rs b/src/rustup-dist/src/component/components.rs index 024262eb9f..a2f6eafae2 100644 --- a/src/rustup-dist/src/component/components.rs +++ b/src/rustup-dist/src/component/components.rs @@ -1,16 +1,15 @@ +use crate::errors::*; +use crate::prefix::InstallPrefix; /// The representation of the installed toolchain and its components. /// `Components` and `DirectoryPackage` are the two sides of the /// installation / uninstallation process. - use rustup_utils::utils; -use crate::prefix::InstallPrefix; -use crate::errors::*; -use crate::component::transaction::Transaction; use crate::component::package::{INSTALLER_VERSION, VERSION_FILE}; +use crate::component::transaction::Transaction; -use std::path::{Path, PathBuf}; use std::fs::File; +use std::path::{Path, PathBuf}; const COMPONENTS_FILE: &'static str = "components"; @@ -172,8 +171,10 @@ impl Component { pub fn parts(&self) -> Result> { let mut result = Vec::new(); for line in utils::read_file("component", &self.manifest_file())?.lines() { - result.push(ComponentPart::decode(line) - .ok_or_else(|| ErrorKind::CorruptComponent(self.name.clone()))?); + result.push( + ComponentPart::decode(line) + .ok_or_else(|| ErrorKind::CorruptComponent(self.name.clone()))?, + ); } Ok(result) } @@ -182,9 +183,7 @@ impl Component { let path = self.components.rel_components_file(); let abs_path = self.components.prefix.abs_path(&path); let temp = tx.temp().new_file()?; - utils::filter_file("components", &abs_path, &temp, |l| { - (l != self.name) - })?; + utils::filter_file("components", &abs_path, &temp, |l| (l != self.name))?; tx.modify_file(path)?; utils::rename_file("components", &temp, &abs_path)?; @@ -192,8 +191,8 @@ impl Component { // and the version file. // Track visited directories - use std::collections::HashSet; use std::collections::hash_set::IntoIter; + use std::collections::HashSet; use std::fs::read_dir; // dirs will contain the set of longest disjoint directory paths seen @@ -258,11 +257,13 @@ impl Component { Some(_) => { let mut path_buf = self.path_buf.take().unwrap(); match path_buf.file_name() { - Some(_) => if path_buf.pop() { - Some(path_buf) - } else { - None - }, + Some(_) => { + if path_buf.pop() { + Some(path_buf) + } else { + None + } + } None => self.iter.next(), } } diff --git a/src/rustup-dist/src/component/mod.rs b/src/rustup-dist/src/component/mod.rs index 1c15c3aac3..4f7c3f7ef0 100644 --- a/src/rustup-dist/src/component/mod.rs +++ b/src/rustup-dist/src/component/mod.rs @@ -1,10 +1,9 @@ +pub use self::components::*; +pub use self::package::*; /// An interpreter for the rust-installer [1] installation format. /// /// https://github.com/rust-lang/rust-installer - pub use self::transaction::*; -pub use self::components::*; -pub use self::package::*; // Transactional file system tools mod transaction; diff --git a/src/rustup-dist/src/component/package.rs b/src/rustup-dist/src/component/package.rs index 9b823b3832..cbd0223819 100644 --- a/src/rustup-dist/src/component/package.rs +++ b/src/rustup-dist/src/component/package.rs @@ -10,14 +10,14 @@ use crate::component::components::*; use crate::component::transaction::*; use crate::errors::*; -use rustup_utils::utils; use crate::temp; +use rustup_utils::utils; -use std::path::{Path, PathBuf}; use std::collections::HashSet; use std::fmt; -use std::io::Read; use std::fs::File; +use std::io::Read; +use std::path::{Path, PathBuf}; /// The current metadata revision used by rust-installer pub const INSTALLER_VERSION: &'static str = "3"; @@ -66,11 +66,12 @@ fn validate_installer_version(path: &Path) -> Result<()> { impl Package for DirectoryPackage { fn contains(&self, component: &str, short_name: Option<&str>) -> bool { - self.components.contains(component) || if let Some(n) = short_name { - self.components.contains(n) - } else { - false - } + self.components.contains(component) + || if let Some(n) = short_name { + self.components.contains(n) + } else { + false + } } fn install<'a>( &self, @@ -157,7 +158,8 @@ fn set_file_perms(dest_path: &Path, src_path: &Path) -> Result<()> { .chain_err(|| ErrorKind::ComponentFilePermissionsFailed)?; } } else { - let meta = fs::metadata(dest_path).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)?; + let meta = + fs::metadata(dest_path).chain_err(|| ErrorKind::ComponentFilePermissionsFailed)?; let mut perm = meta.permissions(); perm.set_mode(if is_bin || needs_x(&meta) { 0o755 diff --git a/src/rustup-dist/src/component/transaction.rs b/src/rustup-dist/src/component/transaction.rs index 5520cbe7e7..ad42a05cc2 100644 --- a/src/rustup-dist/src/component/transaction.rs +++ b/src/rustup-dist/src/component/transaction.rs @@ -9,11 +9,11 @@ //! FIXME: This uses ensure_dir_exists in some places but rollback //! does not remove any dirs created by it. -use rustup_utils::utils; -use crate::temp; -use crate::prefix::InstallPrefix; use crate::errors::*; use crate::notifications::*; +use crate::prefix::InstallPrefix; +use crate::temp; +use rustup_utils::utils; use std::fs::File; use std::path::{Path, PathBuf}; @@ -201,7 +201,8 @@ impl<'a> ChangedItem<'a> { Err(ErrorKind::ComponentConflict { name: component.to_owned(), path: relpath.clone(), - }.into()) + } + .into()) } else { if let Some(p) = abs_path.parent() { utils::ensure_dir_exists("component", p, &|_| ())?; @@ -223,7 +224,8 @@ impl<'a> ChangedItem<'a> { Err(ErrorKind::ComponentConflict { name: component.to_owned(), path: relpath.clone(), - }.into()) + } + .into()) } else { if let Some(p) = abs_path.parent() { utils::ensure_dir_exists("component", p, &|_| ())?; @@ -243,7 +245,8 @@ impl<'a> ChangedItem<'a> { Err(ErrorKind::ComponentConflict { name: component.to_owned(), path: relpath.clone(), - }.into()) + } + .into()) } else { if let Some(p) = abs_path.parent() { utils::ensure_dir_exists("component", p, &|_| ())?; @@ -264,7 +267,8 @@ impl<'a> ChangedItem<'a> { Err(ErrorKind::ComponentMissingFile { name: component.to_owned(), path: relpath.clone(), - }.into()) + } + .into()) } else { utils::rename_file("component", &abs_path, &backup)?; Ok(ChangedItem::RemovedFile(relpath, backup)) @@ -282,7 +286,8 @@ impl<'a> ChangedItem<'a> { Err(ErrorKind::ComponentMissingDir { name: component.to_owned(), path: relpath.clone(), - }.into()) + } + .into()) } else { utils::rename_dir("component", &abs_path, &backup.join("bk"))?; Ok(ChangedItem::RemovedDir(relpath, backup)) diff --git a/src/rustup-dist/src/config.rs b/src/rustup-dist/src/config.rs index 2f10aa08f2..20c8edcad8 100644 --- a/src/rustup-dist/src/config.rs +++ b/src/rustup-dist/src/config.rs @@ -1,8 +1,8 @@ use toml; -use rustup_utils::toml_utils::*; -use crate::errors::*; use super::manifest::Component; +use crate::errors::*; +use rustup_utils::toml_utils::*; pub const SUPPORTED_CONFIG_VERSIONS: [&'static str; 1] = ["1"]; pub const DEFAULT_CONFIG_VERSION: &'static str = "1"; diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index 1098df5bcf..a4415b37eb 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -1,16 +1,16 @@ -use crate::temp; +use crate::download::DownloadCfg; use crate::errors::*; -use crate::notifications::*; -use rustup_utils::{self, utils}; -use crate::prefix::InstallPrefix; use crate::manifest::Component; use crate::manifest::Manifest as ManifestV2; use crate::manifestation::{Changes, Manifestation, UpdateStatus}; -use crate::download::DownloadCfg; +use crate::notifications::*; +use crate::prefix::InstallPrefix; +use crate::temp; +use rustup_utils::{self, utils}; -use std::path::Path; -use std::fmt; use std::env; +use std::fmt; +use std::path::Path; use regex::Regex; @@ -125,8 +125,8 @@ impl TargetTriple { pub fn from_host() -> Option { #[cfg(windows)] fn inner() -> Option { - use winapi::um::sysinfoapi::GetNativeSystemInfo; use std::mem; + use winapi::um::sysinfoapi::GetNativeSystemInfo; // First detect architecture const PROCESSOR_ARCHITECTURE_AMD64: u16 = 9; @@ -152,8 +152,8 @@ impl TargetTriple { #[cfg(not(windows))] fn inner() -> Option { use libc; - use std::mem; use std::ffi::CStr; + use std::mem; let mut sys_info; let (sysname, machine) = unsafe { @@ -582,14 +582,13 @@ pub fn update_from_dist_<'a>( ) { Ok(None) => Ok(None), Ok(Some(hash)) => Ok(Some(hash)), - e @ Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::DownloadNotExists { .. }), _)) => { - e.chain_err(|| { + e @ Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::DownloadNotExists { .. }), _)) => e + .chain_err(|| { format!( "could not download nonexistent rust version `{}`", toolchain_str ) - }) - } + }), Err(e) => Err(e), } } diff --git a/src/rustup-dist/src/download.rs b/src/rustup-dist/src/download.rs index 195cd7de68..ce48f2a56e 100644 --- a/src/rustup-dist/src/download.rs +++ b/src/rustup-dist/src/download.rs @@ -1,13 +1,13 @@ -use rustup_utils::utils; use crate::errors::*; -use crate::temp; use crate::notifications::*; +use crate::temp; +use rustup_utils::utils; use sha2::{Digest, Sha256}; use url::Url; -use std::path::{Path, PathBuf}; use std::fs; use std::ops; +use std::path::{Path, PathBuf}; const UPDATE_HASH_LEN: usize = 20; @@ -59,7 +59,8 @@ impl<'a> DownloadCfg<'a> { .file_name() .map(|s| s.to_str().unwrap_or("_")) .unwrap_or("_") - .to_owned() + ".partial", + .to_owned() + + ".partial", ); let mut hasher = Sha256::new(); @@ -80,7 +81,8 @@ impl<'a> DownloadCfg<'a> { url: url.to_string(), expected: hash.to_string(), calculated: actual_hash, - }.into()); + } + .into()); } else { (self.notify_handler)(Notification::ChecksumValid(&url.to_string())); @@ -152,7 +154,8 @@ impl<'a> DownloadCfg<'a> { url: url_str.to_owned(), expected: hash, calculated: actual_hash, - }.into()); + } + .into()); } else { (self.notify_handler)(Notification::ChecksumValid(url_str)); } diff --git a/src/rustup-dist/src/errors.rs b/src/rustup-dist/src/errors.rs index 4f6a324495..3d3187c723 100644 --- a/src/rustup-dist/src/errors.rs +++ b/src/rustup-dist/src/errors.rs @@ -1,9 +1,9 @@ -use std::path::PathBuf; -use std::io::{self, Write}; +use crate::manifest::{Component, Manifest}; use crate::temp; -use toml; use rustup_utils; -use crate::manifest::{Component, Manifest}; +use std::io::{self, Write}; +use std::path::PathBuf; +use toml; error_chain! { links { @@ -121,7 +121,8 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest) -> String { ); } else { use itertools::Itertools; - let same_target = cs.iter() + let same_target = cs + .iter() .all(|c| c.target == cs[0].target || c.target.is_none()); if same_target { let mut cs_strs = cs.iter().map(|c| format!("'{}'", c.short_name(manifest))); diff --git a/src/rustup-dist/src/lib.rs b/src/rustup-dist/src/lib.rs index 13c025bc89..b7ee50654e 100644 --- a/src/rustup-dist/src/lib.rs +++ b/src/rustup-dist/src/lib.rs @@ -24,12 +24,12 @@ pub use crate::notifications::Notification; pub mod temp; +pub mod component; +pub mod config; pub mod dist; +pub mod download; pub mod errors; +pub mod manifest; +pub mod manifestation; pub mod notifications; pub mod prefix; -pub mod component; -pub mod manifestation; -pub mod download; -pub mod manifest; -pub mod config; diff --git a/src/rustup-dist/src/manifest.rs b/src/rustup-dist/src/manifest.rs index c0e06dc098..fa177c7619 100644 --- a/src/rustup-dist/src/manifest.rs +++ b/src/rustup-dist/src/manifest.rs @@ -11,11 +11,11 @@ //! See tests/channel-rust-nightly-example.toml for an example. use crate::errors::*; -use toml; use rustup_utils::toml_utils::*; +use toml; -use std::collections::HashMap; use crate::dist::TargetTriple; +use std::collections::HashMap; pub const SUPPORTED_MANIFEST_VERSIONS: [&'static str; 1] = ["2"]; pub const DEFAULT_MANIFEST_VERSION: &'static str = "2"; @@ -169,9 +169,11 @@ impl Manifest { fn validate_targeted_package(&self, tpkg: &TargetedPackage) -> Result<()> { for c in tpkg.components.iter().chain(tpkg.extensions.iter()) { - let cpkg = self.get_package(&c.pkg) + let cpkg = self + .get_package(&c.pkg) .chain_err(|| ErrorKind::MissingPackageForComponent(c.short_name(self)))?; - let _ctpkg = cpkg.get_target(c.target.as_ref()) + let _ctpkg = cpkg + .get_target(c.target.as_ref()) .chain_err(|| ErrorKind::MissingPackageForComponent(c.short_name(self)))?; } Ok(()) @@ -184,9 +186,11 @@ impl Manifest { PackageTargets::Wildcard(ref tpkg) => { self.validate_targeted_package(tpkg)?; } - PackageTargets::Targeted(ref tpkgs) => for (_, tpkg) in tpkgs { - self.validate_targeted_package(tpkg)?; - }, + PackageTargets::Targeted(ref tpkgs) => { + for (_, tpkg) in tpkgs { + self.validate_targeted_package(tpkg)?; + } + } } } @@ -235,8 +239,7 @@ impl Package { if let Some(toml::Value::Table(t)) = target_table.remove("*") { Ok(PackageTargets::Wildcard(TargetedPackage::from_toml( - t, - &path, + t, &path, )?)) } else { let mut result = HashMap::new(); @@ -257,9 +260,11 @@ impl Package { PackageTargets::Wildcard(tpkg) => { result.insert("*".to_owned(), toml::Value::Table(tpkg.to_toml())); } - PackageTargets::Targeted(tpkgs) => for (k, v) in tpkgs { - result.insert(k.to_string(), toml::Value::Table(v.to_toml())); - }, + PackageTargets::Targeted(tpkgs) => { + for (k, v) in tpkgs { + result.insert(k.to_string(), toml::Value::Table(v.to_toml())); + } + } } result } diff --git a/src/rustup-dist/src/manifestation.rs b/src/rustup-dist/src/manifestation.rs index c3e8f6f800..30ee8d42c4 100644 --- a/src/rustup-dist/src/manifestation.rs +++ b/src/rustup-dist/src/manifestation.rs @@ -1,16 +1,16 @@ //! Maintains a Rust installation by installing individual Rust //! platform components from a distribution server. +use crate::component::{Components, Package, TarGzPackage, TarXzPackage, Transaction}; use crate::config::Config; -use crate::manifest::{Component, Manifest, TargetedPackage}; use crate::dist::{TargetTriple, DEFAULT_DIST_SERVER}; -use crate::component::{Components, Package, TarGzPackage, TarXzPackage, Transaction}; -use crate::temp; +use crate::download::{DownloadCfg, File}; use crate::errors::*; +use crate::manifest::{Component, Manifest, TargetedPackage}; use crate::notifications::*; -use rustup_utils::utils; -use crate::download::{DownloadCfg, File}; use crate::prefix::InstallPrefix; +use crate::temp; +use rustup_utils::utils; use std::path::Path; pub const DIST_MANIFEST: &'static str = "multirust-channel-manifest.toml"; @@ -290,7 +290,9 @@ impl Manifestation { } else if let Some(c) = self.installation.find(&short_name)? { tx = c.uninstall(tx)?; } else { - notify_handler(Notification::MissingInstalledComponent(&component.short_name(manifest))); + notify_handler(Notification::MissingInstalledComponent( + &component.short_name(manifest), + )); } Ok(tx) @@ -344,10 +346,12 @@ impl Manifestation { return Err(format!( "binary package was not provided for '{}'", self.target_triple.to_string() - ).into()); + ) + .into()); } // Only replace once. The cost is inexpensive. - let url = url.unwrap() + let url = url + .unwrap() .replace(DEFAULT_DIST_SERVER, temp_cfg.dist_server.as_str()); notify_handler(Notification::DownloadingComponent( @@ -498,7 +502,7 @@ impl Update { } else { if changes.add_extensions.contains(&component) { notify_handler(Notification::ComponentAlreadyInstalled( - &component.description(new_manifest) + &component.description(new_manifest), )); } } @@ -538,7 +542,8 @@ impl Update { if !is_removed { // If there is a rename in the (new) manifest, then we uninstall the component with the // old name and install a component with the new name - if let Some(renamed_component) = new_manifest.rename_component(&existing_component) { + if let Some(renamed_component) = new_manifest.rename_component(&existing_component) + { let is_already_included = self.final_component_list.contains(&renamed_component); if !is_already_included { @@ -575,11 +580,19 @@ impl Update { self.components_to_uninstall.is_empty() && self.components_to_install.is_empty() } - fn missing_essential_components(&self, target_triple: &TargetTriple, manifest: &Manifest) -> Result<()> { + fn missing_essential_components( + &self, + target_triple: &TargetTriple, + manifest: &Manifest, + ) -> Result<()> { let missing_essential_components = ["rustc", "cargo"] .iter() .filter_map(|pkg| { - if self.final_component_list.iter().any(|c| &c.short_name_in_manifest() == pkg) { + if self + .final_component_list + .iter() + .any(|c| &c.short_name_in_manifest() == pkg) + { None } else { Some(Component::new(pkg.to_string(), Some(target_triple.clone()))) @@ -588,20 +601,24 @@ impl Update { .collect::>(); if !missing_essential_components.is_empty() { - return Err( - ErrorKind::RequestedComponentsUnavailable(missing_essential_components, manifest.clone()).into(), - ); + return Err(ErrorKind::RequestedComponentsUnavailable( + missing_essential_components, + manifest.clone(), + ) + .into()); } Ok(()) } fn unavailable_components(&self, new_manifest: &Manifest) -> Result<()> { - let mut unavailable_components: Vec = self.components_to_install + let mut unavailable_components: Vec = self + .components_to_install .iter() .filter(|c| { use crate::manifest::*; - let pkg: Option<&Package> = new_manifest.get_package(&c.short_name_in_manifest()).ok(); + let pkg: Option<&Package> = + new_manifest.get_package(&c.short_name_in_manifest()).ok(); let target_pkg: Option<&TargetedPackage> = pkg.and_then(|p| p.get_target(c.target.as_ref()).ok()); target_pkg.map(|tp| tp.available()) != Some(true) @@ -612,7 +629,11 @@ impl Update { unavailable_components.extend_from_slice(&self.missing_components); if !unavailable_components.is_empty() { - return Err(ErrorKind::RequestedComponentsUnavailable(unavailable_components, new_manifest.clone()).into()); + return Err(ErrorKind::RequestedComponentsUnavailable( + unavailable_components, + new_manifest.clone(), + ) + .into()); } Ok(()) diff --git a/src/rustup-dist/src/notifications.rs b/src/rustup-dist/src/notifications.rs index 1c19150d06..b9f5c01203 100644 --- a/src/rustup-dist/src/notifications.rs +++ b/src/rustup-dist/src/notifications.rs @@ -1,10 +1,10 @@ -use std::path::Path; -use std::fmt::{self, Display}; +use crate::dist::TargetTriple; +use crate::errors::*; use crate::temp; use rustup_utils; use rustup_utils::notify::NotificationLevel; -use crate::dist::TargetTriple; -use crate::errors::*; +use std::fmt::{self, Display}; +use std::path::Path; #[derive(Debug)] pub enum Notification<'a> { @@ -82,9 +82,7 @@ impl<'a> Display for Notification<'a> { Temp(ref n) => n.fmt(f), Utils(ref n) => n.fmt(f), Extracting(_, _) => write!(f, "extracting..."), - ComponentAlreadyInstalled(ref c) => { - write!(f, "component {} is up to date", c) - } + ComponentAlreadyInstalled(ref c) => write!(f, "component {} is up to date", c), CantReadUpdateHash(path) => write!( f, "can't read update hash file: '{}', can't skip update...", diff --git a/src/rustup-dist/src/temp.rs b/src/rustup-dist/src/temp.rs index f457fe0057..1bf0328e3b 100644 --- a/src/rustup-dist/src/temp.rs +++ b/src/rustup-dist/src/temp.rs @@ -1,12 +1,12 @@ extern crate remove_dir_all; +use rustup_utils::raw; use std::error; +use std::fmt::{self, Display}; use std::fs; -use std::path::{Path, PathBuf}; use std::io; use std::ops; -use std::fmt::{self, Display}; -use rustup_utils::raw; +use std::path::{Path, PathBuf}; use rustup_utils::notify::NotificationLevel; @@ -140,7 +140,8 @@ impl Cfg { pub fn create_root(&self) -> Result { raw::ensure_dir_exists(&self.root_directory, |p| { (self.notify_handler)(Notification::CreatingRoot(p)); - }).map_err(|e| Error::CreatingRoot { + }) + .map_err(|e| Error::CreatingRoot { path: PathBuf::from(&self.root_directory), error: e, }) diff --git a/src/rustup-dist/tests/dist.rs b/src/rustup-dist/tests/dist.rs index ef8fbe6215..f12994a78d 100644 --- a/src/rustup-dist/tests/dist.rs +++ b/src/rustup-dist/tests/dist.rs @@ -12,25 +12,25 @@ extern crate toml; extern crate url; extern crate walkdir; -use rustup_mock::dist::*; -use rustup_mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; -use rustup_dist::prefix::InstallPrefix; -use rustup_dist::ErrorKind; -use rustup_dist::errors::Result; use rustup_dist::dist::{TargetTriple, ToolchainDesc, DEFAULT_DIST_SERVER}; use rustup_dist::download::DownloadCfg; +use rustup_dist::errors::Result; +use rustup_dist::manifest::{Component, Manifest}; +use rustup_dist::manifestation::{Changes, Manifestation, UpdateStatus}; +use rustup_dist::prefix::InstallPrefix; +use rustup_dist::temp; +use rustup_dist::ErrorKind; use rustup_dist::Notification; -use rustup_utils::utils; +use rustup_mock::dist::*; +use rustup_mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; use rustup_utils::raw as utils_raw; -use rustup_dist::temp; -use rustup_dist::manifestation::{Changes, Manifestation, UpdateStatus}; -use rustup_dist::manifest::{Component, Manifest}; -use url::Url; +use rustup_utils::utils; use std::cell::Cell; use std::collections::HashMap; use std::fs; use std::path::Path; use std::sync::Arc; +use url::Url; use tempdir::TempDir; @@ -126,12 +126,10 @@ pub fn create_mock_channel( components: vec![], extensions: vec![], installer: MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: pkg.to_string(), - files: vec![MockFile::new_arc(*bin, contents.clone())], - }, - ], + components: vec![MockComponentBuilder { + name: pkg.to_string(), + files: vec![MockFile::new_arc(*bin, contents.clone())], + }], }, }, MockTargetedPackage { @@ -155,12 +153,10 @@ pub fn create_mock_channel( components: vec![], extensions: vec![], installer: MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "rust-std-x86_64-apple-darwin".to_string(), - files: vec![MockFile::new_arc("lib/libstd.rlib", contents.clone())], - }, - ], + components: vec![MockComponentBuilder { + name: "rust-std-x86_64-apple-darwin".to_string(), + files: vec![MockFile::new_arc("lib/libstd.rlib", contents.clone())], + }], }, }, MockTargetedPackage { @@ -169,17 +165,13 @@ pub fn create_mock_channel( components: vec![], extensions: vec![], installer: MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "rust-std-i686-apple-darwin".to_string(), - files: vec![ - MockFile::new_arc( - "lib/i686-apple-darwin/libstd.rlib", - contents.clone(), - ), - ], - }, - ], + components: vec![MockComponentBuilder { + name: "rust-std-i686-apple-darwin".to_string(), + files: vec![MockFile::new_arc( + "lib/i686-apple-darwin/libstd.rlib", + contents.clone(), + )], + }], }, }, MockTargetedPackage { @@ -188,17 +180,13 @@ pub fn create_mock_channel( components: vec![], extensions: vec![], installer: MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "rust-std-i686-unknown-linux-gnu".to_string(), - files: vec![ - MockFile::new_arc( - "lib/i686-unknown-linux-gnu/libstd.rlib", - contents.clone(), - ), - ], - }, - ], + components: vec![MockComponentBuilder { + name: "rust-std-i686-unknown-linux-gnu".to_string(), + files: vec![MockFile::new_arc( + "lib/i686-unknown-linux-gnu/libstd.rlib", + contents.clone(), + )], + }], }, }, ], @@ -224,22 +212,18 @@ fn bonus_component(name: &'static str, contents: Arc>) -> MockPackage { MockPackage { name: name, version: "1.0.0", - targets: vec![ - MockTargetedPackage { - target: "x86_64-apple-darwin".to_string(), - available: true, - components: vec![], - extensions: vec![], - installer: MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: format!("{}-x86_64-apple-darwin", name), - files: vec![MockFile::new_arc("bin/bonus", contents)], - }, - ], - }, + targets: vec![MockTargetedPackage { + target: "x86_64-apple-darwin".to_string(), + available: true, + components: vec![], + extensions: vec![], + installer: MockInstallerBuilder { + components: vec![MockComponentBuilder { + name: format!("{}-x86_64-apple-darwin", name), + files: vec![MockFile::new_arc("bin/bonus", contents)], + }], }, - ], + }], } } @@ -253,9 +237,9 @@ fn mock_dist_server_smoke_test() { assert!(utils::path_exists(path.join( "dist/2016-02-01/rustc-nightly-x86_64-apple-darwin.tar.gz" ))); - assert!(utils::path_exists(path.join( - "dist/2016-02-01/rustc-nightly-i686-apple-darwin.tar.gz" - ))); + assert!(utils::path_exists( + path.join("dist/2016-02-01/rustc-nightly-i686-apple-darwin.tar.gz") + )); assert!(utils::path_exists(path.join( "dist/2016-02-01/rust-std-nightly-x86_64-apple-darwin.tar.gz" ))); @@ -274,12 +258,12 @@ fn mock_dist_server_smoke_test() { assert!(utils::path_exists(path.join( "dist/2016-02-01/rust-std-nightly-i686-apple-darwin.tar.gz.sha256" ))); - assert!(utils::path_exists(path.join( - "dist/channel-rust-nightly.toml" - ))); - assert!(utils::path_exists(path.join( - "dist/channel-rust-nightly.toml.sha256" - ))); + assert!(utils::path_exists( + path.join("dist/channel-rust-nightly.toml") + )); + assert!(utils::path_exists( + path.join("dist/channel-rust-nightly.toml.sha256") + )); } // Test that a standard rename works - the component is installed with the old name, then renamed @@ -567,9 +551,13 @@ fn uninstall_removes_config_file() { download_cfg, temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - assert!(utils::path_exists(&prefix.manifest_file("multirust-config.toml"))); + assert!(utils::path_exists( + &prefix.manifest_file("multirust-config.toml") + )); uninstall(toolchain, prefix, temp_cfg, &|_| ()).unwrap(); - assert!(!utils::path_exists(&prefix.manifest_file("multirust-config.toml"))); + assert!(!utils::path_exists( + &prefix.manifest_file("multirust-config.toml") + )); }); } @@ -713,22 +701,22 @@ fn update_preserves_extensions() { change_channel_date(url, "nightly", "2016-02-01"); update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); change_channel_date(url, "nightly", "2016-02-02"); update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -762,12 +750,10 @@ fn update_preserves_extensions_that_became_components() { Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| { - let ref adds = vec![ - Component::new( - "bonus".to_string(), - Some(TargetTriple::from_str("x86_64-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "bonus".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; change_channel_date(url, "nightly", "2016-02-01"); update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); @@ -856,12 +842,12 @@ fn add_extensions_for_initial_install() { ]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -887,12 +873,12 @@ fn add_extensions_for_same_manifest() { update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -922,12 +908,12 @@ fn add_extensions_for_upgrade() { update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -939,12 +925,10 @@ fn add_extension_not_in_manifest() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ - Component::new( - "rust-bogus".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rust-bogus".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); }); @@ -958,12 +942,10 @@ fn add_extension_that_is_required_component() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ - Component::new( - "rustc".to_string(), - Some(TargetTriple::from_str("x86_64-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rustc".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); }); @@ -986,12 +968,10 @@ fn add_extensions_does_not_remove_other_components() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); @@ -1008,12 +988,10 @@ fn remove_extensions_for_initial_install() { prefix, download_cfg, temp_cfg| { - let ref removes = vec![ - Component::new( - "rustc".to_string(), - Some(TargetTriple::from_str("x86_64-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rustc".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); }); @@ -1039,21 +1017,19 @@ fn remove_extensions_for_same_manifest() { update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); - assert!(!utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(!utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -1081,21 +1057,19 @@ fn remove_extensions_for_upgrade() { change_channel_date(url, "nightly", "2016-02-02"); - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); - assert!(!utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + assert!(!utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -1113,12 +1087,10 @@ fn remove_extension_not_in_manifest() { change_channel_date(url, "nightly", "2016-02-02"); - let ref removes = vec![ - Component::new( - "rust-bogus".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rust-bogus".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); }); @@ -1149,23 +1121,19 @@ fn remove_extension_not_in_manifest_but_is_already_installed() { &|url, toolchain, prefix, download_cfg, temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); - let ref adds = vec![ - Component::new( - "bonus".to_string(), - Some(TargetTriple::from_str("x86_64-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "bonus".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists(&prefix.path().join("bin/bonus"))); change_channel_date(url, "nightly", "2016-02-02"); - let ref removes = vec![ - Component::new( - "bonus".to_string(), - Some(TargetTriple::from_str("x86_64-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "bonus".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); }, ); @@ -1181,12 +1149,10 @@ fn remove_extension_that_is_required_component() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![ - Component::new( - "rustc".to_string(), - Some(TargetTriple::from_str("x86_64-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rustc".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); }); @@ -1202,12 +1168,10 @@ fn remove_extension_not_installed() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); }); @@ -1224,21 +1188,17 @@ fn remove_extensions_does_not_remove_other_components() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); @@ -1255,30 +1215,24 @@ fn add_and_remove_for_upgrade() { temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-unknown-linux-gnu")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-unknown-linux-gnu")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); change_channel_date(url, "nightly", "2016-02-02"); - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-unknown-linux-gnu")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-unknown-linux-gnu")), + )]; update_from_dist( url, @@ -1288,14 +1242,15 @@ fn add_and_remove_for_upgrade() { removes, download_cfg, temp_cfg, - ).unwrap(); - - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(!utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + ) + .unwrap(); + + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(!utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -1306,28 +1261,22 @@ fn add_and_remove() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-unknown-linux-gnu")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-unknown-linux-gnu")), + )]; update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-unknown-linux-gnu")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-unknown-linux-gnu")), + )]; update_from_dist( url, @@ -1337,14 +1286,15 @@ fn add_and_remove() { removes, download_cfg, temp_cfg, - ).unwrap(); - - assert!(utils::path_exists(&prefix - .path() - .join("lib/i686-apple-darwin/libstd.rlib"))); - assert!(!utils::path_exists(&prefix - .path() - .join("lib/i686-unknown-linux-gnu/libstd.rlib"))); + ) + .unwrap(); + + assert!(utils::path_exists( + &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") + )); + assert!(!utils::path_exists( + &prefix.path().join("lib/i686-unknown-linux-gnu/libstd.rlib") + )); }); } @@ -1358,19 +1308,15 @@ fn add_and_remove_same_component() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple-darwin")), - ), - ]; + let ref adds = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple-darwin")), + )]; - let ref removes = vec![ - Component::new( - "rust-std".to_string(), - Some(TargetTriple::from_str("i686-apple_darwin")), - ), - ]; + let ref removes = vec![Component::new( + "rust-std".to_string(), + Some(TargetTriple::from_str("i686-apple_darwin")), + )]; update_from_dist( url, @@ -1380,7 +1326,8 @@ fn add_and_remove_same_component() { removes, download_cfg, temp_cfg, - ).unwrap(); + ) + .unwrap(); }); } @@ -1481,7 +1428,8 @@ fn checks_files_hashes_before_reuse() { let target_hash = utils::read_file( "target hash", &path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz.sha256"), - ).unwrap()[..64] + ) + .unwrap()[..64] .to_owned(); let prev_download = download_cfg.download_dir.join(target_hash); utils::ensure_dir_exists("download dir", &download_cfg.download_dir, &|_| {}).unwrap(); diff --git a/src/rustup-dist/tests/install.rs b/src/rustup-dist/tests/install.rs index 306a863633..426ab16c73 100644 --- a/src/rustup-dist/tests/install.rs +++ b/src/rustup-dist/tests/install.rs @@ -4,18 +4,18 @@ extern crate rustup_utils; extern crate tempdir; use rustup_dist::component::Components; -use rustup_dist::component::{DirectoryPackage, Package}; use rustup_dist::component::Transaction; +use rustup_dist::component::{DirectoryPackage, Package}; use rustup_dist::dist::DEFAULT_DIST_SERVER; +use rustup_dist::prefix::InstallPrefix; use rustup_dist::temp; use rustup_dist::ErrorKind; use rustup_dist::Notification; +use rustup_mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; use rustup_utils::utils; -use rustup_dist::prefix::InstallPrefix; use std::fs::File; use std::io::Write; use tempdir::TempDir; -use rustup_mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; // Just testing that the mocks work #[test] @@ -80,12 +80,10 @@ fn package_bad_version() { let tempdir = TempDir::new("rustup").unwrap(); let mock = MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "mycomponent".to_string(), - files: vec![MockFile::new("bin/foo", b"foo")], - }, - ], + components: vec![MockComponentBuilder { + name: "mycomponent".to_string(), + files: vec![MockFile::new("bin/foo", b"foo")], + }], }; mock.build(tempdir.path()); @@ -101,16 +99,14 @@ fn basic_install() { let pkgdir = TempDir::new("rustup").unwrap(); let mock = MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "mycomponent".to_string(), - files: vec![ - MockFile::new("bin/foo", b"foo"), - MockFile::new("lib/bar", b"bar"), - MockFile::new_dir("doc/stuff", &[("doc1", b"", false), ("doc2", b"", false)]), - ], - }, - ], + components: vec![MockComponentBuilder { + name: "mycomponent".to_string(), + files: vec![ + MockFile::new("bin/foo", b"foo"), + MockFile::new("lib/bar", b"bar"), + MockFile::new_dir("doc/stuff", &[("doc1", b"", false), ("doc2", b"", false)]), + ], + }], }; mock.build(pkgdir.path()); @@ -260,12 +256,10 @@ fn component_bad_version() { let pkgdir = TempDir::new("rustup").unwrap(); let mock = MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "mycomponent".to_string(), - files: vec![MockFile::new("bin/foo", b"foo")], - }, - ], + components: vec![MockComponentBuilder { + name: "mycomponent".to_string(), + files: vec![MockFile::new("bin/foo", b"foo")], + }], }; mock.build(pkgdir.path()); @@ -305,30 +299,28 @@ fn component_bad_version() { #[test] #[cfg(unix)] fn unix_permissions() { - use std::os::unix::fs::PermissionsExt; use std::fs; + use std::os::unix::fs::PermissionsExt; let pkgdir = TempDir::new("rustup").unwrap(); let mock = MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "mycomponent".to_string(), - files: vec![ - MockFile::new("bin/foo", b"foo"), - MockFile::new("lib/bar", b"bar"), - MockFile::new("lib/foobar", b"foobar").executable(true), - MockFile::new_dir( - "doc/stuff", - &[ - ("doc1", b"", false), - ("morestuff/doc2", b"", false), - ("morestuff/tool", b"", true), - ], - ), - ], - }, - ], + components: vec![MockComponentBuilder { + name: "mycomponent".to_string(), + files: vec![ + MockFile::new("bin/foo", b"foo"), + MockFile::new("lib/bar", b"bar"), + MockFile::new("lib/foobar", b"foobar").executable(true), + MockFile::new_dir( + "doc/stuff", + &[ + ("doc1", b"", false), + ("morestuff/doc2", b"", false), + ("morestuff/tool", b"", true), + ], + ), + ], + }], }; mock.build(pkgdir.path()); @@ -408,12 +400,10 @@ fn install_to_prefix_that_does_not_exist() { let pkgdir = TempDir::new("rustup").unwrap(); let mock = MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "mycomponent".to_string(), - files: vec![MockFile::new("bin/foo", b"foo")], - }, - ], + components: vec![MockComponentBuilder { + name: "mycomponent".to_string(), + files: vec![MockFile::new("bin/foo", b"foo")], + }], }; mock.build(pkgdir.path()); diff --git a/src/rustup-dist/tests/manifest.rs b/src/rustup-dist/tests/manifest.rs index 3e2711485f..b3b4290d1f 100644 --- a/src/rustup-dist/tests/manifest.rs +++ b/src/rustup-dist/tests/manifest.rs @@ -1,8 +1,8 @@ extern crate rustup_dist; +use rustup_dist::dist::TargetTriple; use rustup_dist::manifest::Manifest; use rustup_dist::ErrorKind; -use rustup_dist::dist::TargetTriple; // Example manifest from https://public.etherpad-mozilla.org/p/Rust-infra-work-week static EXAMPLE: &'static str = include_str!("channel-rust-nightly-example.toml"); diff --git a/src/rustup-dist/tests/transactions.rs b/src/rustup-dist/tests/transactions.rs index a055755f26..15bf782d5f 100644 --- a/src/rustup-dist/tests/transactions.rs +++ b/src/rustup-dist/tests/transactions.rs @@ -2,18 +2,18 @@ extern crate rustup_dist; extern crate rustup_utils; extern crate tempdir; -use rustup_dist::prefix::InstallPrefix; use rustup_dist::component::Transaction; use rustup_dist::dist::DEFAULT_DIST_SERVER; +use rustup_dist::prefix::InstallPrefix; use rustup_dist::temp; -use rustup_dist::Notification; use rustup_dist::ErrorKind; -use rustup_utils::utils; +use rustup_dist::Notification; use rustup_utils::raw as utils_raw; -use tempdir::TempDir; +use rustup_utils::utils; use std::fs; use std::io::Write; use std::path::PathBuf; +use tempdir::TempDir; #[test] fn add_file() { @@ -172,7 +172,8 @@ fn copy_file_that_exists() { fs::create_dir_all(&prefixdir.path().join("foo")).unwrap(); utils::write_file("", &prefixdir.path().join("foo/bar"), "").unwrap(); - let err = tx.copy_file("c", PathBuf::from("foo/bar"), &srcpath) + let err = tx + .copy_file("c", PathBuf::from("foo/bar"), &srcpath) .unwrap_err(); match err.0 { @@ -271,7 +272,8 @@ fn copy_dir_that_exists() { fs::create_dir_all(prefix.path().join("a")).unwrap(); - let err = tx.copy_dir("c", PathBuf::from("a"), srcdir.path()) + let err = tx + .copy_dir("c", PathBuf::from("a"), srcdir.path()) .unwrap_err(); match err.0 { @@ -508,7 +510,8 @@ fn write_file_that_exists() { let content = "hi".to_string(); utils_raw::write_file(&prefix.path().join("a"), &content).unwrap(); - let err = tx.write_file("c", PathBuf::from("a"), content.clone()) + let err = tx + .write_file("c", PathBuf::from("a"), content.clone()) .unwrap_err(); match err.0 { diff --git a/src/rustup-mock/src/clitools.rs b/src/rustup-mock/src/clitools.rs index 89d108c8b6..90d1a309e4 100644 --- a/src/rustup-mock/src/clitools.rs +++ b/src/rustup-mock/src/clitools.rs @@ -1,10 +1,15 @@ //! A mock distribution server used by tests/cli-v1.rs and //! tests/cli-v2.rs +use crate::dist::{ + change_channel_date, ManifestVersion, MockChannel, MockComponent, MockDistServer, MockPackage, + MockTargetedPackage, +}; +use crate::{MockComponentBuilder, MockFile, MockInstallerBuilder}; use std::cell::RefCell; use std::collections::HashMap; -use std::env::consts::EXE_SUFFIX; use std::env; +use std::env::consts::EXE_SUFFIX; use std::fs::{self, File}; use std::io::{self, Read, Write}; use std::mem; @@ -13,9 +18,6 @@ use std::process::{Command, Stdio}; use std::sync::Arc; use std::time::Duration; use tempdir::TempDir; -use crate::{MockComponentBuilder, MockFile, MockInstallerBuilder}; -use crate::dist::{change_channel_date, ManifestVersion, MockChannel, MockComponent, MockDistServer, - MockPackage, MockTargetedPackage}; use url::Url; use wait_timeout::ChildExt; @@ -393,7 +395,8 @@ fn create_mock_dist_server(path: &Path, s: Scenario) { MockDistServer { path: path.to_owned(), channels: chans, - }.write(vs, true); + } + .write(vs, true); // Also create the manifests for stable releases by version if dates_count > 1 { @@ -424,14 +427,16 @@ fn create_mock_dist_server(path: &Path, s: Scenario) { host_triple )), path.join(format!("dist/rust-1.0.0-{}.tar.gz", host_triple)), - ).unwrap(); + ) + .unwrap(); hard_link( path.join(format!( "dist/2015-01-01/rust-stable-{}.tar.gz.sha256", host_triple )), path.join(format!("dist/rust-1.0.0-{}.tar.gz.sha256", host_triple)), - ).unwrap(); + ) + .unwrap(); } hard_link( path.join(format!( @@ -439,14 +444,16 @@ fn create_mock_dist_server(path: &Path, s: Scenario) { host_triple )), path.join(format!("dist/rust-1.1.0-{}.tar.gz", host_triple)), - ).unwrap(); + ) + .unwrap(); hard_link( path.join(format!( "dist/2015-01-02/rust-stable-{}.tar.gz.sha256", host_triple )), path.join(format!("dist/rust-1.1.0-{}.tar.gz.sha256", host_triple)), - ).unwrap(); + ) + .unwrap(); } fn build_mock_channel( @@ -642,15 +649,13 @@ fn build_mock_unavailable_channel(channel: &str, date: &str, version: &'static s .map(|name| MockPackage { name, version, - targets: vec![ - MockTargetedPackage { - target: host_triple.clone(), - available: false, - components: vec![], - extensions: vec![], - installer: MockInstallerBuilder { components: vec![] }, - }, - ], + targets: vec![MockTargetedPackage { + target: host_triple.clone(), + available: false, + components: vec![], + extensions: vec![], + installer: MockInstallerBuilder { components: vec![] }, + }], }) .collect(); @@ -700,28 +705,25 @@ pub fn this_host_triple() -> String { fn build_mock_std_installer(trip: &str) -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: format!("rust-std-{}", trip.clone()), - files: vec![ - MockFile::new(format!("lib/rustlib/{}/libstd.rlib", trip), b""), - ], - }, - ], + components: vec![MockComponentBuilder { + name: format!("rust-std-{}", trip.clone()), + files: vec![MockFile::new( + format!("lib/rustlib/{}/libstd.rlib", trip), + b"", + )], + }], } } fn build_mock_cross_std_installer(target: &str, date: &str) -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: format!("rust-std-{}", target.clone()), - files: vec![ - MockFile::new(format!("lib/rustlib/{}/lib/libstd.rlib", target), b""), - MockFile::new(format!("lib/rustlib/{}/lib/{}", target, date), b""), - ], - }, - ], + components: vec![MockComponentBuilder { + name: format!("rust-std-{}", target.clone()), + files: vec![ + MockFile::new(format!("lib/rustlib/{}/lib/libstd.rlib", target), b""), + MockFile::new(format!("lib/rustlib/{}/lib/{}", target, date), b""), + ], + }], } } @@ -741,23 +743,19 @@ fn build_mock_rustc_installer( } MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "rustc".to_string(), - files: mock_bin("rustc", version, &version_hash), - }, - ], + components: vec![MockComponentBuilder { + name: "rustc".to_string(), + files: mock_bin("rustc", version, &version_hash), + }], } } fn build_mock_cargo_installer(version: &str, version_hash: &str) -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "cargo".to_string(), - files: mock_bin("cargo", version, &version_hash), - }, - ], + components: vec![MockComponentBuilder { + name: "cargo".to_string(), + files: mock_bin("cargo", version, &version_hash), + }], } } @@ -767,51 +765,44 @@ fn build_mock_rls_installer( preview: bool, ) -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: if preview { - "rls-preview".to_string() - } else { - "rls".to_string() - }, - files: mock_bin("rls", version, version_hash), + components: vec![MockComponentBuilder { + name: if preview { + "rls-preview".to_string() + } else { + "rls".to_string() }, - ], + files: mock_bin("rls", version, version_hash), + }], } } fn build_mock_rust_doc_installer() -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "rust-docs".to_string(), - files: vec![MockFile::new("share/doc/rust/html/index.html", b"")], - }, - ], + components: vec![MockComponentBuilder { + name: "rust-docs".to_string(), + files: vec![MockFile::new("share/doc/rust/html/index.html", b"")], + }], } } fn build_mock_rust_analysis_installer(trip: &str) -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: format!("rust-analysis-{}", trip), - files: vec![ - MockFile::new(format!("lib/rustlib/{}/analysis/libfoo.json", trip), b""), - ], - }, - ], + components: vec![MockComponentBuilder { + name: format!("rust-analysis-{}", trip), + files: vec![MockFile::new( + format!("lib/rustlib/{}/analysis/libfoo.json", trip), + b"", + )], + }], } } fn build_mock_rust_src_installer() -> MockInstallerBuilder { MockInstallerBuilder { - components: vec![ - MockComponentBuilder { - name: "rust-src".to_string(), - files: vec![MockFile::new("lib/rustlib/src/rust-src/foo.rs", b"")], - }, - ], + components: vec![MockComponentBuilder { + name: "rust-src".to_string(), + files: vec![MockFile::new("lib/rustlib/src/rust-src/foo.rs", b"")], + }], } } diff --git a/src/rustup-mock/src/dist.rs b/src/rustup-mock/src/dist.rs index 2bb8169bfe..b9dd947fdb 100644 --- a/src/rustup-mock/src/dist.rs +++ b/src/rustup-mock/src/dist.rs @@ -2,19 +2,19 @@ //! distribution server, with v1 and v2 manifests. use crate::MockInstallerBuilder; -use url::Url; +use flate2; +use sha2::{Digest, Sha256}; use std::collections::HashMap; use std::fs::{self, File}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::sync::Mutex; +use tar; use tempdir::TempDir; -use sha2::{Digest, Sha256}; use toml; -use flate2; -use xz2; -use tar; +use url::Url; use walkdir; +use xz2; use crate::clitools::hard_link; @@ -204,8 +204,7 @@ impl MockDistServer { // Tarball creation can be super slow, so cache created tarballs // globally to avoid recreating and recompressing tons of tarballs. lazy_static! { - static ref TARBALLS: Mutex, String)>> = + static ref TARBALLS: Mutex, String)>> = Mutex::new(HashMap::new()); } @@ -327,7 +326,8 @@ impl MockDistServer { } else { format!("{}-{}.tar.gz", package.name, channel.name) }; - let path = self.path + let path = self + .path .join("dist") .join(&channel.date) .join(package_file_name); @@ -415,7 +415,8 @@ impl MockDistServer { let ref archive_manifest_path = self.path.join(format!("{}.toml", archive_manifest_name)); hard_link(manifest_path, archive_manifest_path).unwrap(); - let ref archive_hash_path = self.path + let ref archive_hash_path = self + .path .join(format!("{}.toml.sha256", archive_manifest_name)); hard_link(hash_path, archive_hash_path).unwrap(); } diff --git a/src/rustup-mock/src/lib.rs b/src/rustup-mock/src/lib.rs index 42d914203a..fc39965e75 100644 --- a/src/rustup-mock/src/lib.rs +++ b/src/rustup-mock/src/lib.rs @@ -17,8 +17,8 @@ extern crate winapi; #[cfg(windows)] extern crate winreg; -pub mod dist; pub mod clitools; +pub mod dist; use std::fs::{self, File, OpenOptions}; use std::io::Write; @@ -144,10 +144,12 @@ impl MockFile { pub fn build(&self, path: &Path) { let path = path.join(&self.path); match self.contents { - Contents::Dir(ref files) => for &(ref name, ref contents) in files { - let fname = path.join(name); - contents.build(&fname); - }, + Contents::Dir(ref files) => { + for &(ref name, ref contents) in files { + let fname = path.join(name); + contents.build(&fname); + } + } Contents::File(ref contents) => contents.build(&path), } } @@ -176,11 +178,12 @@ impl MockContents { #[cfg(windows)] pub fn get_path() -> Option { - use winreg::RegKey; use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); environment.get_value("PATH").ok() @@ -188,11 +191,12 @@ pub fn get_path() -> Option { #[cfg(windows)] pub fn restore_path(p: &Option) { - use winreg::{RegKey, RegValue}; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::{RegKey, RegValue}; let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); if let Some(p) = p.as_ref() { diff --git a/src/rustup-utils/src/errors.rs b/src/rustup-utils/src/errors.rs index 10995bf028..38ed04d1dc 100644 --- a/src/rustup-utils/src/errors.rs +++ b/src/rustup-utils/src/errors.rs @@ -1,7 +1,7 @@ -use std::path::PathBuf; +use download; use std::ffi::OsString; +use std::path::PathBuf; use url::Url; -use download; error_chain! { links { diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index 932d635492..9038c44058 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -21,9 +21,9 @@ extern crate libc; pub mod errors; pub mod notifications; pub mod raw; +pub mod toml_utils; pub mod tty; pub mod utils; -pub mod toml_utils; pub use crate::errors::*; pub use crate::notifications::Notification; diff --git a/src/rustup-utils/src/notifications.rs b/src/rustup-utils/src/notifications.rs index 234c0ac0ab..b6590c89fc 100644 --- a/src/rustup-utils/src/notifications.rs +++ b/src/rustup-utils/src/notifications.rs @@ -1,5 +1,5 @@ -use std::path::Path; use std::fmt::{self, Display}; +use std::path::Path; use url::Url; diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index 9628f78b67..fcff9d6533 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -6,8 +6,8 @@ use std::error; use std::ffi::{OsStr, OsString}; use std::fmt; use std::fs; -use std::io::Write; use std::io; +use std::io::Write; use std::path::Path; use std::process::{Command, ExitStatus}; use std::str; @@ -176,14 +176,14 @@ pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> { #[cfg(windows)] #[allow(non_snake_case)] fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { + use std::os::windows::ffi::OsStrExt; + use std::ptr; use winapi::shared::minwindef::*; use winapi::um::fileapi::*; use winapi::um::ioapiset::*; use winapi::um::winbase::*; use winapi::um::winioctl::FSCTL_SET_REPARSE_POINT; use winapi::um::winnt::*; - use std::ptr; - use std::os::windows::ffi::OsStrExt; const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; @@ -359,8 +359,8 @@ pub fn find_cmd<'a>(cmds: &[&'a str]) -> Option<&'a str> { pub fn open_browser(path: &Path) -> io::Result { #[cfg(not(windows))] fn inner(path: &Path) -> io::Result { - use std::process::Stdio; use std::env; + use std::process::Stdio; let env_browser = env::var_os("BROWSER").map(|b| env::split_paths(&b).collect::>()); let env_commands = env_browser @@ -389,11 +389,11 @@ pub fn open_browser(path: &Path) -> io::Result { } #[cfg(windows)] fn inner(path: &Path) -> io::Result { + use std::ptr; use winapi::ctypes; - use winapi::shared::windef::HWND; - use winapi::shared::ntdef::LPCWSTR; use winapi::shared::minwindef::HINSTANCE; - use std::ptr; + use winapi::shared::ntdef::LPCWSTR; + use winapi::shared::windef::HWND; // FIXME: When winapi has this function, use their version extern "system" { @@ -427,14 +427,14 @@ pub fn open_browser(path: &Path) -> io::Result { #[cfg(windows)] pub mod windows { - use winapi::um::{combaseapi, shlobj, shtypes}; - use winapi::shared::guiddef::GUID; + use std::ffi::{OsStr, OsString}; use std::io; + use std::os::windows::ffi::{OsStrExt, OsStringExt}; use std::path::PathBuf; use std::ptr; use std::slice; - use std::ffi::{OsStr, OsString}; - use std::os::windows::ffi::{OsStrExt, OsStringExt}; + use winapi::shared::guiddef::GUID; + use winapi::um::{combaseapi, shlobj, shtypes}; #[allow(non_upper_case_globals)] pub const FOLDERID_LocalAppData: GUID = GUID { diff --git a/src/rustup-utils/src/toml_utils.rs b/src/rustup-utils/src/toml_utils.rs index b32fdbe1ec..4b6f4ffa84 100644 --- a/src/rustup-utils/src/toml_utils.rs +++ b/src/rustup-utils/src/toml_utils.rs @@ -1,5 +1,5 @@ -use toml; use crate::errors::*; +use toml; pub fn get_value(table: &mut toml::value::Table, key: &str, path: &str) -> Result { table diff --git a/src/rustup-utils/src/utils.rs b/src/rustup-utils/src/utils.rs index 4eb443cb7a..3773d84943 100644 --- a/src/rustup-utils/src/utils.rs +++ b/src/rustup-utils/src/utils.rs @@ -1,23 +1,24 @@ use crate::errors::*; -use std::path::{Path, PathBuf}; +use crate::notifications::Notification; +use crate::raw; +use sha2::Sha256; +use std::cmp::Ord; +use std::env; +use std::ffi::OsString; use std::fs::{self, File}; use std::io::{self, Write}; +use std::path::{Path, PathBuf}; use std::process::Command; -use std::ffi::OsString; -use std::env; use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT}; -use sha2::Sha256; -use crate::notifications::Notification; -use crate::raw; +use url::Url; #[cfg(windows)] use winapi::shared::minwindef::DWORD; #[cfg(windows)] use winreg; -use std::cmp::Ord; -use url::Url; -pub use crate::raw::{find_cmd, has_cmd, if_not_empty, is_directory, is_file, path_exists, prefix_arg, - random_string}; +pub use crate::raw::{ + find_cmd, has_cmd, if_not_empty, is_directory, is_file, path_exists, prefix_arg, random_string, +}; pub struct ExitCode(pub i32); @@ -28,7 +29,8 @@ pub fn ensure_dir_exists( ) -> Result { raw::ensure_dir_exists(path, |p| { notify_handler(Notification::CreatingDirectory(name, p)) - }).chain_err(|| ErrorKind::CreatingDirectory { + }) + .chain_err(|| ErrorKind::CreatingDirectory { name: name, path: PathBuf::from(path), }) @@ -166,10 +168,10 @@ fn download_file_( resume_from_partial: bool, notify_handler: &Fn(Notification), ) -> Result<()> { - use sha2::Digest; - use std::cell::RefCell; use download::download_to_path_with_backend; use download::{self, Backend, Event}; + use sha2::Digest; + use std::cell::RefCell; notify_handler(Notification::DownloadingFile(url, path)); @@ -237,7 +239,8 @@ pub fn assert_is_file(path: &Path) -> Result<()> { if !is_file(path) { Err(ErrorKind::NotAFile { path: PathBuf::from(path), - }.into()) + } + .into()) } else { Ok(()) } @@ -247,7 +250,8 @@ pub fn assert_is_directory(path: &Path) -> Result<()> { if !is_directory(path) { Err(ErrorKind::NotADirectory { path: PathBuf::from(path), - }.into()) + } + .into()) } else { Ok(()) } @@ -289,7 +293,8 @@ pub fn symlink_file(src: &Path, dest: &Path) -> Result<()> { Err(ErrorKind::LinkingFile { src: PathBuf::from(src), dest: PathBuf::from(dest), - }.into()) + } + .into()) } pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &Fn(Notification)) -> Result<()> { @@ -344,7 +349,7 @@ pub fn ensure_file_removed(name: &'static str, path: &Path) -> Result<()> { let result = fs::remove_file(path); if let Err(err) = &result { if err.kind() == io::ErrorKind::NotFound { - return Ok(()) + return Ok(()); } } result.chain_err(|| ErrorKind::RemovingFile { @@ -424,6 +429,7 @@ pub fn to_absolute>(path: P) -> Result { // depending on whether you happened to install under msys. #[cfg(windows)] pub fn home_dir() -> Option { + use scopeguard; use std::ptr; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::errhandlingapi::GetLastError; @@ -431,7 +437,6 @@ pub fn home_dir() -> Option { use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::um::winnt::TOKEN_READ; - use scopeguard; ::std::env::var_os("USERPROFILE") .map(PathBuf::from) @@ -453,7 +458,8 @@ pub fn home_dir() -> Option { } }, os2path, - ).ok() + ) + .ok() }) } @@ -469,8 +475,8 @@ where F1: FnMut(*mut u16, DWORD) -> DWORD, F2: FnOnce(&[u16]) -> T, { - use winapi::um::errhandlingapi::{GetLastError, SetLastError}; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; + use winapi::um::errhandlingapi::{GetLastError, SetLastError}; // Start off with a stack buf but then spill over to the heap if we end up // needing more space. @@ -530,7 +536,8 @@ pub fn cargo_home() -> Result { // multirust-rs to rustup upgrade seamless. let env_var = if let Some(v) = env_var { let vv = v.to_string_lossy().to_string(); - if vv.contains(".multirust/cargo") || vv.contains(r".multirust\cargo") + if vv.contains(".multirust/cargo") + || vv.contains(r".multirust\cargo") || vv.trim().is_empty() { None @@ -650,25 +657,26 @@ pub fn do_rustup_home_upgrade() -> bool { }; // Now we're trying to move ~/.multirust to ~/.rustup - old_rustup_dir_removed && if multirust_dir_exists() { - if rustup_dir_exists() { - // There appears to be both a ~/.multirust dir and a valid ~/.rustup - // dir. Most likely because one is a symlink to the other, as configured - // below. - true - } else { - if rename_multirust_dir_to_rustup().is_ok() { - // Finally, making the hardlink from ~/.multirust back to - // ~/.rustup, for temporary compatibility. - let _ = create_legacy_multirust_symlink(); + old_rustup_dir_removed + && if multirust_dir_exists() { + if rustup_dir_exists() { + // There appears to be both a ~/.multirust dir and a valid ~/.rustup + // dir. Most likely because one is a symlink to the other, as configured + // below. true } else { - false + if rename_multirust_dir_to_rustup().is_ok() { + // Finally, making the hardlink from ~/.multirust back to + // ~/.rustup, for temporary compatibility. + let _ = create_legacy_multirust_symlink(); + true + } else { + false + } } + } else { + true } - } else { - true - } } // Creates a ~/.rustup folder and a ~/.multirust symlink @@ -716,8 +724,8 @@ pub fn delete_legacy_multirust_symlink() -> Result<()> { let oldhome = legacy_multirust_home()?; if oldhome.exists() { - let meta = - fs::symlink_metadata(&oldhome).chain_err(|| "unable to get metadata for ~/.multirust")?; + let meta = fs::symlink_metadata(&oldhome) + .chain_err(|| "unable to get metadata for ~/.multirust")?; if meta.file_type().is_symlink() { // remove_dir handles unlinking symlinks raw::remove_dir(&oldhome) @@ -785,8 +793,8 @@ pub fn string_to_winreg_bytes(s: &str) -> Vec { // conversion. #[cfg(windows)] pub fn string_from_winreg_value(val: &winreg::RegValue) -> Option { - use winreg::enums::RegType; use std::slice; + use winreg::enums::RegType; match val.vtype { RegType::REG_SZ | RegType::REG_EXPAND_SZ => { diff --git a/src/rustup-win-installer/build.rs b/src/rustup-win-installer/build.rs index 1af2175fe6..c8c8357d89 100644 --- a/src/rustup-win-installer/build.rs +++ b/src/rustup-win-installer/build.rs @@ -1,7 +1,7 @@ extern crate gcc; -use std::env; use gcc::windows_registry::{self, VsVers}; +use std::env; fn main() { println!("cargo:rustc-link-lib=dylib=msi"); diff --git a/src/rustup-win-installer/src/lib.rs b/src/rustup-win-installer/src/lib.rs index fa2d0b90ea..f6e0e03956 100644 --- a/src/rustup-win-installer/src/lib.rs +++ b/src/rustup-win-installer/src/lib.rs @@ -3,12 +3,12 @@ extern crate rustup; extern crate winapi; +use std::collections::HashMap; use std::ffi::CString; use std::path::PathBuf; -use std::collections::HashMap; -use winapi::shared::ntdef::{HRESULT, LPCWSTR, LPWSTR, PCSTR}; use winapi::shared::minwindef::{LPVOID, UINT}; +use winapi::shared::ntdef::{HRESULT, LPCWSTR, LPWSTR, PCSTR}; pub type MSIHANDLE = u32; diff --git a/src/rustup/command.rs b/src/rustup/command.rs index 0dc76c939f..71fbe5c9da 100644 --- a/src/rustup/command.rs +++ b/src/rustup/command.rs @@ -1,16 +1,16 @@ +use regex::Regex; use std::ffi::OsStr; use std::fs::File; use std::io::{self, BufRead, BufReader, Seek, SeekFrom, Write}; use std::process::{self, Command, Stdio}; use std::time::Instant; -use regex::Regex; use tempfile::tempfile; -use crate::Cfg; use crate::errors::*; use crate::notifications::*; -use rustup_utils::{self, utils::ExitCode}; use crate::telemetry::{Telemetry, TelemetryEvent}; +use crate::Cfg; +use rustup_utils::{self, utils::ExitCode}; pub fn run_command_for_dir>( cmd: Command, @@ -62,7 +62,8 @@ fn telemetry_rustc>( // FIXME rust-lang/rust#32254. It's not clear to me // when and why this is needed. - let mut cmd = cmd.stdin(Stdio::inherit()) + let mut cmd = cmd + .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(cmd_err_stdio) .spawn() diff --git a/src/rustup/config.rs b/src/rustup/config.rs index c9641eb552..96230ae4f8 100644 --- a/src/rustup/config.rs +++ b/src/rustup/config.rs @@ -1,18 +1,18 @@ -use std::path::{Path, PathBuf}; use std::borrow::Cow; use std::env; +use std::fmt::{self, Display}; use std::io; +use std::path::{Path, PathBuf}; use std::process::Command; -use std::fmt::{self, Display}; use std::sync::Arc; use crate::errors::*; use crate::notifications::*; +use crate::settings::{Settings, SettingsFile, TelemetryMode, DEFAULT_METADATA_VERSION}; +use crate::telemetry_analysis::*; +use crate::toolchain::{Toolchain, UpdateStatus}; use rustup_dist::{dist, temp}; use rustup_utils::utils; -use crate::toolchain::{Toolchain, UpdateStatus}; -use crate::telemetry_analysis::*; -use crate::settings::{Settings, SettingsFile, TelemetryMode, DEFAULT_METADATA_VERSION}; #[derive(Debug)] pub enum OverrideReason { @@ -210,11 +210,13 @@ impl Cfg { } pub fn find_default(&self) -> Result> { - let opt_name = self.settings_file + let opt_name = self + .settings_file .with(|s| Ok(s.default_toolchain.clone()))?; if let Some(name) = opt_name { - let toolchain = self.verify_toolchain(&name) + let toolchain = self + .verify_toolchain(&name) .chain_err(|| ErrorKind::ToolchainNotInstalled(name.to_string()))?; Ok(Some(toolchain)) @@ -478,7 +480,8 @@ impl Cfg { } pub fn get_default_host_triple(&self) -> Result { - Ok(self.settings_file + Ok(self + .settings_file .with(|s| { Ok(s.default_host_triple .as_ref() diff --git a/src/rustup/errors.rs b/src/rustup/errors.rs index c95c761da0..48e569c967 100644 --- a/src/rustup/errors.rs +++ b/src/rustup/errors.rs @@ -1,6 +1,6 @@ +use crate::component_for_bin; use rustup_dist::{self, temp}; use rustup_utils; -use crate::component_for_bin; use toml; error_chain! { diff --git a/src/rustup/install.rs b/src/rustup/install.rs index 36709b3440..16e18f1c8d 100644 --- a/src/rustup/install.rs +++ b/src/rustup/install.rs @@ -1,14 +1,14 @@ //! Installation and upgrade of both distribution-managed and local //! toolchains -use rustup_dist::Notification; -use rustup_dist::prefix::InstallPrefix; -use rustup_utils::utils; -use rustup_dist::temp; +use crate::errors::Result; +use rustup_dist::component::{Components, Package, TarGzPackage, Transaction}; use rustup_dist::dist; use rustup_dist::download::DownloadCfg; -use rustup_dist::component::{Components, Package, TarGzPackage, Transaction}; -use crate::errors::Result; +use rustup_dist::prefix::InstallPrefix; +use rustup_dist::temp; +use rustup_dist::Notification; +use rustup_utils::utils; use std::path::Path; #[derive(Copy, Clone)] diff --git a/src/rustup/lib.rs b/src/rustup/lib.rs index ade00cd049..ceefb512fc 100644 --- a/src/rustup/lib.rs +++ b/src/rustup/lib.rs @@ -16,16 +16,22 @@ extern crate time; extern crate toml; extern crate url; +pub use crate::config::*; pub use crate::errors::*; pub use crate::notifications::*; -pub use crate::config::*; pub use crate::toolchain::*; pub use rustup_utils::{notify, toml_utils, utils}; - // A list of all binaries which Rustup will proxy. -pub static TOOLS: &'static [&'static str] = - &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls", "cargo-clippy"]; +pub static TOOLS: &'static [&'static str] = &[ + "rustc", + "rustdoc", + "cargo", + "rust-lldb", + "rust-gdb", + "rls", + "cargo-clippy", +]; // Tools which are commonly installed by Cargo as well as rustup. We take a bit // more care with these to ensure we don't overwrite the user's previous @@ -45,13 +51,13 @@ fn component_for_bin(binary: &str) -> Option<&'static str> { } } -mod errors; -mod notifications; -mod toolchain; +pub mod command; mod config; +pub mod env_var; +mod errors; mod install; +mod notifications; pub mod settings; pub mod telemetry; -pub mod command; pub mod telemetry_analysis; -pub mod env_var; +mod toolchain; diff --git a/src/rustup/notifications.rs b/src/rustup/notifications.rs index 1f75c48dbf..7812ca7d3e 100644 --- a/src/rustup/notifications.rs +++ b/src/rustup/notifications.rs @@ -1,5 +1,5 @@ -use std::path::{Path, PathBuf}; use std::fmt::{self, Display}; +use std::path::{Path, PathBuf}; use crate::errors::*; diff --git a/src/rustup/settings.rs b/src/rustup/settings.rs index 8063ebbe0a..f88862347c 100644 --- a/src/rustup/settings.rs +++ b/src/rustup/settings.rs @@ -2,11 +2,11 @@ use crate::errors::*; use crate::notifications::*; use crate::toml_utils::*; use crate::utils; -use toml; +use std::cell::RefCell; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; -use std::cell::RefCell; use std::str::FromStr; +use toml; pub const SUPPORTED_METADATA_VERSIONS: [&'static str; 2] = ["2", "12"]; pub const DEFAULT_METADATA_VERSION: &'static str = "12"; diff --git a/src/rustup/telemetry.rs b/src/rustup/telemetry.rs index 40a3d8b61e..6536d660bc 100644 --- a/src/rustup/telemetry.rs +++ b/src/rustup/telemetry.rs @@ -1,7 +1,7 @@ use crate::errors::*; -use time; use rustup_utils::{raw, utils}; use serde_json; +use time; use std::fs; use std::path::PathBuf; diff --git a/src/rustup/telemetry_analysis.rs b/src/rustup/telemetry_analysis.rs index 699c4aa196..2e985f4295 100644 --- a/src/rustup/telemetry_analysis.rs +++ b/src/rustup/telemetry_analysis.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use std::fmt; use std::fs::File; -use std::io::BufReader; use std::io::BufRead; +use std::io::BufReader; use std::path::PathBuf; use itertools::Itertools; @@ -119,7 +119,8 @@ impl TelemetryAnalysis { pub fn import_telemery(&mut self) -> Result> { let mut events: Vec = Vec::new(); - let contents = self.telemetry_dir + let contents = self + .telemetry_dir .read_dir() .chain_err(|| ErrorKind::TelemetryAnalysisError)?; @@ -189,7 +190,8 @@ impl TelemetryAnalysis { self.rustc_statistics.rustc_execution_count += 1; rustc_durations.push(duration_ms); - let exit_count = self.rustc_statistics + let exit_count = self + .rustc_statistics .exit_codes_with_count .entry(*exit_code) .or_insert(0); @@ -243,7 +245,8 @@ impl TelemetryAnalysis { let error_list = Itertools::flatten(error_list.into_iter()); for e in error_list { - let error_count = self.rustc_statistics + let error_count = self + .rustc_statistics .error_codes_with_counts .entry(e) .or_insert(0); diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index a7a636d6b1..3cb1e5610f 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -1,24 +1,24 @@ -use crate::errors::*; -use crate::notifications::*; -use rustup_dist; -use rustup_dist::download::DownloadCfg; -use rustup_utils::utils; -use rustup_dist::prefix::InstallPrefix; -use rustup_dist::dist::ToolchainDesc; -use rustup_dist::manifestation::{Changes, Manifestation}; -use rustup_dist::manifest::Component; use crate::config::Cfg; use crate::env_var; +use crate::errors::*; use crate::install::{self, InstallMethod}; +use crate::notifications::*; use crate::telemetry; use crate::telemetry::{Telemetry, TelemetryEvent}; +use rustup_dist; +use rustup_dist::dist::ToolchainDesc; +use rustup_dist::download::DownloadCfg; +use rustup_dist::manifest::Component; +use rustup_dist::manifestation::{Changes, Manifestation}; +use rustup_dist::prefix::InstallPrefix; +use rustup_utils::utils; +use std::env; use std::env::consts::EXE_SUFFIX; +use std::ffi::OsStr; use std::ffi::OsString; -use std::process::Command; use std::path::{Path, PathBuf}; -use std::ffi::OsStr; -use std::env; +use std::process::Command; use url::Url; @@ -226,7 +226,8 @@ impl<'a> Toolchain<'a> { pub fn is_tracking(&self) -> bool { ToolchainDesc::from_str(&self.name) .ok() - .map(|d| d.is_tracking()) == Some(true) + .map(|d| d.is_tracking()) + == Some(true) } fn ensure_custom(&self) -> Result<()> { @@ -234,7 +235,8 @@ impl<'a> Toolchain<'a> { Err( ErrorKind::Dist(::rustup_dist::ErrorKind::InvalidCustomToolchainName( self.name.to_string(), - )).into(), + )) + .into(), ) } else { Ok(()) @@ -344,7 +346,8 @@ impl<'a> Toolchain<'a> { return Err(ErrorKind::BinaryNotFound( self.name.clone(), binary.to_string_lossy().into(), - ).into()); + ) + .into()); } Path::new(&binary) }; @@ -390,7 +393,8 @@ impl<'a> Toolchain<'a> { .chain_err(|| "unable to create dir to hold fallback exe")?; let fallback_file = fallback_dir.join("cargo.exe"); if fallback_file.exists() { - fs::remove_file(&fallback_file).chain_err(|| "unable to unlink old fallback exe")?; + fs::remove_file(&fallback_file) + .chain_err(|| "unable to unlink old fallback exe")?; } fs::hard_link(&src_file, &fallback_file) .chain_err(|| "unable to hard link fallback exe")?; @@ -513,10 +517,12 @@ impl<'a> Toolchain<'a> { .unwrap_or(false); // Get the component so we can check if it is available - let component_pkg = manifest.get_package(&component.short_name_in_manifest()).expect(&format!( - "manifest should contain component {}", - &component.short_name(&manifest) - )); + let component_pkg = manifest + .get_package(&component.short_name_in_manifest()) + .expect(&format!( + "manifest should contain component {}", + &component.short_name(&manifest) + )); let component_target_pkg = component_pkg .targets .get(&toolchain.target) @@ -538,10 +544,12 @@ impl<'a> Toolchain<'a> { .unwrap_or(false); // Get the component so we can check if it is available - let extension_pkg = manifest.get_package(&extension.short_name_in_manifest()).expect(&format!( - "manifest should contain extension {}", - &extension.short_name(&manifest) - )); + let extension_pkg = manifest + .get_package(&extension.short_name_in_manifest()) + .expect(&format!( + "manifest should contain extension {}", + &extension.short_name(&manifest) + )); let extension_target_pkg = extension_pkg .targets .get(&toolchain.target) @@ -651,12 +659,11 @@ impl<'a> Toolchain<'a> { if targ_pkg.extensions.contains(&wildcard_component) { component = wildcard_component; } else { - return Err( - ErrorKind::UnknownComponent( - self.name.to_string(), - component.description(&manifest), - ).into(), - ); + return Err(ErrorKind::UnknownComponent( + self.name.to_string(), + component.description(&manifest), + ) + .into()); } } @@ -708,12 +715,11 @@ impl<'a> Toolchain<'a> { .expect("installed manifest should have a known target"); if targ_pkg.components.contains(&component) { - return Err( - ErrorKind::RemovingRequiredComponent( - self.name.to_string(), - component.description(&manifest), - ).into(), - ); + return Err(ErrorKind::RemovingRequiredComponent( + self.name.to_string(), + component.description(&manifest), + ) + .into()); } let dist_config = manifestation.read_config()?.unwrap(); @@ -722,12 +728,11 @@ impl<'a> Toolchain<'a> { if dist_config.components.contains(&wildcard_component) { component = wildcard_component; } else { - return Err( - ErrorKind::UnknownComponent( - self.name.to_string(), - component.description(&manifest), - ).into(), - ); + return Err(ErrorKind::UnknownComponent( + self.name.to_string(), + component.description(&manifest), + ) + .into()); } } diff --git a/tests/cli-exact.rs b/tests/cli-exact.rs index a833d12577..5d2ccaaa99 100644 --- a/tests/cli-exact.rs +++ b/tests/cli-exact.rs @@ -6,10 +6,15 @@ extern crate rustup_mock; extern crate rustup_utils; extern crate tempdir; -use rustup_mock::clitools::{self, expect_err_ex, expect_ok, expect_ok_ex, this_host_triple, - Config, Scenario}; - -macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) } +use rustup_mock::clitools::{ + self, expect_err_ex, expect_ok, expect_ok_ex, this_host_triple, Config, Scenario, +}; + +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} fn setup(f: &Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 4aaf05ec6d..3b52015522 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -6,11 +6,11 @@ extern crate rustup_mock; extern crate rustup_utils; extern crate scopeguard; -use std::sync::Mutex; -use std::process::Stdio; -use std::io::Write; use rustup_mock::clitools::{self, expect_stdout_ok, Config, SanitizedOutput, Scenario}; use rustup_mock::{get_path, restore_path}; +use std::io::Write; +use std::process::Stdio; +use std::sync::Mutex; pub fn setup(f: &Fn(&Config)) { clitools::setup(Scenario::SimpleV2, &|config| { @@ -130,10 +130,9 @@ fn with_no_modify_path() { setup(&|config| { let out = run_input(config, &["rustup-init", "--no-modify-path"], "\n\n"); assert!(out.ok); - assert!( - out.stdout - .contains("This path needs to be in your PATH environment variable") - ); + assert!(out + .stdout + .contains("This path needs to be in your PATH environment variable")); if cfg!(unix) { assert!(!config.homedir.join(".profile").exists()); diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 0896c6d5bc..08aa775bf1 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -7,19 +7,24 @@ extern crate rustup_utils; extern crate tempdir; extern crate time; -use rustup_mock::clitools::{self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, - expect_stdout_ok, expect_timeout_ok, run, set_current_dist_date, - this_host_triple, Config, Scenario}; +use rustup_mock::clitools::{ + self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, expect_stdout_ok, + expect_timeout_ok, run, set_current_dist_date, this_host_triple, Config, Scenario, +}; use rustup_utils::{raw, utils}; +use std::env::consts::EXE_SUFFIX; use std::ops::Add; use std::ops::Sub; use std::time::Duration as StdDuration; -use std::env::consts::EXE_SUFFIX; use tempdir::TempDir; use time::Duration; -macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) } +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} pub fn setup(f: &Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); @@ -147,21 +152,21 @@ fn upgrade_toml_settings() { "rustup's metadata is out of date. run `rustup self upgrade-data`", ); // Replace the metadata version - assert!(!rustup_utils::raw::is_file(&config - .rustupdir - .join("version"))); - assert!(!rustup_utils::raw::is_file(&config - .rustupdir - .join("default"))); - assert!(!rustup_utils::raw::is_file(&config - .rustupdir - .join("overrides"))); - assert!(!rustup_utils::raw::is_file(&config - .rustupdir - .join("telemetry-on"))); - assert!(rustup_utils::raw::is_file(&config - .rustupdir - .join("settings.toml"))); + assert!(!rustup_utils::raw::is_file( + &config.rustupdir.join("version") + )); + assert!(!rustup_utils::raw::is_file( + &config.rustupdir.join("default") + )); + assert!(!rustup_utils::raw::is_file( + &config.rustupdir.join("overrides") + )); + assert!(!rustup_utils::raw::is_file( + &config.rustupdir.join("telemetry-on") + )); + assert!(rustup_utils::raw::is_file( + &config.rustupdir.join("settings.toml") + )); let content = rustup_utils::raw::read_file(&config.rustupdir.join("settings.toml")).unwrap(); @@ -613,12 +618,7 @@ fn rename_rls_list() { expect_ok(config, &["rustup", "update", "--no-self-update"]); expect_ok(config, &["rustup", "component", "add", "rls"]); - let out = run( - config, - "rustup", - &["component", "list"], - &[], - ); + let out = run(config, "rustup", &["component", "list"], &[]); assert!(out.ok); assert!(out.stdout.contains(&format!("rls-{}", this_host_triple()))); }); @@ -634,12 +634,7 @@ fn rename_rls_preview_list() { expect_ok(config, &["rustup", "update", "--no-self-update"]); expect_ok(config, &["rustup", "component", "add", "rls-preview"]); - let out = run( - config, - "rustup", - &["component", "list"], - &[], - ); + let out = run(config, "rustup", &["component", "list"], &[]); assert!(out.ok); assert!(out.stdout.contains(&format!("rls-{}", this_host_triple()))); }); @@ -657,12 +652,20 @@ fn rename_rls_remove() { expect_ok(config, &["rustup", "component", "add", "rls"]); expect_ok(config, &["rls", "--version"]); expect_ok(config, &["rustup", "component", "remove", "rls"]); - expect_err(config, &["rls", "--version"], &format!("'rls{}' is not installed", EXE_SUFFIX)); + expect_err( + config, + &["rls", "--version"], + &format!("'rls{}' is not installed", EXE_SUFFIX), + ); expect_ok(config, &["rustup", "component", "add", "rls"]); expect_ok(config, &["rls", "--version"]); expect_ok(config, &["rustup", "component", "remove", "rls-preview"]); - expect_err(config, &["rls", "--version"], &format!("'rls{}' is not installed", EXE_SUFFIX)); + expect_err( + config, + &["rls", "--version"], + &format!("'rls{}' is not installed", EXE_SUFFIX), + ); }); } @@ -685,14 +688,12 @@ fn install_stops_if_rustc_exists() { ], ); assert!(!out.ok); - assert!( - out.stderr - .contains("it looks like you have an existing installation of Rust at:") - ); - assert!( - out.stderr - .contains("if this is what you want, restart the installation with `-y'") - ); + assert!(out + .stderr + .contains("it looks like you have an existing installation of Rust at:")); + assert!(out + .stderr + .contains("if this is what you want, restart the installation with `-y'")); }); } @@ -715,14 +716,12 @@ fn install_stops_if_cargo_exists() { ], ); assert!(!out.ok); - assert!( - out.stderr - .contains("it looks like you have an existing installation of Rust at:") - ); - assert!( - out.stderr - .contains("if this is what you want, restart the installation with `-y'") - ); + assert!(out + .stderr + .contains("it looks like you have an existing installation of Rust at:")); + assert!(out + .stderr + .contains("if this is what you want, restart the installation with `-y'")); }); } @@ -752,8 +751,8 @@ fn with_no_prompt_install_succeeds_if_rustc_exists() { #[test] #[cfg(any(unix, windows))] fn toolchain_broken_symlink() { - use std::path::Path; use std::fs; + use std::path::Path; #[cfg(unix)] fn create_symlink_dir, Q: AsRef>(src: P, dst: Q) { diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index c9ee904e74..e43000cb45 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -5,16 +5,21 @@ extern crate rustup_mock; extern crate rustup_utils; extern crate tempdir; -use std::fs; +use rustup_mock::clitools::{ + self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, expect_stdout_ok, + set_current_dist_date, this_host_triple, Config, Scenario, +}; +use rustup_utils::raw; use std::env::consts::EXE_SUFFIX; +use std::fs; use std::path::MAIN_SEPARATOR; use std::process; -use rustup_utils::raw; -use rustup_mock::clitools::{self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, - expect_stdout_ok, set_current_dist_date, this_host_triple, Config, - Scenario}; -macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) } +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} pub fn setup(f: &Fn(&Config)) { clitools::setup(Scenario::ArchivesV2, &|config| { @@ -865,12 +870,7 @@ fn show_active_toolchain() { #[test] fn show_active_toolchain_none() { setup(&|config| { - expect_ok_ex( - config, - &["rustup", "show", "active-toolchain"], - r"", - r"", - ); + expect_ok_ex(config, &["rustup", "show", "active-toolchain"], r"", r""); }); } @@ -1092,12 +1092,10 @@ fn multirust_dir_upgrade_rename_multirust_dir_to_rustup() { assert!(String::from_utf8(out.stdout).unwrap().contains("stable")); assert!(multirust_dir.exists()); - assert!( - fs::symlink_metadata(&multirust_dir) - .unwrap() - .file_type() - .is_symlink() - ); + assert!(fs::symlink_metadata(&multirust_dir) + .unwrap() + .file_type() + .is_symlink()); assert!(rustup_dir.exists()); }); } @@ -1140,12 +1138,10 @@ fn multirust_dir_upgrade_old_rustup_exists() { assert!(String::from_utf8(out.stdout).unwrap().contains("stable")); assert!(multirust_dir.exists()); - assert!( - fs::symlink_metadata(&multirust_dir) - .unwrap() - .file_type() - .is_symlink() - ); + assert!(fs::symlink_metadata(&multirust_dir) + .unwrap() + .file_type() + .is_symlink()); assert!(rustup_dir.exists()); assert!(!old_rustup_sh_version_file.exists()); assert!(new_rustup_sh_version_file.exists()); @@ -1201,12 +1197,10 @@ fn multirust_dir_upgrade_old_rustup_existsand_new_rustup_sh_exists() { // .multirust is now a symlink to .rustup assert!(multirust_dir.exists()); - assert!( - fs::symlink_metadata(&multirust_dir) - .unwrap() - .file_type() - .is_symlink() - ); + assert!(fs::symlink_metadata(&multirust_dir) + .unwrap() + .file_type() + .is_symlink()); assert!(rustup_dir.exists()); assert!(!old_rustup_sh_version_file.exists()); @@ -1230,12 +1224,10 @@ fn multirust_upgrade_works_with_proxy() { run_no_home(config, &["rustc", "--version"], &[]); assert!(multirust_dir.exists()); - assert!( - fs::symlink_metadata(&multirust_dir) - .unwrap() - .file_type() - .is_symlink() - ); + assert!(fs::symlink_metadata(&multirust_dir) + .unwrap() + .file_type() + .is_symlink()); assert!(rustup_dir.exists()); }); } diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index e8e499fa63..e5172d4851 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -17,22 +17,27 @@ extern crate winapi; #[cfg(windows)] extern crate winreg; -use tempdir::TempDir; -use std::sync::Mutex; -use std::env; -use std::env::consts::EXE_SUFFIX; -use std::path::Path; -use std::fs; -use std::process::Command; use remove_dir_all::remove_dir_all; -use rustup_mock::clitools::{self, expect_err, expect_err_ex, expect_ok, expect_ok_contains, - expect_ok_ex, expect_stderr_ok, expect_stdout_ok, this_host_triple, - Config, Scenario}; +use rustup_mock::clitools::{ + self, expect_err, expect_err_ex, expect_ok, expect_ok_contains, expect_ok_ex, expect_stderr_ok, + expect_stdout_ok, this_host_triple, Config, Scenario, +}; use rustup_mock::dist::calc_hash; use rustup_mock::{get_path, restore_path}; use rustup_utils::{raw, utils}; +use std::env; +use std::env::consts::EXE_SUFFIX; +use std::fs; +use std::path::Path; +use std::process::Command; +use std::sync::Mutex; +use tempdir::TempDir; -macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) } +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} const TEST_VERSION: &'static str = "1.1.1"; @@ -530,19 +535,21 @@ fn install_doesnt_modify_path_if_passed_no_modify_path() { #[test] #[cfg(windows)] fn install_doesnt_modify_path_if_passed_no_modify_path() { - use winreg::RegKey; use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; setup(&|config| { let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let old_path = environment.get_raw_value("PATH").unwrap(); expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let new_path = environment.get_raw_value("PATH").unwrap(); @@ -556,7 +563,8 @@ fn update_exact() { let expected_output = &(r"info: checking for self-updates info: downloading self-update info: rustup updated successfully to " - .to_owned() + version + .to_owned() + + version + " "); @@ -996,14 +1004,15 @@ fn rustup_init_works_with_weird_names() { #[test] #[cfg(windows)] fn doesnt_write_wrong_path_type_to_reg() { - use winreg::RegKey; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; setup(&|config| { expect_ok(config, &["rustup-init", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH").unwrap(); assert!(path.vtype == RegType::REG_EXPAND_SZ); @@ -1011,7 +1020,8 @@ fn doesnt_write_wrong_path_type_to_reg() { expect_ok(config, &["rustup", "self", "uninstall", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH").unwrap(); assert!(path.vtype == RegType::REG_EXPAND_SZ); @@ -1023,19 +1033,21 @@ fn doesnt_write_wrong_path_type_to_reg() { #[test] #[cfg(windows)] fn windows_handle_empty_path_registry_key() { - use winreg::RegKey; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; setup(&|config| { let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let _ = environment.delete_value("PATH"); expect_ok(config, &["rustup-init", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH").unwrap(); assert!(path.vtype == RegType::REG_EXPAND_SZ); @@ -1043,7 +1055,8 @@ fn windows_handle_empty_path_registry_key() { expect_ok(config, &["rustup", "self", "uninstall", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH"); @@ -1054,12 +1067,13 @@ fn windows_handle_empty_path_registry_key() { #[test] #[cfg(windows)] fn windows_uninstall_removes_semicolon_from_path() { - use winreg::RegKey; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::RegKey; setup(&|config| { let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); // This time set the value of PATH and make sure it's restored exactly after uninstall, @@ -1069,7 +1083,8 @@ fn windows_uninstall_removes_semicolon_from_path() { expect_ok(config, &["rustup-init", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH").unwrap(); assert!(path.vtype == RegType::REG_EXPAND_SZ); @@ -1077,7 +1092,8 @@ fn windows_uninstall_removes_semicolon_from_path() { expect_ok(config, &["rustup", "self", "uninstall", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path: String = environment.get_value("PATH").unwrap(); assert!(path == "foo"); @@ -1087,18 +1103,21 @@ fn windows_uninstall_removes_semicolon_from_path() { #[test] #[cfg(windows)] fn install_doesnt_mess_with_a_non_unicode_path() { - use winreg::{RegKey, RegValue}; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::{RegKey, RegValue}; setup(&|config| { let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let reg_value = RegValue { - bytes: vec![0x00, 0xD8, // leading surrogate - 0x01, 0x01, // bogus trailing surrogate - 0x00, 0x00], // null + bytes: vec![ + 0x00, 0xD8, // leading surrogate + 0x01, 0x01, // bogus trailing surrogate + 0x00, 0x00, + ], // null vtype: RegType::REG_EXPAND_SZ, }; environment.set_raw_value("PATH", ®_value).unwrap(); @@ -1108,7 +1127,8 @@ fn install_doesnt_mess_with_a_non_unicode_path() { Not modifying the PATH variable"); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH").unwrap(); assert!(path.bytes == reg_value.bytes); @@ -1118,20 +1138,23 @@ fn install_doesnt_mess_with_a_non_unicode_path() { #[test] #[cfg(windows)] fn uninstall_doesnt_mess_with_a_non_unicode_path() { - use winreg::{RegKey, RegValue}; use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; + use winreg::{RegKey, RegValue}; setup(&|config| { expect_ok(config, &["rustup-init", "-y"]); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let reg_value = RegValue { - bytes: vec![0x00, 0xD8, // leading surrogate - 0x01, 0x01, // bogus trailing surrogate - 0x00, 0x00], // null + bytes: vec![ + 0x00, 0xD8, // leading surrogate + 0x01, 0x01, // bogus trailing surrogate + 0x00, 0x00, + ], // null vtype: RegType::REG_EXPAND_SZ, }; environment.set_raw_value("PATH", ®_value).unwrap(); @@ -1141,7 +1164,8 @@ fn uninstall_doesnt_mess_with_a_non_unicode_path() { Not modifying the PATH variable"); let root = RegKey::predef(HKEY_CURRENT_USER); - let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) + let environment = root + .open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE) .unwrap(); let path = environment.get_raw_value("PATH").unwrap(); assert!(path.bytes == reg_value.bytes); @@ -1222,12 +1246,10 @@ fn install_creates_legacy_home_symlink() { assert!(rustup_dir.exists()); let multirust_dir = config.homedir.join(".multirust"); assert!(multirust_dir.exists()); - assert!( - fs::symlink_metadata(&multirust_dir) - .unwrap() - .file_type() - .is_symlink() - ); + assert!(fs::symlink_metadata(&multirust_dir) + .unwrap() + .file_type() + .is_symlink()); }); } @@ -1267,12 +1289,10 @@ fn install_over_unupgraded_multirust_dir() { // Directories should be set up correctly assert!(rustup_dir.exists()); assert!(multirust_dir.exists()); - assert!( - fs::symlink_metadata(&multirust_dir) - .unwrap() - .file_type() - .is_symlink() - ); + assert!(fs::symlink_metadata(&multirust_dir) + .unwrap() + .file_type() + .is_symlink()); // We should still be on nightly let mut cmd = clitools::cmd(config, "rustc", &["--version"]); @@ -1376,7 +1396,9 @@ fn update_installs_clippy_cargo_and() { let version = env!("CARGO_PKG_VERSION"); output_release_file(self_dist, "1", version); - let ref cargo_clippy_path = config.cargodir.join(format!("bin/cargo-clippy{}", EXE_SUFFIX)); + let ref cargo_clippy_path = config + .cargodir + .join(format!("bin/cargo-clippy{}", EXE_SUFFIX)); assert!(cargo_clippy_path.exists()); }); } diff --git a/tests/cli-v1.rs b/tests/cli-v1.rs index 490f57e42e..33b7d1be78 100644 --- a/tests/cli-v1.rs +++ b/tests/cli-v1.rs @@ -6,12 +6,18 @@ extern crate rustup_mock; extern crate rustup_utils; extern crate tempdir; +use rustup_mock::clitools::{ + self, expect_err, expect_ok, expect_stderr_ok, expect_stdout_ok, set_current_dist_date, + this_host_triple, Config, Scenario, +}; use std::fs; use tempdir::TempDir; -use rustup_mock::clitools::{self, expect_err, expect_ok, expect_stderr_ok, expect_stdout_ok, - set_current_dist_date, this_host_triple, Config, Scenario}; -macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) } +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} pub fn setup(f: &Fn(&mut Config)) { clitools::setup(Scenario::SimpleV1, f); diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index ef83821ae1..173d360a0f 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -6,15 +6,20 @@ extern crate rustup_mock; extern crate rustup_utils; extern crate tempdir; +use rustup_mock::clitools::{ + self, expect_err, expect_not_stdout_ok, expect_ok, expect_stderr_ok, expect_stdout_ok, + set_current_dist_date, this_host_triple, Config, Scenario, +}; use std::fs; use tempdir::TempDir; -use rustup_mock::clitools::{self, expect_err, expect_not_stdout_ok, expect_ok, expect_stderr_ok, - expect_stdout_ok, set_current_dist_date, this_host_triple, Config, - Scenario}; use rustup_dist::dist::TargetTriple; -macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) } +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} pub fn setup(f: &Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); @@ -787,7 +792,6 @@ fn remove_target_host() { // Issue #304 fn remove_target_missing_update_hash() { setup(&|config| { - expect_ok(config, &["rustup", "update", "nightly"]); let file_name = format!("nightly-{}", this_host_triple());