diff --git a/doc/src/overrides.md b/doc/src/overrides.md index 9d6d7b64e1..e0e869937f 100644 --- a/doc/src/overrides.md +++ b/doc/src/overrides.md @@ -82,6 +82,7 @@ called `rust-toolchain`, the content of which is either the name of a single channel = "nightly-2020-07-10" components = [ "rustfmt", "rustc-dev" ] targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ] +profile = "minimal" ``` If the TOML format is used, the `[toolchain]` section is mandatory, and at diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index f6d6363af2..c3dd100ab5 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -949,6 +949,7 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result { m.is_present("allow-downgrade"), &components, &targets, + None, )?) } else if !toolchain.exists() { return Err(ErrorKind::InvalidToolchainName(toolchain.name().to_string()).into()); diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index bff0eb50eb..d42febdb7f 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -738,7 +738,7 @@ fn maybe_install_rust( warn!("Updating existing toolchain, profile choice will be ignored"); } let distributable = DistributableToolchain::new(&toolchain)?; - let status = distributable.install_from_dist(true, false, components, targets)?; + let status = distributable.install_from_dist(true, false, components, targets, None)?; let toolchain_str = toolchain.name().to_owned(); toolchain.cfg().set_default(&toolchain_str)?; writeln!(process().stdout())?; diff --git a/src/config.rs b/src/config.rs index 66ab0cd2bd..ecc288aa2a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,7 @@ struct ToolchainSection { channel: Option, components: Option>, targets: Option>, + profile: Option, } impl ToolchainSection { @@ -78,6 +79,7 @@ struct OverrideCfg<'a> { toolchain: Option>, components: Vec, targets: Vec, + profile: Option, } impl<'a> OverrideCfg<'a> { @@ -89,6 +91,12 @@ impl<'a> OverrideCfg<'a> { }, components: file.toolchain.components.unwrap_or_default(), targets: file.toolchain.targets.unwrap_or_default(), + profile: file + .toolchain + .profile + .as_deref() + .map(dist::Profile::from_str) + .transpose()?, }) } } @@ -660,13 +668,14 @@ impl Cfg { } } - if let Some((toolchain, components, targets, reason)) = + if let Some((toolchain, components, targets, reason, profile)) = match self.find_override_config(path)? { Some(( OverrideCfg { toolchain, components, targets, + profile, }, reason, )) => { @@ -678,11 +687,11 @@ impl Cfg { toolchain .or(default) - .map(|toolchain| (toolchain, components, targets, Some(reason))) + .map(|toolchain| (toolchain, components, targets, Some(reason), profile)) } None => self .find_default()? - .map(|toolchain| (toolchain, vec![], vec![], None)), + .map(|toolchain| (toolchain, vec![], vec![], None, None)), } { if toolchain.is_custom() { @@ -698,7 +707,7 @@ impl Cfg { let distributable = DistributableToolchain::new(&toolchain)?; if !toolchain.exists() || !components_exist(&distributable, &components, &targets)? { - distributable.install_from_dist(true, false, &components, &targets)?; + distributable.install_from_dist(true, false, &components, &targets, profile)?; } } @@ -760,7 +769,7 @@ impl Cfg { let channels = channels.map(|(n, t)| { let st = t.and_then(|t| { let distributable = DistributableToolchain::new(&t)?; - let st = distributable.install_from_dist(force_update, false, &[], &[]); + let st = distributable.install_from_dist(force_update, false, &[], &[], None); if let Err(ref e) = st { (self.notify_handler)(Notification::NonFatalError(e)); } @@ -815,7 +824,7 @@ impl Cfg { let toolchain = self.get_toolchain(toolchain, false)?; if install_if_missing && !toolchain.exists() { let distributable = DistributableToolchain::new(&toolchain)?; - distributable.install_from_dist(true, false, &[], &[])?; + distributable.install_from_dist(true, false, &[], &[], None)?; } if let Some(cmd) = self.maybe_do_cargo_fallback(&toolchain, binary)? { @@ -911,6 +920,7 @@ mod tests { channel: Some(contents.into()), components: None, targets: None, + profile: None, } } ); @@ -922,6 +932,7 @@ mod tests { channel = "nightly-2020-07-10" components = [ "rustfmt", "rustc-dev" ] targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ] +profile = "default" "#; let result = Cfg::parse_override_file(contents); @@ -935,6 +946,7 @@ targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ] "wasm32-unknown-unknown".into(), "thumbv2-none-eabi".into() ]), + profile: Some("default".into()), } } ); @@ -954,6 +966,7 @@ channel = "nightly-2020-07-10" channel: Some("nightly-2020-07-10".into()), components: None, targets: None, + profile: None, } } ); @@ -974,6 +987,7 @@ components = [] channel: Some("nightly-2020-07-10".into()), components: Some(vec![]), targets: None, + profile: None, } } ); @@ -994,6 +1008,7 @@ targets = [] channel: Some("nightly-2020-07-10".into()), components: None, targets: Some(vec![]), + profile: None, } } ); @@ -1013,6 +1028,7 @@ components = [ "rustfmt" ] channel: None, components: Some(vec!["rustfmt".into()]), targets: None, + profile: None, } } ); diff --git a/src/toolchain.rs b/src/toolchain.rs index 7410216e35..bbdee214c8 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -12,6 +12,7 @@ use wait_timeout::ChildExt; use crate::component_for_bin; use crate::config::Cfg; +use crate::dist::dist::Profile; use crate::dist::dist::TargetTriple; use crate::dist::dist::ToolchainDesc; use crate::dist::download::DownloadCfg; @@ -685,12 +686,15 @@ impl<'a> DistributableToolchain<'a> { allow_downgrade: bool, components: &[&str], targets: &[&str], + profile: Option, ) -> Result { let update_hash = self.update_hash()?; let old_date = self.get_manifest().ok().and_then(|m| m.map(|m| m.date)); InstallMethod::Dist { desc: &self.desc()?, - profile: self.0.cfg.get_profile()?, + profile: profile + .map(Ok) + .unwrap_or_else(|| self.0.cfg.get_profile())?, update_hash: Some(&update_hash), dl_cfg: self.download_cfg(), force_update, diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index a897b7a60f..5bf26882a7 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -1548,6 +1548,35 @@ components = [ "rust-bongo" ] }); } +#[test] +fn file_override_toml_format_specify_profile() { + setup(&|config| { + expect_ok(config, &["rustup", "set", "profile", "default"]); + expect_stderr_ok( + config, + &["rustup", "default", "stable"], + "downloading component 'rust-docs'", + ); + + let cwd = config.current_dir(); + let toolchain_file = cwd.join("rust-toolchain"); + raw::write_file( + &toolchain_file, + r#" +[toolchain] +profile = "minimal" +channel = "nightly" +"#, + ) + .unwrap(); + expect_not_stdout_ok( + config, + &["rustup", "component", "list"], + for_host!("rust-docs-{} (installed)"), + ); + }); +} + #[test] fn directory_override_beats_file_override() { setup(&|config| {