-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(config)!: use unqualified names for default_toolchain
#4947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8055ce0
4f396da
11a6ee8
5616ba4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,6 @@ use crate::{ | |
| process::Process, | ||
| toolchain::{ | ||
| DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain, | ||
| ToolchainName, | ||
| }, | ||
| utils::{self, ExitCode}, | ||
| }; | ||
|
|
@@ -252,7 +251,8 @@ impl InstallOpts<'_> { | |
|
|
||
| let (components, targets) = (self.components, self.targets); | ||
| let toolchain = self.select_toolchain(cfg)?; | ||
| if let Some(desc) = toolchain { | ||
| if let Some(partial_desc) = toolchain { | ||
| let desc = partial_desc.clone().resolve(&cfg.default_host_tuple()?)?; | ||
| let options = | ||
| DistOptions::new(components, targets, &desc, cfg.get_profile()?, true, cfg)?; | ||
| let status = if Toolchain::exists(cfg, &desc.clone().into())? { | ||
|
|
@@ -272,7 +272,7 @@ impl InstallOpts<'_> { | |
|
|
||
| check_proxy_sanity(cfg.process, components, &desc)?; | ||
|
|
||
| cfg.set_default(Some(&desc.clone().into()))?; | ||
| cfg.set_default(Some(&partial_desc.into()))?; | ||
| writeln!(cfg.process.stdout().lock())?; | ||
| common::show_channel_update(cfg, PackageUpdate::Toolchain(desc), Ok(status))?; | ||
| } | ||
|
|
@@ -284,7 +284,7 @@ impl InstallOpts<'_> { | |
| /// This function first initializes the default profile and default host tuple in the | ||
| /// configuration, then returns the toolchain that should be installed, or `None` if none is | ||
| /// specified by the user. | ||
| fn select_toolchain(self, cfg: &mut Cfg<'_>) -> Result<Option<ToolchainDesc>> { | ||
| fn select_toolchain(self, cfg: &mut Cfg<'_>) -> Result<Option<PartialToolchainDesc>> { | ||
| let Self { | ||
| default_host_tuple, | ||
| default_toolchain, | ||
|
|
@@ -342,18 +342,14 @@ impl InstallOpts<'_> { | |
| MaybeOfficialToolchainName::None => unreachable!(), | ||
| MaybeOfficialToolchainName::Some(n) => n, | ||
| }; | ||
| Some(toolchain_name.resolve(&cfg.default_host_tuple()?)?) | ||
| Some(toolchain_name) | ||
| } | ||
| None => match cfg.get_default()? { | ||
| None => match cfg.get_default_resolvable()? { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does |
||
| // Default is installable | ||
| Some(ToolchainName::Official(t)) => Some(t), | ||
| Some(ResolvableToolchainName::Official(t)) => Some(t), | ||
| // Default is custom, presumably from a prior install. Do nothing. | ||
| Some(ToolchainName::Custom(_)) => None, | ||
| None => Some( | ||
| "stable" | ||
| .parse::<PartialToolchainDesc>()? | ||
| .resolve(&cfg.default_host_tuple()?)?, | ||
| ), | ||
| Some(ResolvableToolchainName::Custom(_)) => None, | ||
| None => Some(PartialToolchainDesc::from_str("stable")?), | ||
|
rami3l marked this conversation as resolved.
|
||
| }, | ||
| }) | ||
| } else { | ||
|
|
@@ -1376,11 +1372,7 @@ mod tests { | |
| }; | ||
|
|
||
| assert_eq!( | ||
| "stable" | ||
| .parse::<PartialToolchainDesc>() | ||
| .unwrap() | ||
| .resolve(&cfg.default_host_tuple().unwrap()) | ||
| .unwrap(), | ||
| "stable".parse::<PartialToolchainDesc>().unwrap(), | ||
| opts.select_toolchain(&mut cfg) | ||
| .unwrap() // result | ||
| .unwrap() // option | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -384,7 +384,7 @@ impl<'a> Cfg<'a> { | |
| Ok(cfg) | ||
| } | ||
|
|
||
| pub(crate) fn set_default(&self, toolchain: Option<&ToolchainName>) -> Result<()> { | ||
| pub(crate) fn set_default(&self, toolchain: Option<&ResolvableToolchainName>) -> Result<()> { | ||
| self.settings_file.with_mut(|s| { | ||
| s.default_toolchain = toolchain.map(|t| t.to_string()); | ||
| Ok(()) | ||
|
|
@@ -904,6 +904,16 @@ impl<'a> Cfg<'a> { | |
| /// If none is configured, returns None | ||
| /// If a bad toolchain name is configured, errors. | ||
| pub(crate) fn get_default(&self) -> Result<Option<ToolchainName>> { | ||
| let Some(toolchain) = self.get_default_resolvable()? else { | ||
| return Ok(None); | ||
| }; | ||
| Ok(Some(toolchain.resolve(&self.default_host_tuple()?)?)) | ||
| } | ||
|
|
||
| /// Gets the configured default toolchain. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: documentation comment style. Also, duplicating the documentation comment from |
||
| /// If none is configured, returns None | ||
| /// If a bad toolchain name is configured, errors. | ||
| pub(crate) fn get_default_resolvable(&self) -> Result<Option<ResolvableToolchainName>> { | ||
| let user_opt = self.settings_file.with(|s| Ok(s.default_toolchain.clone())); | ||
| let toolchain_maybe_str = if let Some(fallback_settings) = &self.fallback_settings { | ||
| match user_opt { | ||
|
|
@@ -913,11 +923,10 @@ impl<'a> Cfg<'a> { | |
| } else { | ||
| user_opt | ||
| }?; | ||
| toolchain_maybe_str | ||
| .map(ResolvableToolchainName::try_from) | ||
| .transpose()? | ||
| .map(|t| t.resolve(&self.default_host_tuple()?)) | ||
| .transpose() | ||
| let Some(toolchain) = toolchain_maybe_str else { | ||
| return Ok(None); | ||
| }; | ||
| Ok(Some(ResolvableToolchainName::try_from(toolchain)?)) | ||
| } | ||
|
|
||
| /// List all the installed toolchains: that is paths in the toolchain dir | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,6 +304,17 @@ impl ResolvableLocalToolchainName { | |
| } | ||
| } | ||
|
|
||
| from_variant!( | ||
| PartialToolchainDesc, | ||
| ResolvableToolchainName, | ||
| ResolvableToolchainName::Official | ||
| ); | ||
| from_variant!( | ||
| CustomToolchainName, | ||
| ResolvableToolchainName, | ||
| ResolvableToolchainName::Custom | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of these macros and have looked several times at cleaning them up. How about just writing them out (could inline macros with Rust-Analyzer I think)? |
||
|
|
||
| try_from_str!(ResolvableLocalToolchainName); | ||
|
|
||
| impl Display for ResolvableLocalToolchainName { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.