-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor(toolchain)!: remove multiple components at once #5080
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
Changes from all commits
44f01f1
d65fc5a
2ab63b4
025d820
60aa923
41ac5d4
367c94a
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 |
|---|---|---|
|
|
@@ -25,7 +25,6 @@ use clap_complete::{ | |
| }; | ||
| use futures_util::stream::StreamExt; | ||
| use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | ||
| use itertools::Itertools; | ||
| use serde::Serialize; | ||
| use tokio::sync::Semaphore; | ||
| use tracing::{info, warn}; | ||
|
|
@@ -551,7 +550,7 @@ enum TargetSubcmd { | |
| Remove { | ||
| /// List of targets to uninstall | ||
| #[arg(required = true, num_args = 1..)] | ||
| target: Vec<String>, | ||
| target: Vec<TargetTuple>, | ||
|
|
||
| #[arg(long, help = official_toolchain_arg_help())] | ||
| toolchain: Option<PartialToolchainDesc>, | ||
|
|
@@ -1494,7 +1493,7 @@ async fn target_add( | |
| distributable | ||
| .add_components(distributable.components()?.into_iter().filter_map(|c| { | ||
| (c.available && !c.installed && c.component.short_name() == "rust-std") | ||
| .then_some(c.component) | ||
| .then_some(Ok(c.component)) | ||
| })) | ||
| .await?; | ||
|
|
||
|
|
@@ -1505,7 +1504,7 @@ async fn target_add( | |
| .add_components( | ||
| targets | ||
| .into_iter() | ||
| .map(|target| Component::std(TargetTuple::new(target))), | ||
| .map(|target| Ok(Component::std(TargetTuple::new(target)))), | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
@@ -1514,7 +1513,7 @@ async fn target_add( | |
|
|
||
| async fn target_remove( | ||
| cfg: &Cfg<'_>, | ||
| targets: Vec<String>, | ||
| targets: Vec<TargetTuple>, | ||
| toolchain: Option<PartialToolchainDesc>, | ||
| ) -> anyhow::Result<ExitCode> { | ||
| let distributable = DistributableToolchain::from_partial( | ||
|
|
@@ -1523,33 +1522,21 @@ async fn target_remove( | |
| ) | ||
| .await?; | ||
|
|
||
| for target in targets { | ||
| let target = TargetTuple::new(target); | ||
| let default_target = cfg.default_host_tuple()?; | ||
| if target == default_target { | ||
| warn!( | ||
| "removing the default host target; proc-macros and build scripts might no longer build" | ||
| ); | ||
| } | ||
| // Whether we have at most 1 component target that is not `None` (wildcard). | ||
| let has_at_most_one_target = distributable | ||
| .components()? | ||
| .into_iter() | ||
| .filter_map(|c| match (c.installed, c.component.target) { | ||
| (true, Some(t)) => Some(t), | ||
| _ => None, | ||
| }) | ||
| .unique() | ||
| .at_most_one() | ||
| .is_ok(); | ||
| if has_at_most_one_target { | ||
| warn!("removing the last target; no build targets will be available"); | ||
| } | ||
| distributable | ||
| .remove_component(Component::std(target)) | ||
| .await?; | ||
| if targets.contains(&cfg.default_host_tuple()?) { | ||
| warn!( | ||
| "removing the default host target; proc-macros and build scripts might no longer build" | ||
| ); | ||
|
Comment on lines
+1525
to
+1528
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: Shouldn't we print this after confirming the removal succeeded? I know the phrasing is "removing" and not "removed", but still, a command like Maybe we could move this to after the actual removal?
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. Oops, I was looking into the code and did not see that this was already queued. Apologies :)
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. Feedback is still useful!
Member
Author
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.
@FranciscoTGouveia Thanks for the feedback! I'd like to clarify that since #4797, |
||
| } | ||
|
|
||
| let mut remaining_targets = distributable.toolchain.installed_targets()?; | ||
| remaining_targets.retain(|it| !targets.contains(it)); | ||
| if remaining_targets.is_empty() { | ||
| warn!("removing the last target; no build targets will be available"); | ||
| } | ||
|
|
||
| distributable | ||
| .remove_components(targets.into_iter().map(|c| Ok(Component::std(c)))) | ||
| .await?; | ||
| Ok(ExitCode::SUCCESS) | ||
| } | ||
|
|
||
|
|
@@ -1604,9 +1591,7 @@ async fn component_add( | |
| .add_components( | ||
| components | ||
| .into_iter() | ||
| .map(|component| Component::try_new(&component, &distributable, target.as_ref())) | ||
| .collect::<anyhow::Result<Vec<_>>>()? | ||
| .into_iter(), | ||
| .map(|component| Component::try_new(&component, &distributable, target.as_ref())), | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
@@ -1632,37 +1617,14 @@ async fn component_remove( | |
| let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?; | ||
| let target = get_target(target, &distributable); | ||
|
|
||
| let parsed_components = components | ||
| .iter() | ||
| .map(|component| Component::try_new(component, &distributable, target.as_ref())) | ||
| .collect::<anyhow::Result<Vec<_>>>()?; | ||
|
|
||
| let mut unknown_components = Vec::new(); | ||
|
|
||
| for component in parsed_components { | ||
| let Err(err) = distributable.remove_component(component).await else { | ||
| continue; | ||
| }; | ||
|
|
||
| if let Some(RustupError::UnknownComponents { components, .. }) = | ||
| err.downcast_ref::<RustupError>() | ||
| { | ||
| unknown_components.extend(components.iter().cloned()); | ||
| continue; | ||
| } | ||
|
|
||
| return Err(err); | ||
| } | ||
|
|
||
| if unknown_components.is_empty() { | ||
| Ok(ExitCode::SUCCESS) | ||
| } else { | ||
| Err(RustupError::UnknownComponents { | ||
| desc: distributable.desc().clone(), | ||
| components: unknown_components, | ||
| } | ||
| .into()) | ||
| } | ||
| distributable | ||
| .remove_components( | ||
| components | ||
| .iter() | ||
| .map(|component| Component::try_new(component, &distributable, target.as_ref())), | ||
| ) | ||
| .await?; | ||
| Ok(ExitCode::SUCCESS) | ||
| } | ||
|
|
||
| async fn toolchain_link( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.