Skip to content

Commit

Permalink
Auto merge of #3862 - matklad:crate-types, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix crate_types in serialized targets

closes #3840
  • Loading branch information
bors committed Mar 24, 2017
2 parents 20f6eff + 90bcf5c commit 64395de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
23 changes: 5 additions & 18 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,6 @@ pub enum TargetKind {
CustomBuild,
}

impl TargetKind {
/// Returns a vector of crate types as specified in a manifest
pub fn crate_types(&self) -> Vec<&str> {
use self::TargetKind::*;
match *self {
Lib(ref kinds) | ExampleLib(ref kinds) => {
kinds.iter().map(LibKind::crate_type).collect()
}
Bin => vec!["bin"],
ExampleBin => vec!["example"],
Test => vec!["test"],
CustomBuild => vec!["custom-build"],
Bench => vec!["bench"]
}
}
}

impl ser::Serialize for TargetKind {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer,
Expand Down Expand Up @@ -207,7 +190,11 @@ pub struct Target {

#[derive(Serialize)]
struct SerializedTarget<'a> {
/// Is this a `--bin bin`, `--lib`, `--example ex`?
/// Serialized as a list of strings for historical reasons.
kind: &'a TargetKind,
/// Corresponds to `--crate-type` compiler attribute.
/// See https://doc.rust-lang.org/reference.html#linkage
crate_types: Vec<&'a str>,
name: &'a str,
src_path: &'a PathBuf,
Expand All @@ -217,7 +204,7 @@ impl ser::Serialize for Target {
fn serialize<S: ser::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
SerializedTarget {
kind: &self.kind,
crate_types: self.kind.crate_types(),
crate_types: self.rustc_crate_types(),
name: &self.name,
src_path: &self.src_path,
}.serialize(s)
Expand Down
2 changes: 1 addition & 1 deletion tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ name = "ex"
},
{
"kind": [ "example" ],
"crate_types": [ "example" ],
"crate_types": [ "bin" ],
"name": "ex",
"src_path": "[..][/]foo[/]examples[/]ex.rs"
}
Expand Down

0 comments on commit 64395de

Please sign in to comment.