Skip to content

Commit

Permalink
fix(manifest): consider possible renames in Component::try_new()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Aug 14, 2024
1 parent 438586c commit 468e944
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,11 @@ impl Component {
distributable: &DistributableToolchain<'_>,
fallback_target: Option<&TargetTriple>,
) -> Result<Self> {
let manifest = distributable.get_manifest()?;
for component_status in distributable.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,
));
let component = component_status.component;
if name == component.name_in_manifest() || name == component.name(&manifest) {
return Ok(component);
}
}

Expand Down
22 changes: 22 additions & 0 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,28 @@ async fn add_component_by_target_triple() {
assert!(cx.config.rustupdir.has(path));
}

#[tokio::test]
async fn add_component_by_target_triple_renamed_from() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
cx.config
.expect_ok(&["rustup", "component", "add", for_host!("rls-{}")])
.await;
let path = for_host!("toolchains/nightly-{}/bin/rls");
assert!(cx.config.rustupdir.has(path));
}

#[tokio::test]
async fn add_component_by_target_triple_renamed_to() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
cx.config
.expect_ok(&["rustup", "component", "add", for_host!("rls-preview-{}")])
.await;
let path = for_host!("toolchains/nightly-{}/bin/rls");
assert!(cx.config.rustupdir.has(path));
}

#[tokio::test]
async fn fail_invalid_component_name() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
Expand Down

0 comments on commit 468e944

Please sign in to comment.