From d1cacfedf38884df00cafce34246d3f9bef9fac5 Mon Sep 17 00:00:00 2001 From: Yusuf Simonson Date: Wed, 18 Apr 2018 15:08:18 +0700 Subject: [PATCH] Added new metadata fields. `cargo metadata` should now include all of the non-optional suggested fields in the API guidelines (see section C-METADATA.) --- src/cargo/core/package.rs | 15 ++++++ tests/testsuite/metadata.rs | 85 +++++++++++++++++++++++++++++++- tests/testsuite/read_manifest.rs | 7 +++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index ded96734d..39348facc 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -42,6 +42,11 @@ struct SerializedPackage<'a> { features: &'a FeatureMap, manifest_path: &'a str, metadata: Option<&'a toml::Value>, + authors: &'a [String], + categories: &'a [String], + keywords: &'a [String], + readme: Option<&'a str>, + repository: Option<&'a str> } impl ser::Serialize for Package { @@ -55,6 +60,11 @@ impl ser::Serialize for Package { let license = manmeta.license.as_ref().map(String::as_ref); let license_file = manmeta.license_file.as_ref().map(String::as_ref); let description = manmeta.description.as_ref().map(String::as_ref); + let authors = manmeta.authors.as_ref(); + let categories = manmeta.categories.as_ref(); + let keywords = manmeta.keywords.as_ref(); + let readme = manmeta.readme.as_ref().map(String::as_ref); + let repository = manmeta.repository.as_ref().map(String::as_ref); SerializedPackage { name: &*package_id.name(), @@ -69,6 +79,11 @@ impl ser::Serialize for Package { features: summary.features(), manifest_path: &self.manifest_path.display().to_string(), metadata: self.manifest.custom_metadata(), + authors, + categories, + keywords, + readme, + repository, }.serialize(s) } } diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 1eb1dd2e4..0716df585 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -16,14 +16,21 @@ fn cargo_metadata_simple() { { "packages": [ { + "authors": [ + "wycats@example.com" + ], + "categories": [], "name": "foo", "version": "0.5.0", "id": "foo[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, "license_file": null, "description": null, + "readme": null, + "repository": null, "targets": [ { "kind": [ @@ -100,9 +107,14 @@ crate-type = ["lib", "staticlib"] { "packages": [ { + "authors": [], + "categories": [], "name": "foo", + "readme": null, + "repository": null, "version": "0.5.0", "id": "foo[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, @@ -172,9 +184,14 @@ optional_feat = [] { "packages": [ { + "authors": [], + "categories": [], "name": "foo", + "readme": null, + "repository": null, "version": "0.5.0", "id": "foo[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, @@ -260,11 +277,17 @@ fn cargo_metadata_with_deps_and_version() { { "packages": [ { + "authors": [], + "categories": [], "dependencies": [], + "description": null, "features": {}, "id": "baz 0.0.1 (registry+[..])", + "keywords": [], "manifest_path": "[..]Cargo.toml", "name": "baz", + "readme": null, + "repository": null, "source": "registry+[..]", "license": null, "license_file": null, @@ -285,6 +308,8 @@ fn cargo_metadata_with_deps_and_version() { "metadata": null }, { + "authors": [], + "categories": [], "dependencies": [ { "features": [], @@ -300,8 +325,11 @@ fn cargo_metadata_with_deps_and_version() { ], "features": {}, "id": "bar 0.0.1 (registry+[..])", + "keywords": [], "manifest_path": "[..]Cargo.toml", "name": "bar", + "readme": null, + "repository": null, "source": "registry+[..]", "license": null, "license_file": null, @@ -322,6 +350,8 @@ fn cargo_metadata_with_deps_and_version() { "metadata": null }, { + "authors": [], + "categories": [], "dependencies": [ { "features": [], @@ -337,8 +367,11 @@ fn cargo_metadata_with_deps_and_version() { ], "features": {}, "id": "foo 0.5.0 (path+file:[..]foo)", + "keywords": [], "manifest_path": "[..]Cargo.toml", "name": "foo", + "readme": null, + "repository": null, "source": null, "license": "MIT", "license_file": null, @@ -417,9 +450,14 @@ name = "ex" { "packages": [ { + "authors": [], + "categories": [], "name": "foo", + "readme": null, + "repository": null, "version": "0.1.0", "id": "foo[..]", + "keywords": [], "license": null, "license_file": null, "description": null, @@ -491,9 +529,14 @@ crate-type = ["rlib", "dylib"] { "packages": [ { + "authors": [], + "categories": [], "name": "foo", + "readme": null, + "repository": null, "version": "0.1.0", "id": "foo[..]", + "keywords": [], "license": null, "license_file": null, "description": null, @@ -562,9 +605,16 @@ fn workspace_metadata() { { "packages": [ { + "authors": [ + "wycats@example.com" + ], + "categories": [], "name": "bar", "version": "0.5.0", "id": "bar[..]", + "readme": null, + "repository": null, + "keywords": [], "source": null, "dependencies": [], "license": null, @@ -583,9 +633,16 @@ fn workspace_metadata() { "metadata": null }, { + "authors": [ + "wycats@example.com" + ], + "categories": [], "name": "baz", + "readme": null, + "repository": null, "version": "0.5.0", "id": "baz[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, @@ -651,9 +708,16 @@ fn workspace_metadata_no_deps() { { "packages": [ { + "authors": [ + "wycats@example.com" + ], + "categories": [], "name": "bar", + "readme": null, + "repository": null, "version": "0.5.0", "id": "bar[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, @@ -672,9 +736,16 @@ fn workspace_metadata_no_deps() { "metadata": null }, { + "authors": [ + "wycats@example.com" + ], + "categories": [], "name": "baz", + "readme": null, + "repository": null, "version": "0.5.0", "id": "baz[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, @@ -722,11 +793,16 @@ Caused by: const MANIFEST_OUTPUT: &str = r#" { "packages": [{ + "authors": [ + "wycats@example.com" + ], + "categories": [], "name":"foo", "version":"0.5.0", "id":"foo[..]0.5.0[..](path+file://[..]/foo)", "source":null, "dependencies":[], + "keywords": [], "license": null, "license_file": null, "description": null, @@ -738,7 +814,9 @@ const MANIFEST_OUTPUT: &str = r#" }], "features":{}, "manifest_path":"[..]Cargo.toml", - "metadata": null + "metadata": null, + "readme": null, + "repository": null }], "workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ], "resolve": null, @@ -906,9 +984,14 @@ fn package_metadata() { { "packages": [ { + "authors": [], + "categories": [], "name": "foo", + "readme": null, + "repository": null, "version": "0.1.0", "id": "foo[..]", + "keywords": [], "source": null, "dependencies": [], "license": null, diff --git a/tests/testsuite/read_manifest.rs b/tests/testsuite/read_manifest.rs index b03338041..b3d512d8e 100644 --- a/tests/testsuite/read_manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -3,9 +3,16 @@ use hamcrest::assert_that; static MANIFEST_OUTPUT: &'static str = r#" { + "authors": [ + "wycats@example.com" + ], + "categories": [], "name":"foo", + "readme": null, + "repository": null, "version":"0.5.0", "id":"foo[..]0.5.0[..](path+file://[..]/foo)", + "keywords": [], "license": null, "license_file": null, "description": null, -- 2.30.2