Skip to content

Commit

Permalink
Monkey Patch for support target_dir.
Browse files Browse the repository at this point in the history
This is just an adhoc solution for issue cross-rs#272
Possble improvement: read `.cargo/config` to get target-dir.
  • Loading branch information
xiaoniu-578fa6bff964d005 committed Nov 4, 2019
1 parent d611d31 commit 9ed6632
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ pub struct Args {
pub all: Vec<String>,
pub subcommand: Option<Subcommand>,
pub target: Option<Target>,
pub target_dir: Option<String>,
}

pub fn parse(target_list: &TargetList) -> Args {
let all: Vec<_> = env::args().skip(1).collect();
let mut all: Vec<_> = env::args().skip(1).collect();

let mut target = None;
let mut target_dir = None;
let mut sc = None;

{
Expand All @@ -29,15 +31,30 @@ pub fn parse(target_list: &TargetList) -> Args {
target = arg.splitn(2, '=')
.nth(1)
.map(|s| Target::from(&*s, target_list))
} else if arg == "--target-dir" {
target_dir = args.next().map(|s| s.clone());
} else if arg.starts_with("--target-dir=") {
target_dir = arg.splitn(2, '=').nth(1).map(|s| s.to_owned())
} else if !arg.starts_with('-') && sc.is_none() {
sc = Some(Subcommand::from(&**arg));
}
}
}

// delete target-dir from args.all
if let Some(ind) = all.iter().position(|x| x=="--target-dir") {
all[ind]=String::new();
all[ind+1]=String::new();
}
if let Some(ind) = all.iter().position(|x| x.starts_with("--target-dir=")) {
all[ind]=String::new();
}
all = all.into_iter().filter(|x| !x.is_empty()).collect();

Args {
all: all,
subcommand: sc,
target: target,
target_dir: target_dir,
}
}
3 changes: 2 additions & 1 deletion src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {
}

pub fn run(target: &Target,
target_dir: Option<&str>,
args: &[String],
root: &Root,
toml: Option<&Toml>,
Expand All @@ -83,7 +84,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.map(|s| PathBuf::from(s)).unwrap_or(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.target_dir.as_ref().map(|s| &s[..]),
&args.all,
&root,
toml.as_ref(),
Expand Down

0 comments on commit 9ed6632

Please sign in to comment.