From c46fdc2442dcead3ed9251a21f26a75764a2fc60 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 9 Jan 2020 05:01:54 +0100 Subject: [PATCH] Support `--target-dir`. --- src/cli.rs | 44 ++++++++++++++++++++++++++++++-------------- src/docker.rs | 3 ++- src/main.rs | 1 + 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index ec6a40267..19bc32652 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use std::env; +use std::{env, path::PathBuf}; use crate::Target; use crate::cargo::Subcommand; @@ -8,29 +8,44 @@ pub struct Args { pub all: Vec, pub subcommand: Option, pub target: Option, + pub target_dir: Option, } pub fn parse(target_list: &TargetList) -> Args { - let all: Vec<_> = env::args().skip(1).collect(); - let mut target = None; + let mut target_dir = None; let mut sc = None; + let mut all: Vec = Vec::new(); { - let mut args = all.iter(); + let mut args = env::args().skip(1); while let Some(arg) = args.next() { - if !arg.starts_with('-') && sc.is_none() { - sc = Some(Subcommand::from(&**arg)) - } - if arg == "--target" { - target = args.next().map(|s| Target::from(&**s, target_list)) + all.push(arg); + if let Some(t) = args.next() { + target = Some(Target::from(&t, target_list)); + all.push(t); + } } else if arg.starts_with("--target=") { - target = arg.splitn(2, '=') - .nth(1) - .map(|s| Target::from(&*s, target_list)) - } else if !arg.starts_with('-') && sc.is_none() { - sc = Some(Subcommand::from(&**arg)); + target = arg.splitn(2, '=').nth(1).map(|s| Target::from(&*s, target_list)); + all.push(arg); + } else if arg == "--target-dir" { + all.push(arg); + if let Some(td) = args.next() { + target_dir = Some(PathBuf::from(&td)); + all.push("/target".to_string()); + } + } else if arg.starts_with("--target-dir=") { + if let Some(td) = arg.splitn(2, '=').nth(1) { + target_dir = Some(PathBuf::from(&td)); + all.push(format!("--target-dir=/target")); + } + } else { + if !arg.starts_with('-') && sc.is_none() { + sc = Some(Subcommand::from(arg.as_ref())); + } + + all.push(arg.to_string()); } } } @@ -39,5 +54,6 @@ pub fn parse(target_list: &TargetList) -> Args { all, subcommand: sc, target, + target_dir, } } diff --git a/src/docker.rs b/src/docker.rs index fccad253b..511140b31 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -51,6 +51,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> { pub fn run(target: &Target, args: &[String], + target_dir: &Option, root: &Root, toml: Option<&Toml>, uses_xargo: bool, @@ -63,7 +64,7 @@ pub fn run(target: &Target, let xargo_dir = env::var_os("XARGO_HOME") .map(PathBuf::from) .unwrap_or_else(|| home_dir.join(".xargo")); - let target_dir = root.join("target"); + let target_dir = target_dir.clone().unwrap_or_else(|| root.join("target")); // create the directories we are going to mount before we mount them, // otherwise `docker` will create them but they will be owned by `root` diff --git a/src/main.rs b/src/main.rs index 25730a57f..b6b0da5c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -280,6 +280,7 @@ fn run() -> Result { return docker::run(&target, &args.all, + &args.target_dir, &root, toml.as_ref(), uses_xargo,