Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverted the "kind" field to the previous value. #3668

Merged
merged 8 commits into from
Feb 11, 2017
41 changes: 29 additions & 12 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,34 @@ pub enum TargetKind {
CustomBuild,
}

impl Encodable for TargetKind {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
impl TargetKind {
/// Returns a vector of crate types as specified in a manifest with one difference.
/// For ExampleLib it returns "example" instead of crate types
pub fn kinds(&self) -> Vec<&str> {
use self::TargetKind::*;
match *self {
TargetKind::Lib(ref kinds) |
TargetKind::ExampleLib(ref kinds) => {
Lib(ref kinds) => kinds.iter().map(LibKind::crate_type).collect(),
Bin => vec!["bin"],
ExampleBin | ExampleLib(_) => vec!["example"],
Test => vec!["test"],
CustomBuild => vec!["custom-build"],
Bench => vec!["bench"]
}
}

/// 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()
}
TargetKind::Bin => vec!["bin"],
TargetKind::ExampleBin => vec!["example"],
TargetKind::Test => vec!["test"],
TargetKind::CustomBuild => vec!["custom-build"],
TargetKind::Bench => vec!["bench"],
}.encode(s)
Bin => vec!["bin"],
ExampleBin => vec!["example"],
Test => vec!["test"],
CustomBuild => vec!["custom-build"],
Bench => vec!["bench"]
}
}
}

Expand Down Expand Up @@ -196,15 +211,17 @@ pub struct Target {

#[derive(RustcEncodable)]
struct SerializedTarget<'a> {
kind: &'a TargetKind,
kind: Vec<&'a str>,
crate_types: Vec<&'a str>,
name: &'a str,
src_path: &'a str,
}

impl Encodable for Target {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
SerializedTarget {
kind: &self.kind,
kind: self.kind.kinds(),
crate_types: self.kind.crate_types(),
name: &self.name,
src_path: &self.src_path.display().to_string(),
}.encode(s)
Expand Down
42 changes: 36 additions & 6 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,12 @@ fn compiler_json_error_format() {
{
"reason":"compiler-message",
"package_id":"bar 0.5.0 ([..])",
"target":{"kind":["lib"],"name":"bar","src_path":"[..]lib.rs"},
"target":{
"kind":["lib"],
"crate_types":["lib"],
"name":"bar",
"src_path":"[..]lib.rs"
},
"message":"{...}"
}

Expand All @@ -2524,21 +2529,36 @@ fn compiler_json_error_format() {
},
"features": [],
"package_id":"bar 0.5.0 ([..])",
"target":{"kind":["lib"],"name":"bar","src_path":"[..]lib.rs"},
"target":{
"kind":["lib"],
"crate_types":["lib"],
"name":"bar",
"src_path":"[..]lib.rs"
},
"filenames":["[..].rlib"]
}

{
"reason":"compiler-message",
"package_id":"foo 0.5.0 ([..])",
"target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
"target":{
"kind":["bin"],
"crate_types":["bin"],
"name":"foo",
"src_path":"[..]main.rs"
},
"message":"{...}"
}

{
"reason":"compiler-artifact",
"package_id":"foo 0.5.0 ([..])",
"target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
"target":{
"kind":["bin"],
"crate_types":["bin"],
"name":"foo",
"src_path":"[..]main.rs"
},
"profile": {
"debug_assertions": true,
"debuginfo": 2,
Expand Down Expand Up @@ -2580,14 +2600,24 @@ fn message_format_json_forward_stderr() {
{
"reason":"compiler-message",
"package_id":"foo 0.5.0 ([..])",
"target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
"target":{
"kind":["bin"],
"crate_types":["bin"],
"name":"foo",
"src_path":"[..]"
},
"message":"{...}"
}

{
"reason":"compiler-artifact",
"package_id":"foo 0.5.0 ([..])",
"target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
"target":{
"kind":["bin"],
"crate_types":["bin"],
"name":"foo",
"src_path":"[..]"
},
"profile":{
"debug_assertions":true,
"debuginfo":2,
Expand Down
Loading