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

Include the publish field in cargo-metadata output #7354

Merged
merged 3 commits into from
Sep 12, 2019
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
2 changes: 2 additions & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct SerializedPackage<'a> {
features: &'a FeatureMap,
manifest_path: &'a Path,
metadata: Option<&'a toml::Value>,
publish: Option<&'a Vec<String>>,
authors: &'a [String],
categories: &'a [String],
keywords: &'a [String],
Expand Down Expand Up @@ -125,6 +126,7 @@ impl ser::Serialize for Package {
edition: &self.manifest.edition().to_string(),
links: self.manifest.links(),
metabuild: self.manifest.metabuild(),
publish: self.publish().as_ref(),
}
.serialize(s)
}
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/cargo-metadata.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ The output has the following format:
}
}
},
/* List of registries to which this package may be published.
Publishing is unrestricted if null, and forbidden if an empty array. */
"publish": [
"crates-io"
],
/* Array of authors from the manifest.
Empty array if no authors specified.
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ fn alt_reg_metadata() {
"features": {},
"manifest_path": "[..]/foo/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -863,6 +864,7 @@ fn alt_reg_metadata() {
"features": {},
"manifest_path": "[..]/altdep2-0.0.1/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -897,6 +899,7 @@ fn alt_reg_metadata() {
"features": {},
"manifest_path": "[..]/altdep-0.0.1/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -943,6 +946,7 @@ fn alt_reg_metadata() {
"features": {},
"manifest_path": "[..]/foo/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -977,6 +981,7 @@ fn alt_reg_metadata() {
"features": {},
"manifest_path": "[..]/iodep-0.0.1/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand All @@ -998,6 +1003,7 @@ fn alt_reg_metadata() {
"features": {},
"manifest_path": "[..]/bar-0.0.1/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -1076,6 +1082,7 @@ fn unknown_registry() {
"features": {},
"manifest_path": "[..]",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -1110,6 +1117,7 @@ fn unknown_registry() {
"features": {},
"manifest_path": "[..]/foo/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down Expand Up @@ -1144,6 +1152,7 @@ fn unknown_registry() {
"features": {},
"manifest_path": "[..]",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
Expand Down
109 changes: 99 additions & 10 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ fn cargo_metadata_simple() {
],
"features": {},
"manifest_path": "[..]Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
Expand Down Expand Up @@ -138,7 +139,8 @@ crate-type = ["lib", "staticlib"]
],
"features": {},
"manifest_path": "[..]Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
Expand Down Expand Up @@ -223,7 +225,8 @@ optional_feat = []
"optional_feat": []
},
"manifest_path": "[..]Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
Expand Down Expand Up @@ -296,6 +299,7 @@ fn cargo_metadata_with_deps_and_version() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "baz",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -355,6 +359,7 @@ fn cargo_metadata_with_deps_and_version() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "foo",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -389,6 +394,7 @@ fn cargo_metadata_with_deps_and_version() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "foobar",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -436,6 +442,7 @@ fn cargo_metadata_with_deps_and_version() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "bar",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -575,7 +582,8 @@ name = "ex"
],
"features": {},
"manifest_path": "[..]Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": [
Expand Down Expand Up @@ -660,7 +668,8 @@ crate-type = ["rlib", "dylib"]
],
"features": {},
"manifest_path": "[..]Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": [
Expand Down Expand Up @@ -736,7 +745,8 @@ fn workspace_metadata() {
],
"features": {},
"manifest_path": "[..]bar/Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
},
{
"authors": [
Expand Down Expand Up @@ -768,7 +778,8 @@ fn workspace_metadata() {
],
"features": {},
"manifest_path": "[..]baz/Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
Expand Down Expand Up @@ -848,7 +859,8 @@ fn workspace_metadata_no_deps() {
],
"features": {},
"manifest_path": "[..]bar/Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
},
{
"authors": [
Expand Down Expand Up @@ -880,7 +892,8 @@ fn workspace_metadata_no_deps() {
],
"features": {},
"manifest_path": "[..]baz/Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}
],
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
Expand Down Expand Up @@ -938,6 +951,7 @@ const MANIFEST_OUTPUT: &str = r#"
"features":{},
"manifest_path":"[..]Cargo.toml",
"metadata": null,
"publish": null,
"readme": null,
"repository": null
}],
Expand Down Expand Up @@ -1121,7 +1135,75 @@ fn package_metadata() {
"bar": {
"baz": "quux"
}
}
},
"publish": null
}
],
"workspace_members": ["foo[..]"],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
"workspace_root": "[..]/foo"
}"#,
)
.run();
}

#[cargo_test]
fn package_publish() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = ["wycats@example.com"]
categories = ["database"]
keywords = ["database"]
readme = "README.md"
repository = "https://github.com/rust-lang/cargo"
publish = ["my-registry"]
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("metadata --no-deps")
.with_json(
r#"
{
"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": [],
"edition": "2015",
"license": null,
"license_file": null,
"links": null,
"description": null,
"targets": [
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doctest": true,
"edition": "2015",
"name": "foo",
"src_path": "[..]foo/src/lib.rs"
}
],
"features": {},
"manifest_path": "[..]foo/Cargo.toml",
"metadata": null,
"publish": ["my-registry"]
}
],
"workspace_members": ["foo[..]"],
Expand Down Expand Up @@ -1175,6 +1257,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "bar",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -1255,6 +1338,7 @@ fn package_edition_2018() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "foo",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -1339,6 +1423,7 @@ fn target_edition_2018() {
"links": null,
"manifest_path": "[..]Cargo.toml",
"metadata": null,
"publish": null,
"name": "foo",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -1461,6 +1546,7 @@ fn rename_dependency() {
"links": null,
"manifest_path": "[..]",
"metadata": null,
"publish": null,
"name": "foo",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -1495,6 +1581,7 @@ fn rename_dependency() {
"links": null,
"manifest_path": "[..]",
"metadata": null,
"publish": null,
"name": "bar",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -1529,6 +1616,7 @@ fn rename_dependency() {
"links": null,
"manifest_path": "[..]",
"metadata": null,
"publish": null,
"name": "bar",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -1631,6 +1719,7 @@ fn metadata_links() {
"links": "a",
"manifest_path": "[..]/foo/Cargo.toml",
"metadata": null,
"publish": null,
"name": "foo",
"readme": null,
"repository": null,
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ static MANIFEST_OUTPUT: &str = r#"
}],
"features":{},
"manifest_path":"[..]Cargo.toml",
"metadata": null
"metadata": null,
"publish": null
}"#;

#[cargo_test]
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ fn update_precise_first_run() {
"links": null,
"manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml",
"metadata": null,
"publish": null,
"name": "serde",
"readme": null,
"repository": null,
Expand Down Expand Up @@ -494,6 +495,7 @@ fn update_precise_first_run() {
"links": null,
"manifest_path": "[..]/foo/Cargo.toml",
"metadata": null,
"publish": null,
"name": "bar",
"readme": null,
"repository": null,
Expand Down