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

Added new metadata fields #5386

Merged
merged 2 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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)
}
}
Expand Down
91 changes: 89 additions & 2 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -285,6 +308,8 @@ fn cargo_metadata_with_deps_and_version() {
"metadata": null
},
{
"authors": [],
"categories": [],
"dependencies": [
{
"features": [],
Expand All @@ -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,
Expand All @@ -322,6 +350,8 @@ fn cargo_metadata_with_deps_and_version() {
"metadata": null
},
{
"authors": [],
"categories": [],
"dependencies": [
{
"features": [],
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -890,7 +968,11 @@ fn package_metadata() {
[package]
name = "foo"
version = "0.1.0"
authors = []
authors = ["wycats@example.com"]
categories = ["database"]
keywords = ["database"]
readme = "README.md"
repository = "https://github.com/rust-lang/cargo"

[package.metadata.bar]
baz = "quux"
Expand All @@ -906,9 +988,14 @@ fn package_metadata() {
{
"packages": [
{
"authors": ["wycats@example.com"],
"categories": ["database"],
"name": "foo",
"readme": "README.md",
"repository": "https://github.com/rust-lang/cargo",
"version": "0.1.0",
"id": "foo[..]",
"keywords": ["database"],
"source": null,
"dependencies": [],
"license": null,
Expand Down
7 changes: 7 additions & 0 deletions tests/testsuite/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down