Don't assume the first package in the result of cargo metadata is the current crate.

Instead find the one with the manifest path that matches the --manifest-path argument or the current directory.

Fixes #1247
This commit is contained in:
Arnavion
2016-10-22 18:15:42 -07:00
parent 984e15a0c0
commit ebbd00b1ab
3 changed files with 28 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ pub struct Package {
pub dependencies: Vec<Dependency>,
pub targets: Vec<Target>,
features: HashMap<String, Vec<String>>,
manifest_path: String,
pub manifest_path: String,
}
#[derive(RustcDecodable, Debug)]
@@ -65,10 +65,10 @@ impl From<json::DecoderError> for Error {
}
}
pub fn metadata(manifest_path: Option<String>) -> Result<Metadata, Error> {
pub fn metadata(manifest_path_arg: &Option<String>) -> Result<Metadata, Error> {
let mut cmd = Command::new("cargo");
cmd.arg("metadata").arg("--no-deps");
if let Some(ref mani) = manifest_path {
if let Some(ref mani) = *manifest_path_arg {
cmd.arg(mani);
}
let output = cmd.output()?;