Skip to content

Commit ffecbc6

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

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-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

+32
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,38 @@ 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+
cx.config
1553+
.expect_ok_contains(
1554+
&["rustup", "component", "list", "--installed"],
1555+
for_host!("rls-{}"),
1556+
"",
1557+
)
1558+
.await;
1559+
}
1560+
1561+
#[tokio::test]
1562+
async fn add_component_by_target_triple_renamed_to() {
1563+
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
1564+
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
1565+
cx.config
1566+
.expect_ok(&["rustup", "component", "add", for_host!("rls-preview-{}")])
1567+
.await;
1568+
cx.config
1569+
.expect_ok_contains(
1570+
&["rustup", "component", "list", "--installed"],
1571+
for_host!("rls-{}"),
1572+
"",
1573+
)
1574+
.await;
1575+
}
1576+
15451577
#[tokio::test]
15461578
async fn fail_invalid_component_name() {
15471579
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;

0 commit comments

Comments
 (0)