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

Fix component remove error by component name with explicit target triple #3601

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 2 additions & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,8 +1364,7 @@ fn component_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
let target = get_target(m, &distributable);

for component in m.get_many::<String>("component").unwrap() {
let new_component = Component::new_with_target(component, false)
.unwrap_or_else(|| Component::new(component.to_string(), target.clone(), true));
let new_component = Component::try_new(component, &distributable, target.as_ref())?;
distributable.add_component(new_component)?;
}

Expand All @@ -1385,8 +1384,7 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
let target = get_target(m, &distributable);

for component in m.get_many::<String>("component").unwrap() {
let new_component = Component::new_with_target(component, false)
.unwrap_or_else(|| Component::new(component.to_string(), target.clone(), true));
let new_component = Component::try_new(component, &distributable, target.as_ref())?;
distributable.remove_component(new_component)?;
}

Expand Down
45 changes: 31 additions & 14 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use std::str::FromStr;

use anyhow::{anyhow, bail, Context, Result};

use crate::dist::dist::{PartialTargetTriple, Profile, TargetTriple};
use crate::dist::dist::{Profile, TargetTriple};
use crate::errors::*;
use crate::toolchain::distributable::DistributableToolchain;
use crate::utils::toml_utils::*;

use super::{config::Config, dist::ToolchainDesc};
Expand Down Expand Up @@ -588,21 +589,37 @@ impl Component {
}
}

pub(crate) fn new_with_target(pkg_with_target: &str, is_extension: bool) -> Option<Self> {
for (pos, _) in pkg_with_target.match_indices('-') {
let pkg = &pkg_with_target[0..pos];
let target = &pkg_with_target[pos + 1..];
if let Some(partial) = PartialTargetTriple::new(target) {
if let Ok(triple) = TargetTriple::try_from(partial) {
return Some(Self {
pkg: pkg.to_string(),
target: Some(triple),
is_extension,
});
}
pub(crate) fn try_new(
rami3l marked this conversation as resolved.
Show resolved Hide resolved
name: &str,
distributable: &DistributableToolchain<'_>,
fallback_target: Option<&TargetTriple>,
) -> Result<Self> {
let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
let manifest_components = manifest.query_components(distributable.desc(), &config)?;

for component_status in manifest_components {
let short_name = component_status.component.short_name_in_manifest();
let target = component_status.component.target.as_ref();

if name.starts_with(short_name)
&& target.is_some()
&& name == format!("{}-{}", short_name, target.unwrap())
{
return Ok(Component::new(
short_name.to_string(),
target.cloned(),
false,
));
}
}
None

Ok(Component::new(
name.to_string(),
fallback_target.cloned(),
true,
))
}

pub(crate) fn wildcard(&self) -> Self {
Expand Down