-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(config): warn user if auto-install is enabled, take 2 #4859
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
88388d1
7896281
d9ba088
a9611a3
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 |
|---|---|---|
|
|
@@ -124,6 +124,22 @@ impl Display for ActiveSource { | |
| } | ||
| } | ||
|
|
||
| /// Represents the result of an operation that may ensure the installation of a certain toolchain. | ||
| #[derive(Clone, Debug)] | ||
| pub(crate) struct Ensured<T> { | ||
|
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.
|
||
| pub inner: T, | ||
| pub status: UpdateStatus, | ||
| } | ||
|
|
||
| impl<T> Ensured<T> { | ||
| pub fn new(toolchain: impl Into<T>, status: UpdateStatus) -> Self { | ||
| Self { | ||
| inner: toolchain.into(), | ||
| status, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Represents a toolchain override from a +toolchain command line option, | ||
| // RUSTUP_TOOLCHAIN environment variable, or rust-toolchain.toml file etc. Can | ||
| // include components and targets from a rust-toolchain.toml that should be | ||
|
|
@@ -517,7 +533,11 @@ impl<'a> Cfg<'a> { | |
| } | ||
|
|
||
| match self.ensure_active_toolchain(true, false).await { | ||
| Ok(r) => Ok(Some(r)), | ||
| Ok(r) => { | ||
| let (tc, source) = r; | ||
| auto_install_warning(self.process, &tc.inner, &tc.status); | ||
| Ok(Some((tc.inner, source))) | ||
| } | ||
| Err(e) => match e.downcast_ref::<RustupError>() { | ||
| Some(RustupError::ToolchainNotSelected(_)) => Ok(None), | ||
| _ => Err(e), | ||
|
|
@@ -719,10 +739,9 @@ impl<'a> Cfg<'a> { | |
| match name { | ||
| Some((tc, source)) => { | ||
| let install_if_missing = self.should_auto_install()?; | ||
| Ok(( | ||
| Toolchain::from_local(tc, install_if_missing, self).await?, | ||
| source, | ||
| )) | ||
| let tc = Toolchain::from_local(tc, install_if_missing, self).await?; | ||
| auto_install_warning(self.process, tc.inner.name(), &tc.status); | ||
| Ok((tc.inner, source)) | ||
| } | ||
| None => { | ||
| let (tc, source) = self | ||
|
|
@@ -739,10 +758,10 @@ impl<'a> Cfg<'a> { | |
| &self, | ||
| force_non_host: bool, | ||
| verbose: bool, | ||
| ) -> Result<(LocalToolchainName, ActiveSource)> { | ||
| ) -> Result<(Ensured<LocalToolchainName>, ActiveSource)> { | ||
| if let Some((override_config, source)) = self.find_override_config()? { | ||
| let toolchain = override_config.clone().into_local_toolchain_name(); | ||
| if let OverrideCfg::Official { | ||
| let status = if let OverrideCfg::Official { | ||
| toolchain, | ||
| components, | ||
| targets, | ||
|
|
@@ -757,20 +776,24 @@ impl<'a> Cfg<'a> { | |
| force_non_host, | ||
| verbose, | ||
| ) | ||
| .await?; | ||
| .await? | ||
| .status | ||
| } else { | ||
| Toolchain::with_source(self, toolchain.clone(), &source)?; | ||
| } | ||
| Ok((toolchain, source)) | ||
| UpdateStatus::Unchanged | ||
| }; | ||
| Ok((Ensured::new(toolchain, status), source)) | ||
| } else if let Some(toolchain) = self.get_default()? { | ||
| let source = ActiveSource::Default; | ||
| if let ToolchainName::Official(desc) = &toolchain { | ||
| let status = if let ToolchainName::Official(desc) = &toolchain { | ||
| self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose) | ||
| .await?; | ||
| .await? | ||
| .status | ||
| } else { | ||
| Toolchain::with_source(self, toolchain.clone().into(), &source)?; | ||
| } | ||
| Ok((toolchain.into(), source)) | ||
| UpdateStatus::Unchanged | ||
| }; | ||
| Ok((Ensured::new(toolchain, status), source)) | ||
| } else { | ||
| Err(no_toolchain_error(self.process)) | ||
| } | ||
|
|
@@ -787,7 +810,7 @@ impl<'a> Cfg<'a> { | |
| profile: Option<Profile>, | ||
| force_non_host: bool, | ||
| verbose: bool, | ||
| ) -> Result<(UpdateStatus, Toolchain<'_>)> { | ||
| ) -> Result<Ensured<Toolchain<'_>>> { | ||
| common::check_non_host_toolchain( | ||
| toolchain.to_string(), | ||
| &TargetTuple::from_host_or_build(self.process), | ||
|
|
@@ -831,7 +854,7 @@ impl<'a> Cfg<'a> { | |
| } | ||
| Err(e) => return Err(e.into()), | ||
| }; | ||
| Ok((status, toolchain.into())) | ||
| Ok(Ensured::new(toolchain, status)) | ||
| } | ||
|
|
||
| /// Get the configured default toolchain. | ||
|
|
@@ -1003,6 +1026,19 @@ fn no_toolchain_error(process: &Process) -> anyhow::Error { | |
| RustupError::ToolchainNotSelected(process.name().unwrap_or_else(|| "Rust".into())).into() | ||
| } | ||
|
|
||
| fn auto_install_warning(process: &Process, toolchain: impl Display, status: &UpdateStatus) { | ||
|
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. Could/should this take an |
||
| // If we're already in a recursion, or we haven't just installed the active toolchain, then | ||
| // don't print the warning. | ||
| let recursions = process.var("RUST_RECURSION_COUNT"); | ||
| if recursions.is_ok_and(|it| it != "0") || !matches!(status, UpdateStatus::Installed) { | ||
| return; | ||
| } | ||
|
|
||
| warn!("the missing active toolchain `{toolchain}` has been auto-installed"); | ||
| warn!("this might cause rustup commands to take longer time to finish than expected"); | ||
| info!("you may opt out with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`"); | ||
| } | ||
|
|
||
| /// Specifies how a `rust-toolchain`/`rust-toolchain.toml` configuration file should be parsed. | ||
| enum ParseMode { | ||
| /// Only permit TOML format in a configuration file. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these be replaced by a
Derefimpl onEnsured?View changes since the review