Skip to content

Commit

Permalink
Add edition field into target object in metadata as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Undin committed Jul 31, 2018
1 parent 62cd0db commit 5dcc4f1
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct SerializedTarget<'a> {
crate_types: Vec<&'a str>,
name: &'a str,
src_path: &'a PathBuf,
edition: &'a str,
}

impl ser::Serialize for Target {
Expand All @@ -240,6 +241,7 @@ impl ser::Serialize for Target {
crate_types: self.rustc_crate_types(),
name: &self.name,
src_path: &self.src_path.path,
edition: &self.edition.to_string()
}.serialize(s)
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["custom-build"],
"crate_types":["bin"],
"edition": "2015",
"name":"build-script-build",
"src_path":"[..]build.rs"
},
Expand All @@ -3420,6 +3421,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"edition": "2015",
"name":"bar",
"src_path":"[..]lib.rs"
},
Expand All @@ -3440,6 +3442,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"edition": "2015",
"name":"bar",
"src_path":"[..]lib.rs"
},
Expand All @@ -3462,6 +3465,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..]main.rs"
},
Expand All @@ -3474,6 +3478,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..]main.rs"
},
Expand Down Expand Up @@ -3504,6 +3509,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["custom-build"],
"crate_types":["bin"],
"edition": "2015",
"name":"build-script-build",
"src_path":"[..]build.rs"
},
Expand Down Expand Up @@ -3533,6 +3539,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"edition": "2015",
"name":"bar",
"src_path":"[..]lib.rs"
},
Expand All @@ -3555,6 +3562,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..]main.rs"
},
Expand Down Expand Up @@ -3614,6 +3622,7 @@ fn message_format_json_forward_stderr() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..]"
},
Expand All @@ -3626,6 +3635,7 @@ fn message_format_json_forward_stderr() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..]"
},
Expand Down
117 changes: 115 additions & 2 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn cargo_metadata_simple() {
"crate_types": [
"bin"
],
"edition": "2015",
"name": "foo",
"src_path": "[..][/]foo[/]src[/]foo.rs"
}
Expand Down Expand Up @@ -132,6 +133,7 @@ crate-type = ["lib", "staticlib"]
"lib",
"staticlib"
],
"edition": "2015",
"name": "foo",
"src_path": "[..][/]foo[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -208,6 +210,7 @@ optional_feat = []
"crate_types": [
"lib"
],
"edition": "2015",
"name": "foo",
"src_path": "[..][/]foo[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -304,6 +307,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"lib"
],
"edition": "2015",
"name": "baz",
"src_path": "[..]lib.rs"
}
Expand Down Expand Up @@ -347,6 +351,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"lib"
],
"edition": "2015",
"name": "bar",
"src_path": "[..]lib.rs"
}
Expand Down Expand Up @@ -390,6 +395,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"bin"
],
"edition": "2015",
"name": "foo",
"src_path": "[..]foo.rs"
}
Expand Down Expand Up @@ -474,12 +480,14 @@ name = "ex"
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"edition": "2015",
"name": "foo",
"src_path": "[..][/]foo[/]src[/]lib.rs"
},
{
"kind": [ "example" ],
"crate_types": [ "bin" ],
"edition": "2015",
"name": "ex",
"src_path": "[..][/]foo[/]examples[/]ex.rs"
}
Expand Down Expand Up @@ -554,12 +562,14 @@ crate-type = ["rlib", "dylib"]
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"edition": "2015",
"name": "foo",
"src_path": "[..][/]foo[/]src[/]lib.rs"
},
{
"kind": [ "example" ],
"crate_types": [ "rlib", "dylib" ],
"edition": "2015",
"name": "ex",
"src_path": "[..][/]foo[/]examples[/]ex.rs"
}
Expand Down Expand Up @@ -633,6 +643,7 @@ fn workspace_metadata() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"edition": "2015",
"name": "bar",
"src_path": "[..]bar[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -662,6 +673,7 @@ fn workspace_metadata() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"edition": "2015",
"name": "baz",
"src_path": "[..]baz[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -738,6 +750,7 @@ fn workspace_metadata_no_deps() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"edition": "2015",
"name": "bar",
"src_path": "[..]bar[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -767,6 +780,7 @@ fn workspace_metadata_no_deps() {
{
"kind": [ "lib" ],
"crate_types": ["lib"],
"edition": "2015",
"name": "baz",
"src_path": "[..]baz[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -822,6 +836,7 @@ const MANIFEST_OUTPUT: &str = r#"
"targets":[{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..][/]foo[/]src[/]foo.rs"
}],
Expand Down Expand Up @@ -1019,6 +1034,7 @@ fn package_metadata() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"edition": "2015",
"name": "foo",
"src_path": "[..]foo[/]src[/]lib.rs"
}
Expand Down Expand Up @@ -1096,6 +1112,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"crate_types": [
"lib"
],
"edition": "2015",
"kind": [
"lib"
],
Expand Down Expand Up @@ -1129,7 +1146,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
}

#[test]
fn edition_2018() {
fn package_edition_2018() {
let p = project()
.file("src/lib.rs", "")
.file(
Expand Down Expand Up @@ -1175,11 +1192,107 @@ fn edition_2018() {
"crate_types": [
"lib"
],
"edition": "2018",
"kind": [
"lib"
],
"name": "foo",
"src_path": "[..]src[/]lib.rs"
"src_path": "[..]src/lib.rs"
}
],
"version": "0.1.0"
}
],
"resolve": {
"nodes": [
{
"dependencies": [],
"features": [],
"id": "foo 0.1.0 (path+file:[..])"
}
],
"root": "foo 0.1.0 (path+file:[..])"
},
"target_directory": "[..]",
"version": 1,
"workspace_members": [
"foo 0.1.0 (path+file:[..])"
],
"workspace_root": "[..]"
}
"#,
),
);
}

#[test]
fn target_edition_2018() {
let p = project()
.file("src/lib.rs", "")
.file("src/main.rs", "")
.file(
"Cargo.toml",
r#"
cargo-features = ["edition"]
[package]
name = "foo"
version = "0.1.0"
authors = ["[email protected]"]
edition = "2015"
[lib]
edition = "2018"
"#,
)
.build();
assert_that(
p.cargo("metadata").masquerade_as_nightly_cargo(),
execs().with_status(0).with_json(
r#"
{
"packages": [
{
"authors": [
"[email protected]"
],
"categories": [],
"dependencies": [],
"description": null,
"edition": "2015",
"features": {},
"id": "foo 0.1.0 (path+file:[..])",
"keywords": [],
"license": null,
"license_file": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"name": "foo",
"readme": null,
"repository": null,
"source": null,
"targets": [
{
"crate_types": [
"lib"
],
"edition": "2018",
"kind": [
"lib"
],
"name": "foo",
"src_path": "[..]src/lib.rs"
},
{
"crate_types": [
"bin"
],
"edition": "2015",
"kind": [
"bin"
],
"name": "foo",
"src_path": "[..]src/main.rs"
}
],
"version": "0.1.0"
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static MANIFEST_OUTPUT: &'static str = r#"
"targets":[{
"kind":["bin"],
"crate_types":["bin"],
"edition": "2015",
"name":"foo",
"src_path":"[..][/]foo[/]src[/]foo.rs"
}],
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,7 @@ fn json_artifact_includes_test_flag() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"edition": "2015",
"name":"foo",
"src_path":"[..]lib.rs"
},
Expand All @@ -3512,6 +3513,7 @@ fn json_artifact_includes_test_flag() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"edition": "2015",
"name":"foo",
"src_path":"[..]lib.rs"
},
Expand Down

0 comments on commit 5dcc4f1

Please sign in to comment.