Skip to content

Commit

Permalink
Pass channel argument to cargo as is
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Feb 24, 2020
1 parent f45cd9f commit d1b7b46
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 43 deletions.
10 changes: 4 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use std::{env, path::PathBuf};

use rustc_version::Channel;

use crate::Target;
use crate::cargo::Subcommand;
use crate::errors::Result;
use crate::rustc::{ChannelExt, TargetList};
use crate::rustc::TargetList;

#[derive(Debug)]
pub struct Args {
pub all: Vec<String>,
pub subcommand: Option<Subcommand>,
pub channel: Option<Channel>,
pub channel: Option<String>,
pub target: Option<Target>,
pub target_dir: Option<PathBuf>,
}
Expand All @@ -26,8 +24,8 @@ pub fn parse(target_list: &TargetList) -> Result<Args> {
{
let mut args = env::args().skip(1);
while let Some(arg) = args.next() {
if arg.starts_with("+") {
channel = Some(Channel::from_str(&arg[1..])?);
if let ("+", ch) = arg.split_at(1) {
channel = Some(ch.to_string());
} else if arg == "--target" {
all.push(arg);
if let Some(t) = args.next() {
Expand Down
7 changes: 0 additions & 7 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@ error_chain! {
Io(std::io::Error);
Which(which::Error);
}

errors {
InvalidChannelName(channel: String) {
description("invalid channel name")
display("invalid channel name: '{}'", channel)
}
}
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use toml::{Value, value::Table};

use self::cargo::{Root, Subcommand};
use self::errors::*;
use self::rustc::{ChannelExt, TargetList, VersionMetaExt};
use self::rustc::{TargetList, VersionMetaExt};

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -232,7 +232,7 @@ fn run() -> Result<ExitStatus> {
let default_toolchain = sysroot.file_name().and_then(|file_name| file_name.to_str())
.ok_or("couldn't get toolchain name")?;
let toolchain = if let Some(channel) = args.channel {
[channel.to_string()].iter().map(|c| c.as_str()).chain(
[channel].iter().map(|c| c.as_str()).chain(
default_toolchain.splitn(2, '-').skip(1)
)
.collect::<Vec<_>>()
Expand Down
29 changes: 1 addition & 28 deletions src/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;
use std::process::Command;

use rustc_version::{Channel, Version, VersionMeta};
use rustc_version::{Version, VersionMeta};

use crate::{Host, Target};
use crate::errors::*;
Expand Down Expand Up @@ -38,33 +38,6 @@ impl VersionMetaExt for VersionMeta {
}
}

pub(crate) trait ChannelExt {
fn from_str(chan: &str) -> Result<Channel>;
fn to_string(&self) -> String;
}

impl ChannelExt for Channel {
fn from_str(chan: &str) -> Result<Channel> {
Ok(match chan {
"stable" => Channel::Stable,
"nightly" => Channel::Nightly,
"dev" => Channel::Dev,
"beta" => Channel::Beta,
_ => return Err(
ErrorKind::InvalidChannelName(chan.to_string()).into()
),
})
}
fn to_string(&self) -> String {
match self {
Channel::Stable => "stable",
Channel::Nightly => "nightly",
Channel::Dev => "dev",
Channel::Beta => "beta",
}.to_string()
}
}

pub fn target_list(verbose: bool) -> Result<TargetList> {
Command::new("rustc")
.args(&["--print", "target-list"])
Expand Down

0 comments on commit d1b7b46

Please sign in to comment.