Add rust_metadata to SerializedPackage

After the rust_version field was stabilized in #9732 this adds the
rust_version as output to the `cargo metadata` command, so tools like
Clippy can read and use it as well.
This commit is contained in:
flip1995 2021-10-08 19:00:39 +02:00
parent dea587a61c
commit 390af27128
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
11 changed files with 74 additions and 0 deletions

View file

@ -102,6 +102,7 @@ pub struct SerializedPackage {
#[serde(skip_serializing_if = "Option::is_none")]
metabuild: Option<Vec<String>>,
default_run: Option<String>,
rust_version: Option<String>,
}
impl Package {
@ -268,6 +269,7 @@ impl Package {
metabuild: self.manifest().metabuild().cloned(),
publish: self.publish().as_ref().cloned(),
default_run: self.manifest().default_run().map(|s| s.to_owned()),
rust_version: self.rust_version().map(|s| s.to_owned()),
}
}
}

View file

@ -182,6 +182,8 @@ The output has the following format:
],
/* Optional string that is the default binary picked by cargo run. */
"default_run": null,
/* Optional string that is the minimum supported rust version */
"rust_version": "1.56",
/* Array of keywords from the manifest. */
"keywords": [
"cli"

View file

@ -177,6 +177,8 @@ OUTPUT FORMAT
],
/* Optional string that is the default binary picked by cargo run. */
"default_run": null,
/* Optional string that is the minimum supported rust version */
"rust_version": "1.56",
/* Array of keywords from the manifest. */
"keywords": [
"cli"

View file

@ -182,6 +182,8 @@ The output has the following format:
],
/* Optional string that is the default binary picked by cargo run. */
"default_run": null,
/* Optional string that is the minimum supported rust version */
"rust_version": "1.56",
/* Array of keywords from the manifest. */
"keywords": [
"cli"

View file

@ -179,6 +179,8 @@ The output has the following format:
],
/* Optional string that is the default binary picked by cargo run. */
"default_run": null,
/* Optional string that is the minimum supported rust version */
"rust_version": "1.56",
/* Array of keywords from the manifest. */
"keywords": [
"cli"

View file

@ -823,6 +823,7 @@ fn alt_reg_metadata() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -880,6 +881,7 @@ fn alt_reg_metadata() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -905,6 +907,7 @@ fn alt_reg_metadata() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -930,6 +933,7 @@ fn alt_reg_metadata() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -980,6 +984,7 @@ fn alt_reg_metadata() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -1018,6 +1023,7 @@ fn alt_reg_metadata() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -1115,6 +1121,7 @@ fn unknown_registry() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -1140,6 +1147,7 @@ fn unknown_registry() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -1178,6 +1186,7 @@ fn unknown_registry() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",

View file

@ -715,6 +715,7 @@ fn json_exposed() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"edition": "2015",
"links": null
}

View file

@ -3147,6 +3147,7 @@ fn metadata_master_consistency() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -3185,6 +3186,7 @@ fn metadata_master_consistency() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",

View file

@ -37,6 +37,7 @@ fn cargo_metadata_simple() {
"description": null,
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"homepage": null,
@ -128,6 +129,7 @@ crate-type = ["lib", "staticlib"]
"homepage": null,
"documentation": null,
"version": "0.5.0",
"rust_version": null,
"id": "foo[..]",
"keywords": [],
"source": null,
@ -213,6 +215,7 @@ optional_feat = []
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.5.0",
@ -342,6 +345,7 @@ fn cargo_metadata_with_deps_and_version() {
"name": "bar",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
@ -382,6 +386,7 @@ fn cargo_metadata_with_deps_and_version() {
"name": "baz",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
@ -447,6 +452,7 @@ fn cargo_metadata_with_deps_and_version() {
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": null,
@ -487,6 +493,7 @@ fn cargo_metadata_with_deps_and_version() {
"name": "foobar",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
@ -617,6 +624,7 @@ name = "ex"
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.1.0",
@ -711,6 +719,7 @@ crate-type = ["rlib", "dylib"]
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.1.0",
@ -814,6 +823,7 @@ fn workspace_metadata() {
"id": "bar[..]",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"keywords": [],
@ -850,6 +860,7 @@ fn workspace_metadata() {
"name": "baz",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.5.0",
@ -943,6 +954,7 @@ fn workspace_metadata_no_deps() {
"name": "bar",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.5.0",
@ -981,6 +993,7 @@ fn workspace_metadata_no_deps() {
"name": "baz",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.5.0",
@ -1073,6 +1086,7 @@ const MANIFEST_OUTPUT: &str = r#"
"publish": null,
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null
}],
@ -1235,6 +1249,7 @@ fn package_metadata() {
"name": "foo",
"readme": "README.md",
"repository": "https://github.com/rust-lang/cargo",
"rust_version": null,
"homepage": "https://rust-lang.org",
"documentation": "https://doc.rust-lang.org/stable/std/",
"version": "0.1.0",
@ -1313,6 +1328,7 @@ fn package_publish() {
"name": "foo",
"readme": "README.md",
"repository": "https://github.com/rust-lang/cargo",
"rust_version": null,
"homepage": null,
"documentation": null,
"version": "0.1.0",
@ -1400,6 +1416,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"name": "bar",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": null,
@ -1487,6 +1504,7 @@ fn package_edition_2018() {
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": null,
@ -1555,6 +1573,26 @@ fn package_default_run() {
assert_eq!(json["packages"][0]["default_run"], json!("a"));
}
#[cargo_test]
fn package_rust_version() {
let p = project()
.file("src/lib.rs", "")
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.1.0"
authors = ["wycats@example.com"]
edition = "2018"
rust-version = "1.56"
"#,
)
.build();
let json = p.cargo("metadata").run_json();
assert_eq!(json["packages"][0]["rust_version"], json!("1.56"));
}
#[cargo_test]
fn target_edition_2018() {
let p = project()
@ -1600,6 +1638,7 @@ fn target_edition_2018() {
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": null,
@ -1706,6 +1745,7 @@ fn rename_dependency() {
"name": "bar",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
@ -1746,6 +1786,7 @@ fn rename_dependency() {
"name": "bar",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
@ -1811,6 +1852,7 @@ fn rename_dependency() {
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": null,
@ -1932,6 +1974,7 @@ fn metadata_links() {
"name": "foo",
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"source": null,
@ -2064,6 +2107,7 @@ fn deps_with_bin_only() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -2168,6 +2212,7 @@ fn filter_platform() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -2211,6 +2256,7 @@ fn filter_platform() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -2254,6 +2300,7 @@ fn filter_platform() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -2297,6 +2344,7 @@ fn filter_platform() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",
@ -2403,6 +2451,7 @@ fn filter_platform() {
"keywords": [],
"readme": null,
"repository": null,
"rust_version": null,
"homepage": null,
"documentation": null,
"edition": "2015",

View file

@ -16,6 +16,7 @@ fn manifest_output(readme_value: &str) -> String {
"homepage": null,
"documentation": null,
"repository": null,
"rust_version": null,
"version":"0.5.0",
"id":"foo[..]0.5.0[..](path+file://[..]/foo)",
"keywords": [],

View file

@ -464,6 +464,7 @@ fn update_precise_first_run() {
"name": "bar",
"readme": null,
"repository": null,
"rust_version": null,
"source": null,
"targets": [
{
@ -504,6 +505,7 @@ fn update_precise_first_run() {
"name": "serde",
"readme": null,
"repository": null,
"rust_version": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
"targets": [
{