Skip to content

Commit 2f284ac

Browse files
Merge #363
363: Support `--target-dir`. r=Dylan-DPC a=reitermarkus Closes #340. Co-authored-by: Markus Reiter <[email protected]>
2 parents e9affc0 + c46fdc2 commit 2f284ac

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

src/cli.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::env;
1+
use std::{env, path::PathBuf};
22

33
use crate::Target;
44
use crate::cargo::Subcommand;
@@ -8,29 +8,44 @@ pub struct Args {
88
pub all: Vec<String>,
99
pub subcommand: Option<Subcommand>,
1010
pub target: Option<Target>,
11+
pub target_dir: Option<PathBuf>,
1112
}
1213

1314
pub fn parse(target_list: &TargetList) -> Args {
14-
let all: Vec<_> = env::args().skip(1).collect();
15-
1615
let mut target = None;
16+
let mut target_dir = None;
1717
let mut sc = None;
18+
let mut all: Vec<String> = Vec::new();
1819

1920
{
20-
let mut args = all.iter();
21+
let mut args = env::args().skip(1);
2122
while let Some(arg) = args.next() {
22-
if !arg.starts_with('-') && sc.is_none() {
23-
sc = Some(Subcommand::from(&**arg))
24-
}
25-
2623
if arg == "--target" {
27-
target = args.next().map(|s| Target::from(&**s, target_list))
24+
all.push(arg);
25+
if let Some(t) = args.next() {
26+
target = Some(Target::from(&t, target_list));
27+
all.push(t);
28+
}
2829
} else if arg.starts_with("--target=") {
29-
target = arg.splitn(2, '=')
30-
.nth(1)
31-
.map(|s| Target::from(&*s, target_list))
32-
} else if !arg.starts_with('-') && sc.is_none() {
33-
sc = Some(Subcommand::from(&**arg));
30+
target = arg.splitn(2, '=').nth(1).map(|s| Target::from(&*s, target_list));
31+
all.push(arg);
32+
} else if arg == "--target-dir" {
33+
all.push(arg);
34+
if let Some(td) = args.next() {
35+
target_dir = Some(PathBuf::from(&td));
36+
all.push("/target".to_string());
37+
}
38+
} else if arg.starts_with("--target-dir=") {
39+
if let Some(td) = arg.splitn(2, '=').nth(1) {
40+
target_dir = Some(PathBuf::from(&td));
41+
all.push(format!("--target-dir=/target"));
42+
}
43+
} else {
44+
if !arg.starts_with('-') && sc.is_none() {
45+
sc = Some(Subcommand::from(arg.as_ref()));
46+
}
47+
48+
all.push(arg.to_string());
3449
}
3550
}
3651
}
@@ -39,5 +54,6 @@ pub fn parse(target_list: &TargetList) -> Args {
3954
all,
4055
subcommand: sc,
4156
target,
57+
target_dir,
4258
}
4359
}

src/docker.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {
5151

5252
pub fn run(target: &Target,
5353
args: &[String],
54+
target_dir: &Option<PathBuf>,
5455
root: &Root,
5556
toml: Option<&Toml>,
5657
uses_xargo: bool,
@@ -63,7 +64,7 @@ pub fn run(target: &Target,
6364
let xargo_dir = env::var_os("XARGO_HOME")
6465
.map(PathBuf::from)
6566
.unwrap_or_else(|| home_dir.join(".xargo"));
66-
let target_dir = root.join("target");
67+
let target_dir = target_dir.clone().unwrap_or_else(|| root.join("target"));
6768

6869
// create the directories we are going to mount before we mount them,
6970
// otherwise `docker` will create them but they will be owned by `root`

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ fn run() -> Result<ExitStatus> {
280280

281281
return docker::run(&target,
282282
&args.all,
283+
&args.target_dir,
283284
&root,
284285
toml.as_ref(),
285286
uses_xargo,

0 commit comments

Comments
 (0)