Skip to content

Commit

Permalink
Merge pull request #2586 from kinnison/profile-in-rust-toolchain
Browse files Browse the repository at this point in the history
Profile in rust toolchain
  • Loading branch information
kinnison authored Dec 15, 2020
2 parents fbfc454 + 5f4ca98 commit c44e884
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/src/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
m.is_present("allow-downgrade"),
&components,
&targets,
None,
)?)
} else if !toolchain.exists() {
return Err(ErrorKind::InvalidToolchainName(toolchain.name().to_string()).into());
Expand Down
2 changes: 1 addition & 1 deletion src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down
28 changes: 22 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct ToolchainSection {
channel: Option<String>,
components: Option<Vec<String>>,
targets: Option<Vec<String>>,
profile: Option<String>,
}

impl ToolchainSection {
Expand Down Expand Up @@ -78,6 +79,7 @@ struct OverrideCfg<'a> {
toolchain: Option<Toolchain<'a>>,
components: Vec<String>,
targets: Vec<String>,
profile: Option<dist::Profile>,
}

impl<'a> OverrideCfg<'a> {
Expand All @@ -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()?,
})
}
}
Expand Down Expand Up @@ -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,
)) => {
Expand All @@ -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() {
Expand All @@ -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)?;
}
}

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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)? {
Expand Down Expand Up @@ -911,6 +920,7 @@ mod tests {
channel: Some(contents.into()),
components: None,
targets: None,
profile: None,
}
}
);
Expand All @@ -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);
Expand All @@ -935,6 +946,7 @@ targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
"wasm32-unknown-unknown".into(),
"thumbv2-none-eabi".into()
]),
profile: Some("default".into()),
}
}
);
Expand All @@ -954,6 +966,7 @@ channel = "nightly-2020-07-10"
channel: Some("nightly-2020-07-10".into()),
components: None,
targets: None,
profile: None,
}
}
);
Expand All @@ -974,6 +987,7 @@ components = []
channel: Some("nightly-2020-07-10".into()),
components: Some(vec![]),
targets: None,
profile: None,
}
}
);
Expand All @@ -994,6 +1008,7 @@ targets = []
channel: Some("nightly-2020-07-10".into()),
components: None,
targets: Some(vec![]),
profile: None,
}
}
);
Expand All @@ -1013,6 +1028,7 @@ components = [ "rustfmt" ]
channel: None,
components: Some(vec!["rustfmt".into()]),
targets: None,
profile: None,
}
}
);
Expand Down
6 changes: 5 additions & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -685,12 +686,15 @@ impl<'a> DistributableToolchain<'a> {
allow_downgrade: bool,
components: &[&str],
targets: &[&str],
profile: Option<Profile>,
) -> Result<UpdateStatus> {
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,
Expand Down
29 changes: 29 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit c44e884

Please sign in to comment.