Skip to content

Commit eb33fed

Browse files
Merge #371
371: [wip] #370 Support for explicit channel argument r=reitermarkus a=anti-social Need a little time to write some tests (never dealt with azure). Co-authored-by: Alexander Koval <kovalidis@gmail.com>
2 parents 8e8615b + 0c0e030 commit eb33fed

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/cli.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ use crate::cargo::Subcommand;
55
use crate::rustc::TargetList;
66
use crate::Target;
77

8+
#[derive(Debug)]
89
pub struct Args {
910
pub all: Vec<String>,
1011
pub subcommand: Option<Subcommand>,
12+
pub channel: Option<String>,
1113
pub target: Option<Target>,
1214
pub target_dir: Option<PathBuf>,
1315
pub docker_in_docker: bool,
1416
}
1517

1618
pub fn parse(target_list: &TargetList) -> Args {
19+
let mut channel = None;
1720
let mut target = None;
1821
let mut target_dir = None;
1922
let mut sc = None;
@@ -22,7 +25,9 @@ pub fn parse(target_list: &TargetList) -> Args {
2225
{
2326
let mut args = env::args().skip(1);
2427
while let Some(arg) = args.next() {
25-
if arg == "--target" {
28+
if let ("+", ch) = arg.split_at(1) {
29+
channel = Some(ch.to_string());
30+
} else if arg == "--target" {
2631
all.push(arg);
2732
if let Some(t) = args.next() {
2833
target = Some(Target::from(&t, target_list));
@@ -62,6 +67,7 @@ pub fn parse(target_list: &TargetList) -> Args {
6267
Args {
6368
all,
6469
subcommand: sc,
70+
channel,
6571
target,
6672
target_dir,
6773
docker_in_docker,

src/main.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,19 @@ fn run() -> Result<ExitStatus> {
228228
.unwrap_or_else(|| Target::from(host.triple(), &target_list));
229229
let toml = toml(&root)?;
230230

231-
let sysroot = rustc::sysroot(&host, &target, verbose)?;
232-
let toolchain = sysroot.file_name().and_then(|file_name| file_name.to_str())
231+
let mut sysroot = rustc::sysroot(&host, &target, verbose)?;
232+
let default_toolchain = sysroot.file_name().and_then(|file_name| file_name.to_str())
233233
.ok_or("couldn't get toolchain name")?;
234+
let toolchain = if let Some(channel) = args.channel {
235+
[channel].iter().map(|c| c.as_str()).chain(
236+
default_toolchain.splitn(2, '-').skip(1)
237+
)
238+
.collect::<Vec<_>>()
239+
.join("-")
240+
} else {
241+
default_toolchain.to_string()
242+
};
243+
sysroot.set_file_name(&toolchain);
234244

235245
let installed_toolchains = rustup::installed_toolchains(verbose)?;
236246

@@ -250,13 +260,13 @@ fn run() -> Result<ExitStatus> {
250260

251261
if !uses_xargo && !available_targets.is_installed(&target) {
252262
rustup::install(&target, &toolchain, verbose)?;
253-
} else if !rustup::component_is_installed("rust-src", toolchain, verbose)? {
254-
rustup::install_component("rust-src", toolchain, verbose)?;
263+
} else if !rustup::component_is_installed("rust-src", &toolchain, verbose)? {
264+
rustup::install_component("rust-src", &toolchain, verbose)?;
255265
}
256266

257267
if args.subcommand.map(|sc| sc == Subcommand::Clippy).unwrap_or(false) &&
258-
!rustup::component_is_installed("clippy", toolchain, verbose)? {
259-
rustup::install_component("clippy", toolchain, verbose)?;
268+
!rustup::component_is_installed("clippy", &toolchain, verbose)? {
269+
rustup::install_component("clippy", &toolchain, verbose)?;
260270
}
261271

262272
let needs_interpreter = args.subcommand.map(|sc| sc.needs_interpreter()).unwrap_or(false);

0 commit comments

Comments
 (0)