Skip to content

Commit 170ce65

Browse files
committed
Deduplicate code to get components from distributable
1 parent fd0d2ce commit 170ce65

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

src/cli/common.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,7 @@ pub(crate) fn list_targets(
380380
installed_only: bool,
381381
) -> Result<utils::ExitCode> {
382382
let mut t = process().stdout().terminal();
383-
let manifestation = distributable.get_manifestation()?;
384-
let config = manifestation.read_config()?.unwrap_or_default();
385-
let manifest = distributable.get_manifest()?;
386-
let components = manifest.query_components(distributable.desc(), &config)?;
387-
for component in components {
383+
for component in distributable.components()? {
388384
if component.component.short_name_in_manifest() == "rust-std" {
389385
let target = component
390386
.component
@@ -413,12 +409,7 @@ pub(crate) fn list_components(
413409
installed_only: bool,
414410
) -> Result<utils::ExitCode> {
415411
let mut t = process().stdout().terminal();
416-
417-
let manifestation = distributable.get_manifestation()?;
418-
let config = manifestation.read_config()?.unwrap_or_default();
419-
let manifest = distributable.get_manifest()?;
420-
let components = manifest.query_components(distributable.desc(), &config)?;
421-
for component in components {
412+
for component in distributable.components()? {
422413
let name = component.name;
423414
match (component.available, component.installed, installed_only) {
424415
(false, _, _) | (_, false, true) => continue,

src/cli/rustup_mode.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,14 +1084,7 @@ fn show(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
10841084
// active_toolchain will carry the reason we don't have one in its detail.
10851085
let active_targets = if let Ok(ref at) = active_toolchain {
10861086
if let Ok(distributable) = DistributableToolchain::try_from(&at.0) {
1087-
let components = (|| {
1088-
let manifestation = distributable.get_manifestation()?;
1089-
let config = manifestation.read_config()?.unwrap_or_default();
1090-
let manifest = distributable.get_manifest()?;
1091-
manifest.query_components(distributable.desc(), &config)
1092-
})();
1093-
1094-
match components {
1087+
match distributable.components() {
10951088
Ok(cs_vec) => cs_vec
10961089
.into_iter()
10971090
.filter(|c| c.component.short_name_in_manifest() == "rust-std")
@@ -1277,11 +1270,7 @@ fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
12771270
// list_components *and* add_component would both be inappropriate for
12781271
// custom toolchains.
12791272
let distributable = DistributableToolchain::try_from(&toolchain)?;
1280-
let manifestation = distributable.get_manifestation()?;
1281-
let config = manifestation.read_config()?.unwrap_or_default();
1282-
let manifest = distributable.get_manifest()?;
1283-
let components = manifest.query_components(distributable.desc(), &config)?;
1284-
1273+
let components = distributable.components()?;
12851274
let mut targets: Vec<_> = m
12861275
.get_many::<String>("target")
12871276
.unwrap()
@@ -1554,11 +1543,8 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
15541543
let toolchain = explicit_desc_or_dir_toolchain(cfg, m)?;
15551544

15561545
if let Ok(distributable) = DistributableToolchain::try_from(&toolchain) {
1557-
let manifestation = distributable.get_manifestation()?;
1558-
let config = manifestation.read_config()?.unwrap_or_default();
1559-
let manifest = distributable.get_manifest()?;
1560-
let components = manifest.query_components(distributable.desc(), &config)?;
1561-
if let [_] = components
1546+
if let [_] = distributable
1547+
.components()?
15621548
.into_iter()
15631549
.filter(|cstatus| {
15641550
cstatus.component.short_name_in_manifest() == "rust-docs" && !cstatus.installed

src/dist/manifest.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,7 @@ impl Component {
594594
distributable: &DistributableToolchain<'_>,
595595
fallback_target: Option<&TargetTriple>,
596596
) -> Result<Self> {
597-
let manifestation = distributable.get_manifestation()?;
598-
let config = manifestation.read_config()?.unwrap_or_default();
599-
let manifest = distributable.get_manifest()?;
600-
let manifest_components = manifest.query_components(distributable.desc(), &config)?;
601-
602-
for component_status in manifest_components {
597+
for component_status in distributable.components()? {
603598
let short_name = component_status.component.short_name_in_manifest();
604599
let target = component_status.component.target.as_ref();
605600

0 commit comments

Comments
 (0)