Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] #370 Support for explicit channel argument #371

Merged
merged 3 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ use crate::Target;
use crate::cargo::Subcommand;
use crate::rustc::TargetList;

#[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 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 @@ -20,7 +23,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 @@ -53,6 +58,7 @@ pub fn parse(target_list: &TargetList) -> Args {
Args {
all,
subcommand: sc,
channel,
target,
target_dir,
}
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