Skip to content
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

feat(cli): warn when removing the last/host target for a toolchain, pt. 2 #3643

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,17 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
if target == default_target {
warn!("after removing the default host target, proc-macros and build scripts might no longer build");
}
let has_at_most_one_target = {
let components = distributable.components()?;
// Every component target that is not `None` (wildcard).
let targets = components
.iter()
.filter_map(|c| c.installed.then(|| c.component.target.clone()).flatten());
targets.unique().at_most_one().is_ok()
};
// 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,
})
rami3l marked this conversation as resolved.
Show resolved Hide resolved
.unique()
.at_most_one()
.is_ok();
if has_at_most_one_target {
warn!("after removing the last target, no build targets will be available");
}
Expand Down
21 changes: 7 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub use crate::errors::*;
pub(crate) use crate::notifications::*;
pub(crate) use crate::utils::toml_utils;
use anyhow::{anyhow, Result};
use itertools::{chain, Itertools};

#[macro_use]
extern crate rs_tracing;
Expand All @@ -41,23 +42,15 @@ pub static DUP_TOOLS: &[&str] = &["rust-analyzer", "rustfmt", "cargo-fmt"];

// If the given name is one of the tools we proxy.
pub fn is_proxyable_tools(tool: &str) -> Result<()> {
if TOOLS
.iter()
.chain(DUP_TOOLS.iter())
.any(|&name| name == tool)
{
if chain!(TOOLS, DUP_TOOLS).contains(&tool) {
Ok(())
} else {
Err(anyhow!(format!(
"unknown proxy name: '{}'; valid proxy names are {}",
tool,
TOOLS
.iter()
.chain(DUP_TOOLS.iter())
Err(anyhow!(
"unknown proxy name: '{tool}'; valid proxy names are {}",
chain!(TOOLS, DUP_TOOLS)
.map(|s| format!("'{s}'"))
.collect::<Vec<_>>()
.join(", ")
)))
.join(", "),
))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/toolchain/distributable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
dist::{
config::Config,
dist::{Profile, ToolchainDesc},
manifest::{Component, Manifest},
manifest::{Component, ComponentStatus, Manifest},
manifestation::{Changes, Manifestation},
prefix::InstallPrefix,
},
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'a> DistributableToolchain<'a> {
Ok(())
}

pub(crate) fn components(&self) -> anyhow::Result<Vec<crate::dist::manifest::ComponentStatus>> {
pub(crate) fn components(&self) -> anyhow::Result<Vec<ComponentStatus>> {
let manifestation = self.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = self.get_manifest()?;
Expand Down