Skip to content

Commit

Permalink
Merge #363
Browse files Browse the repository at this point in the history
363: Support `--target-dir`. r=Dylan-DPC a=reitermarkus

Closes #340.

Co-authored-by: Markus Reiter <me@reitermark.us>
  • Loading branch information
bors[bot] and reitermarkus committed Jan 9, 2020
2 parents e9affc0 + c46fdc2 commit 2f284ac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
44 changes: 30 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::env;
use std::{env, path::PathBuf};

use crate::Target;
use crate::cargo::Subcommand;
Expand All @@ -8,29 +8,44 @@ pub struct Args {
pub all: Vec<String>,
pub subcommand: Option<Subcommand>,
pub target: Option<Target>,
pub target_dir: Option<PathBuf>,
}

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<String> = 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());
}
}
}
Expand All @@ -39,5 +54,6 @@ pub fn parse(target_list: &TargetList) -> Args {
all,
subcommand: sc,
target,
target_dir,
}
}
3 changes: 2 additions & 1 deletion src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {

pub fn run(target: &Target,
args: &[String],
target_dir: &Option<PathBuf>,
root: &Root,
toml: Option<&Toml>,
uses_xargo: bool,
Expand All @@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ fn run() -> Result<ExitStatus> {

return docker::run(&target,
&args.all,
&args.target_dir,
&root,
toml.as_ref(),
uses_xargo,
Expand Down

0 comments on commit 2f284ac

Please sign in to comment.