Merge pull request #974 from oli-obk/metadata2

process more kinds of metadata
This commit is contained in:
Martin Carton 2016-06-02 17:46:52 +02:00
commit d7df882fa0
2 changed files with 11 additions and 19 deletions

View File

@ -16,7 +16,7 @@ pub struct Package {
pub name: String, pub name: String,
pub version: String, pub version: String,
id: String, id: String,
source: Option<()>, source: Option<String>,
pub dependencies: Vec<Dependency>, pub dependencies: Vec<Dependency>,
pub targets: Vec<Target>, pub targets: Vec<Target>,
features: HashMap<String, Vec<String>>, features: HashMap<String, Vec<String>>,
@ -31,23 +31,14 @@ pub struct Dependency {
kind: Option<String>, kind: Option<String>,
optional: bool, optional: bool,
uses_default_features: bool, uses_default_features: bool,
features: Vec<HashMap<String, String>>, features: Vec<String>,
target: Option<()>, target: Option<()>,
} }
#[allow(non_camel_case_types)]
#[derive(RustcDecodable, Debug)]
pub enum Kind {
dylib,
test,
bin,
lib,
}
#[derive(RustcDecodable, Debug)] #[derive(RustcDecodable, Debug)]
pub struct Target { pub struct Target {
pub name: String, pub name: String,
pub kind: Vec<Kind>, pub kind: Vec<String>,
src_path: String, src_path: String,
} }

View File

@ -126,13 +126,14 @@ pub fn main() {
assert_eq!(metadata.version, 1); assert_eq!(metadata.version, 1);
for target in metadata.packages.remove(0).targets { for target in metadata.packages.remove(0).targets {
let args = std::env::args().skip(2); let args = std::env::args().skip(2);
assert_eq!(target.kind.len(), 1); if let Some(first) = target.kind.get(0) {
match &target.kind[..] { if target.kind.len() > 1 || first.ends_with("lib") {
[cargo::Kind::lib] | process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root);
[cargo::Kind::dylib] => process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root), } else if first == "bin" {
[cargo::Kind::bin] => process(vec!["--bin".to_owned(), target.name].into_iter().chain(args), &dep_path, &sys_root), process(vec!["--bin".to_owned(), target.name].into_iter().chain(args), &dep_path, &sys_root);
// don't process tests and other stuff }
_ => {}, } else {
panic!("badly formatted cargo metadata: target::kind is an empty array");
} }
} }
} else { } else {