Merge pull request #988 from oli-obk/metadata3

simply parse unknown json-strings as strings instead of erroring
This commit is contained in:
Martin Carton 2016-06-06 16:54:24 +02:00
commit e4a5a53c20
2 changed files with 12 additions and 6 deletions

View File

@ -32,7 +32,7 @@ pub struct Dependency {
optional: bool, optional: bool,
uses_default_features: bool, uses_default_features: bool,
features: Vec<String>, features: Vec<String>,
target: Option<()>, target: Option<String>,
} }
#[derive(RustcDecodable, Debug)] #[derive(RustcDecodable, Debug)]

View File

@ -128,9 +128,13 @@ pub fn main() {
let args = std::env::args().skip(2); let args = std::env::args().skip(2);
if let Some(first) = target.kind.get(0) { if let Some(first) = target.kind.get(0) {
if target.kind.len() > 1 || first.ends_with("lib") { if target.kind.len() > 1 || first.ends_with("lib") {
process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root); if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root) {
std::process::exit(code);
}
} else if first == "bin" { } else if first == "bin" {
process(vec!["--bin".to_owned(), target.name].into_iter().chain(args), &dep_path, &sys_root); if let Err(code) = process(vec!["--bin".to_owned(), target.name].into_iter().chain(args), &dep_path, &sys_root) {
std::process::exit(code);
}
} }
} else { } else {
panic!("badly formatted cargo metadata: target::kind is an empty array"); panic!("badly formatted cargo metadata: target::kind is an empty array");
@ -152,7 +156,7 @@ pub fn main() {
} }
} }
fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
where P: AsRef<Path>, I: Iterator<Item=String> { where P: AsRef<Path>, I: Iterator<Item=String> {
let mut args = vec!["rustc".to_owned()]; let mut args = vec!["rustc".to_owned()];
@ -178,7 +182,9 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str)
.spawn().expect("could not run cargo") .spawn().expect("could not run cargo")
.wait().expect("failed to wait for cargo?"); .wait().expect("failed to wait for cargo?");
if let Some(code) = exit_status.code() { if exit_status.success() {
std::process::exit(code); Ok(())
} else {
Err(exit_status.code().unwrap_or(-1))
} }
} }