Skip to content

Commit 1c3eb9b

Browse files
Merge #462
462: add cross metadata r=reitermarkus a=Emilgardis this will enable running `cargo metadata` in the container instead of on the host. Co-authored-by: Emil Gardström <[email protected]>
2 parents e9da0dc + e0dd3c9 commit 1c3eb9b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/cargo.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum Subcommand {
1717
Bench,
1818
Deb,
1919
Clippy,
20+
Metadata,
2021
}
2122

2223
impl Subcommand {
@@ -33,6 +34,13 @@ impl Subcommand {
3334
_ => false,
3435
}
3536
}
37+
38+
pub fn needs_target_in_command(self) -> bool {
39+
match self {
40+
Subcommand::Metadata => false,
41+
_ => true,
42+
}
43+
}
3644
}
3745

3846
impl<'a> From<&'a str> for Subcommand {
@@ -47,6 +55,7 @@ impl<'a> From<&'a str> for Subcommand {
4755
"bench" => Subcommand::Bench,
4856
"deb" => Subcommand::Deb,
4957
"clippy" => Subcommand::Clippy,
58+
"metadata" => Subcommand::Metadata,
5059
_ => Subcommand::Other,
5160
}
5261
}

src/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,23 @@ fn run() -> Result<ExitStatus> {
278278
false
279279
},
280280
};
281+
282+
let filtered_args = if args.subcommand.map_or(false, |s| !s.needs_target_in_command()) {
283+
let mut filtered_args = Vec::new();
284+
let mut args_iter = args.all.clone().into_iter();
285+
while let Some(arg) = args_iter.next() {
286+
if arg == "--target" {
287+
args_iter.next();
288+
} else if arg.starts_with("--target=") {
289+
// NOOP
290+
} else {
291+
filtered_args.push(arg)
292+
}
293+
}
294+
filtered_args
295+
} else {
296+
args.all.clone()
297+
};
281298

282299
if image_exists && target.needs_docker() &&
283300
args.subcommand.map(|sc| sc.needs_docker()).unwrap_or(false) {
@@ -289,7 +306,7 @@ fn run() -> Result<ExitStatus> {
289306
}
290307

291308
return docker::run(&target,
292-
&args.all,
309+
&filtered_args,
293310
&args.target_dir,
294311
&root,
295312
toml.as_ref(),

0 commit comments

Comments
 (0)