From 390af27128eda83d5f7f1d5a6e76734ef8a1880d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 8 Oct 2021 19:00:39 +0200 Subject: [PATCH] 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. --- src/cargo/core/package.rs | 2 + src/doc/man/cargo-metadata.md | 2 + src/doc/man/generated_txt/cargo-metadata.txt | 2 + src/doc/src/commands/cargo-metadata.md | 2 + src/etc/man/cargo-metadata.1 | 2 + tests/testsuite/alt_registry.rs | 9 ++++ tests/testsuite/features_namespaced.rs | 1 + tests/testsuite/git.rs | 2 + tests/testsuite/metadata.rs | 49 ++++++++++++++++++++ tests/testsuite/read_manifest.rs | 1 + tests/testsuite/update.rs | 2 + 11 files changed, 74 insertions(+) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 6605a348e38..724e720866a 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -102,6 +102,7 @@ pub struct SerializedPackage { #[serde(skip_serializing_if = "Option::is_none")] metabuild: Option>, default_run: Option, + rust_version: Option, } 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()), } } } diff --git a/src/doc/man/cargo-metadata.md b/src/doc/man/cargo-metadata.md index 3ef6e8d6884..c1a8920bc2b 100644 --- a/src/doc/man/cargo-metadata.md +++ b/src/doc/man/cargo-metadata.md @@ -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" diff --git a/src/doc/man/generated_txt/cargo-metadata.txt b/src/doc/man/generated_txt/cargo-metadata.txt index 97a1940f660..85394a9decb 100644 --- a/src/doc/man/generated_txt/cargo-metadata.txt +++ b/src/doc/man/generated_txt/cargo-metadata.txt @@ -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" diff --git a/src/doc/src/commands/cargo-metadata.md b/src/doc/src/commands/cargo-metadata.md index 7d856a49aa7..40948340255 100644 --- a/src/doc/src/commands/cargo-metadata.md +++ b/src/doc/src/commands/cargo-metadata.md @@ -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" diff --git a/src/etc/man/cargo-metadata.1 b/src/etc/man/cargo-metadata.1 index dfe79583c45..b35d998ae4b 100644 --- a/src/etc/man/cargo-metadata.1 +++ b/src/etc/man/cargo-metadata.1 @@ -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" diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 5813942ce65..b0580d57eae 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -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", diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index f2003c1182c..5b5ea47e7be 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -715,6 +715,7 @@ fn json_exposed() { "keywords": [], "readme": null, "repository": null, + "rust_version": null, "edition": "2015", "links": null } diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index d7974a3ef87..fb0278e525c 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -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", diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 312603d984f..bc39d86ed0f 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -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", diff --git a/tests/testsuite/read_manifest.rs b/tests/testsuite/read_manifest.rs index 28bf6eed2a7..b5e9f05a34c 100644 --- a/tests/testsuite/read_manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -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": [], diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index d63606693a0..6a3f2fe78e1 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -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": [ {