Skip to content

Commit f908e5c

Browse files
refactor(custom-toolchains): separate logic for listing components and targets
1 parent a65ecb0 commit f908e5c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/cli/rustup_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
10021002
ToolchainName::Custom(name) => {
10031003
Toolchain::new(cfg, LocalToolchainName::Named(name.into()))
10041004
.ok()?
1005-
.list_targets()
1005+
.installed_targets()
10061006
.ok()
10071007
}
10081008
})

src/toolchain.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use crate::{
2323
RustupError,
2424
config::{ActiveReason, Cfg, InstalledPath},
2525
dist::{
26-
PartialToolchainDesc, TargetTriple, component::components::Components,
26+
PartialToolchainDesc, TargetTriple,
27+
component::components::{Component, Components},
2728
prefix::InstallPrefix,
2829
},
2930
env_var, install,
@@ -579,15 +580,21 @@ impl<'a> Toolchain<'a> {
579580
Ok(())
580581
}
581582

582-
/// Get the list of installed targets for any toolchain
583+
/// Get the list of installed components for any toolchain
583584
///
584585
/// NB: An assumption is made that custom toolchains always have a `rustlib/components` file
585-
pub fn list_targets(&self) -> anyhow::Result<Vec<TargetTriple>> {
586+
pub fn installed_components(&self) -> anyhow::Result<Vec<Component>> {
586587
let prefix = InstallPrefix::from(self.path.clone());
587588
let components = Components::open(prefix)?;
588-
let installed_components = components.list()?;
589+
components.list()
590+
}
589591

590-
let targets = installed_components
592+
/// Get the list of installed targets for any toolchain
593+
///
594+
///
595+
pub fn installed_targets(&self) -> anyhow::Result<Vec<TargetTriple>> {
596+
let targets = self
597+
.installed_components()?
591598
.into_iter()
592599
.filter_map(|c| {
593600
if c.name().starts_with("rust-std-") {

0 commit comments

Comments
 (0)