From ce7bdd97d3f78690248ea4013ba0f988ec5039a8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 22 Jun 2022 10:08:47 -0700 Subject: [PATCH] Add a --no-default-components flag --- README.md | 13 ++++----- src/main.rs | 76 +++++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index e5c37ce..0bb4bbe 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,13 @@ USAGE: rustup-toolchain-install-master [FLAGS] [OPTIONS] [--] [commits]... FLAGS: - -a, --alt download the alt build instead of normal build - --dry-run Only log the URLs, without downloading the artifacts - -f, --force Replace an existing toolchain of the same name - -h, --help Prints help information - -k, --keep-going Continue downloading toolchains even if some of them failed - -V, --version Prints version information + -a, --alt download the alt build instead of normal build + --dry-run Only log the URLs, without downloading the artifacts + -f, --force Replace an existing toolchain of the same name + -h, --help Prints help information + -k, --keep-going Continue downloading toolchains even if some of them failed + --no-default-components do not install rustc and rust-std component unless explicitly specified + -V, --version Prints version information OPTIONS: --channel specify the channel of the commits instead of detecting it automatically diff --git a/src/main.rs b/src/main.rs index 54e2e3c..e8cb021 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use std::ops::Deref; use std::path::{Path, PathBuf}; use std::process::exit; use std::process::Command; +use std::slice; use std::time::Duration; use ansi_term::Color::{Red, Yellow}; @@ -70,6 +71,12 @@ struct Args { )] components: Vec, + #[structopt( + long, + help = "do not install rustc and rust-std component unless explicitly specified" + )] + no_default_components: bool, + #[structopt( long = "channel", help = "specify the channel of the commits instead of detecting it automatically" @@ -203,6 +210,7 @@ struct Toolchain<'a> { host_target: &'a str, rust_std_targets: &'a [&'a str], components: &'a [&'a str], + no_default_components: bool, dest: PathBuf, } @@ -236,43 +244,40 @@ fn install_single_toolchain( get_channel(client, prefix, toolchain.commit)? }; - // download every component except rust-std. - for component in once(&"rustc").chain(toolchain.components) { - let component_filename = if *component == "rust-src" { - // rust-src is the only target-independent component - format!("{}-{}", component, channel) - } else { - format!("{}-{}-{}", component, channel, toolchain.host_target) - }; - download_tar_xz( - maybe_dry_client, - &format!( - "{}/{}/{}.tar.xz", - prefix, toolchain.commit, &component_filename - ), - &toolchain.dest, - toolchain.commit, - component, - channel, - toolchain.host_target, - )?; + let mut components = toolchain.components.to_vec(); + if !toolchain.no_default_components { + components.insert(0, "rustc"); + components.push("rust-std"); } - // download rust-std for every target. - for target in toolchain.rust_std_targets { - let rust_std_filename = format!("rust-std-{}-{}", channel, target); - download_tar_xz( - maybe_dry_client, - &format!( - "{}/{}/{}.tar.xz", - prefix, toolchain.commit, rust_std_filename - ), - &toolchain.dest, - toolchain.commit, - "rust-std", - channel, - target, - )?; + for component in components { + let targets = if component == "rust-std" { + // download rust-std for every target + &toolchain.rust_std_targets + } else { + // otherwise just the host target + slice::from_ref(&toolchain.host_target) + }; + for target in targets { + let component_filename = if component == "rust-src" { + // rust-src is the only target-independent component + format!("{}-{}", component, channel) + } else { + format!("{}-{}-{}", component, channel, target) + }; + download_tar_xz( + maybe_dry_client, + &format!( + "{}/{}/{}.tar.xz", + prefix, toolchain.commit, &component_filename + ), + &toolchain.dest, + toolchain.commit, + component, + channel, + target, + )?; + } } // install @@ -472,6 +477,7 @@ fn run() -> Result<(), Error> { host_target: host, rust_std_targets: &rust_std_targets, components: &components, + no_default_components: args.no_default_components, dest, }, args.channel.as_deref(),