Skip to content

Commit 468e944

Browse files
committed
fix(manifest): consider possible renames in Component::try_new()
1 parent 438586c commit 468e944

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/dist/manifest.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,11 @@ impl Component {
498498
distributable: &DistributableToolchain<'_>,
499499
fallback_target: Option<&TargetTriple>,
500500
) -> Result<Self> {
501+
let manifest = distributable.get_manifest()?;
501502
for component_status in distributable.components()? {
502-
let short_name = component_status.component.short_name_in_manifest();
503-
let target = component_status.component.target.as_ref();
504-
505-
if name.starts_with(short_name)
506-
&& target.is_some()
507-
&& name == format!("{}-{}", short_name, target.unwrap())
508-
{
509-
return Ok(Component::new(
510-
short_name.to_string(),
511-
target.cloned(),
512-
false,
513-
));
503+
let component = component_status.component;
504+
if name == component.name_in_manifest() || name == component.name(&manifest) {
505+
return Ok(component);
514506
}
515507
}
516508

tests/suite/cli_rustup.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,28 @@ async fn add_component_by_target_triple() {
15421542
assert!(cx.config.rustupdir.has(path));
15431543
}
15441544

1545+
#[tokio::test]
1546+
async fn add_component_by_target_triple_renamed_from() {
1547+
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
1548+
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
1549+
cx.config
1550+
.expect_ok(&["rustup", "component", "add", for_host!("rls-{}")])
1551+
.await;
1552+
let path = for_host!("toolchains/nightly-{}/bin/rls");
1553+
assert!(cx.config.rustupdir.has(path));
1554+
}
1555+
1556+
#[tokio::test]
1557+
async fn add_component_by_target_triple_renamed_to() {
1558+
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
1559+
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
1560+
cx.config
1561+
.expect_ok(&["rustup", "component", "add", for_host!("rls-preview-{}")])
1562+
.await;
1563+
let path = for_host!("toolchains/nightly-{}/bin/rls");
1564+
assert!(cx.config.rustupdir.has(path));
1565+
}
1566+
15451567
#[tokio::test]
15461568
async fn fail_invalid_component_name() {
15471569
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;

0 commit comments

Comments
 (0)