Skip to content

Commit

Permalink
Merge #371
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bors[bot] and anti-social authored Apr 13, 2020
2 parents 8e8615b + 0c0e030 commit eb33fed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ use crate::cargo::Subcommand;
use crate::rustc::TargetList;
use crate::Target;

#[derive(Debug)]
pub struct Args {
pub all: Vec<String>,
pub subcommand: Option<Subcommand>,
pub channel: Option<String>,
pub target: Option<Target>,
pub target_dir: Option<PathBuf>,
pub docker_in_docker: bool,
}

pub fn parse(target_list: &TargetList) -> Args {
let mut channel = None;
let mut target = None;
let mut target_dir = None;
let mut sc = None;
Expand All @@ -22,7 +25,9 @@ pub fn parse(target_list: &TargetList) -> Args {
{
let mut args = env::args().skip(1);
while let Some(arg) = args.next() {
if arg == "--target" {
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() {
target = Some(Target::from(&t, target_list));
Expand Down Expand Up @@ -62,6 +67,7 @@ pub fn parse(target_list: &TargetList) -> Args {
Args {
all,
subcommand: sc,
channel,
target,
target_dir,
docker_in_docker,
Expand Down
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,19 @@ fn run() -> Result<ExitStatus> {
.unwrap_or_else(|| Target::from(host.triple(), &target_list));
let toml = toml(&root)?;

let sysroot = rustc::sysroot(&host, &target, verbose)?;
let toolchain = sysroot.file_name().and_then(|file_name| file_name.to_str())
let mut sysroot = rustc::sysroot(&host, &target, verbose)?;
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].iter().map(|c| c.as_str()).chain(
default_toolchain.splitn(2, '-').skip(1)
)
.collect::<Vec<_>>()
.join("-")
} else {
default_toolchain.to_string()
};
sysroot.set_file_name(&toolchain);

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

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

if !uses_xargo && !available_targets.is_installed(&target) {
rustup::install(&target, &toolchain, verbose)?;
} else if !rustup::component_is_installed("rust-src", toolchain, verbose)? {
rustup::install_component("rust-src", toolchain, verbose)?;
} else if !rustup::component_is_installed("rust-src", &toolchain, verbose)? {
rustup::install_component("rust-src", &toolchain, verbose)?;
}

if args.subcommand.map(|sc| sc == Subcommand::Clippy).unwrap_or(false) &&
!rustup::component_is_installed("clippy", toolchain, verbose)? {
rustup::install_component("clippy", toolchain, verbose)?;
!rustup::component_is_installed("clippy", &toolchain, verbose)? {
rustup::install_component("clippy", &toolchain, verbose)?;
}

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

0 comments on commit eb33fed

Please sign in to comment.