Skip to content

Commit 8c16489

Browse files
committed
Add a --no-default-components flag
1 parent 21e67de commit 8c16489

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

src/main.rs

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::ops::Deref;
88
use std::path::{Path, PathBuf};
99
use std::process::exit;
1010
use std::process::Command;
11+
use std::slice;
1112
use std::time::Duration;
1213

1314
use ansi_term::Color::{Red, Yellow};
@@ -70,6 +71,12 @@ struct Args {
7071
)]
7172
components: Vec<String>,
7273

74+
#[structopt(
75+
long,
76+
help = "do not install rustc and rust-std component unless explicitly specified"
77+
)]
78+
no_default_components: bool,
79+
7380
#[structopt(
7481
long = "channel",
7582
help = "specify the channel of the commits instead of detecting it automatically"
@@ -203,6 +210,7 @@ struct Toolchain<'a> {
203210
host_target: &'a str,
204211
rust_std_targets: &'a [&'a str],
205212
components: &'a [&'a str],
213+
no_default_components: bool,
206214
dest: PathBuf,
207215
}
208216

@@ -236,43 +244,40 @@ fn install_single_toolchain(
236244
get_channel(client, prefix, toolchain.commit)?
237245
};
238246

239-
// download every component except rust-std.
240-
for component in once(&"rustc").chain(toolchain.components) {
241-
let component_filename = if *component == "rust-src" {
242-
// rust-src is the only target-independent component
243-
format!("{}-{}", component, channel)
244-
} else {
245-
format!("{}-{}-{}", component, channel, toolchain.host_target)
246-
};
247-
download_tar_xz(
248-
maybe_dry_client,
249-
&format!(
250-
"{}/{}/{}.tar.xz",
251-
prefix, toolchain.commit, &component_filename
252-
),
253-
&toolchain.dest,
254-
toolchain.commit,
255-
component,
256-
channel,
257-
toolchain.host_target,
258-
)?;
247+
let mut components = toolchain.components.to_vec();
248+
if !toolchain.no_default_components {
249+
components.insert(0, "rustc");
250+
components.push("rust-std");
259251
}
260252

261-
// download rust-std for every target.
262-
for target in toolchain.rust_std_targets {
263-
let rust_std_filename = format!("rust-std-{}-{}", channel, target);
264-
download_tar_xz(
265-
maybe_dry_client,
266-
&format!(
267-
"{}/{}/{}.tar.xz",
268-
prefix, toolchain.commit, rust_std_filename
269-
),
270-
&toolchain.dest,
271-
toolchain.commit,
272-
"rust-std",
273-
channel,
274-
target,
275-
)?;
253+
for component in components {
254+
let targets = if component == "rust-std" {
255+
// download rust-std for every target
256+
&toolchain.rust_std_targets
257+
} else {
258+
// otherwise just the host target
259+
slice::from_ref(&toolchain.host_target)
260+
};
261+
for target in targets {
262+
let component_filename = if component == "rust-src" {
263+
// rust-src is the only target-independent component
264+
format!("{}-{}", component, channel)
265+
} else {
266+
format!("{}-{}-{}", component, channel, target)
267+
};
268+
download_tar_xz(
269+
maybe_dry_client,
270+
&format!(
271+
"{}/{}/{}.tar.xz",
272+
prefix, toolchain.commit, &component_filename
273+
),
274+
&toolchain.dest,
275+
toolchain.commit,
276+
component,
277+
channel,
278+
target,
279+
)?;
280+
}
276281
}
277282

278283
// install
@@ -472,6 +477,7 @@ fn run() -> Result<(), Error> {
472477
host_target: host,
473478
rust_std_targets: &rust_std_targets,
474479
components: &components,
480+
no_default_components: args.no_default_components,
475481
dest,
476482
},
477483
args.channel.as_deref(),

0 commit comments

Comments
 (0)