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

Support --target-dir. #363

Merged
merged 1 commit into from
Jan 9, 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
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