Skip to content

Commit

Permalink
component: Support installation/removal of component-target
Browse files Browse the repository at this point in the history
In order to reduce the surprise available when someone expects to be able to
take output of `rustup component list` and use it as input to `rustup component
add` or `rustup component remove` we now support creation of `Component`
objects by attempting to split it on '-' and see if we get a component name and
valid full target triple.

Fixes: #2057
  • Loading branch information
kinnison committed Oct 26, 2019
1 parent bef6279 commit 8595201
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,8 @@ fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
});

for component in m.values_of("component").expect("") {
let new_component = Component::new(component.to_string(), target.clone(), true);
let new_component = Component::new_with_target(component, false)
.unwrap_or_else(|| Component::new(component.to_string(), target.clone(), true));

toolchain.add_component(new_component)?;
}
Expand All @@ -1146,7 +1147,8 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
});

for component in m.values_of("component").expect("") {
let new_component = Component::new(component.to_string(), target.clone(), true);
let new_component = Component::new_with_target(component, false)
.unwrap_or_else(|| Component::new(component.to_string(), target.clone(), true));

toolchain.remove_component(new_component)?;
}
Expand Down
20 changes: 19 additions & 1 deletion src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use crate::errors::*;
use crate::utils::toml_utils::*;

use crate::dist::dist::{Profile, TargetTriple};
use crate::dist::dist::{PartialTargetTriple, Profile, TargetTriple};
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::str::FromStr;
Expand Down Expand Up @@ -496,6 +496,24 @@ impl Component {
is_extension,
}
}

pub 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 partial.arch.is_some() && partial.os.is_some() && partial.env.is_some() {
return Some(Self {
pkg: pkg.to_string(),
target: Some(TargetTriple::new(target)),
is_extension,
});
}
}
}
None
}

pub fn wildcard(&self) -> Self {
Self {
pkg: self.pkg.clone(),
Expand Down

0 comments on commit 8595201

Please sign in to comment.