diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index ec3c7faf8b9..a64e4d84e46 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -67,6 +67,7 @@ struct SerializedPackage<'a> { features: &'a FeatureMap, manifest_path: &'a Path, metadata: Option<&'a toml::Value>, + publish: Option<&'a Vec>, authors: &'a [String], categories: &'a [String], keywords: &'a [String], @@ -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) } diff --git a/src/doc/man/cargo-metadata.adoc b/src/doc/man/cargo-metadata.adoc index cffad736831..906cb999e8f 100644 --- a/src/doc/man/cargo-metadata.adoc +++ b/src/doc/man/cargo-metadata.adoc @@ -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. */ diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index edeb67a6b7d..fd5729e6073 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -824,6 +824,7 @@ fn alt_reg_metadata() { "features": {}, "manifest_path": "[..]/foo/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -863,6 +864,7 @@ fn alt_reg_metadata() { "features": {}, "manifest_path": "[..]/altdep2-0.0.1/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -897,6 +899,7 @@ fn alt_reg_metadata() { "features": {}, "manifest_path": "[..]/altdep-0.0.1/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -943,6 +946,7 @@ fn alt_reg_metadata() { "features": {}, "manifest_path": "[..]/foo/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -977,6 +981,7 @@ fn alt_reg_metadata() { "features": {}, "manifest_path": "[..]/iodep-0.0.1/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -998,6 +1003,7 @@ fn alt_reg_metadata() { "features": {}, "manifest_path": "[..]/bar-0.0.1/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -1076,6 +1082,7 @@ fn unknown_registry() { "features": {}, "manifest_path": "[..]", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -1110,6 +1117,7 @@ fn unknown_registry() { "features": {}, "manifest_path": "[..]/foo/Cargo.toml", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], @@ -1144,6 +1152,7 @@ fn unknown_registry() { "features": {}, "manifest_path": "[..]", "metadata": null, + "publish": null, "authors": [], "categories": [], "keywords": [], diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 10f5636c67d..713c9d4a83a 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -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)"], @@ -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)"], @@ -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)"], @@ -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, @@ -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, @@ -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, @@ -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, @@ -575,7 +582,8 @@ name = "ex" ], "features": {}, "manifest_path": "[..]Cargo.toml", - "metadata": null + "metadata": null, + "publish": null } ], "workspace_members": [ @@ -660,7 +668,8 @@ crate-type = ["rlib", "dylib"] ], "features": {}, "manifest_path": "[..]Cargo.toml", - "metadata": null + "metadata": null, + "publish": null } ], "workspace_members": [ @@ -736,7 +745,8 @@ fn workspace_metadata() { ], "features": {}, "manifest_path": "[..]bar/Cargo.toml", - "metadata": null + "metadata": null, + "publish": null }, { "authors": [ @@ -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)"], @@ -848,7 +859,8 @@ fn workspace_metadata_no_deps() { ], "features": {}, "manifest_path": "[..]bar/Cargo.toml", - "metadata": null + "metadata": null, + "publish": null }, { "authors": [ @@ -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)"], @@ -938,6 +951,7 @@ const MANIFEST_OUTPUT: &str = r#" "features":{}, "manifest_path":"[..]Cargo.toml", "metadata": null, + "publish": null, "readme": null, "repository": null }], @@ -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[..]"], @@ -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, @@ -1255,6 +1338,7 @@ fn package_edition_2018() { "links": null, "manifest_path": "[..]Cargo.toml", "metadata": null, + "publish": null, "name": "foo", "readme": null, "repository": null, @@ -1339,6 +1423,7 @@ fn target_edition_2018() { "links": null, "manifest_path": "[..]Cargo.toml", "metadata": null, + "publish": null, "name": "foo", "readme": null, "repository": null, @@ -1461,6 +1546,7 @@ fn rename_dependency() { "links": null, "manifest_path": "[..]", "metadata": null, + "publish": null, "name": "foo", "readme": null, "repository": null, @@ -1495,6 +1581,7 @@ fn rename_dependency() { "links": null, "manifest_path": "[..]", "metadata": null, + "publish": null, "name": "bar", "readme": null, "repository": null, @@ -1529,6 +1616,7 @@ fn rename_dependency() { "links": null, "manifest_path": "[..]", "metadata": null, + "publish": null, "name": "bar", "readme": null, "repository": null, @@ -1631,6 +1719,7 @@ fn metadata_links() { "links": "a", "manifest_path": "[..]/foo/Cargo.toml", "metadata": null, + "publish": null, "name": "foo", "readme": null, "repository": null, diff --git a/tests/testsuite/read_manifest.rs b/tests/testsuite/read_manifest.rs index 61e520f1499..b72060f3faf 100644 --- a/tests/testsuite/read_manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -29,7 +29,8 @@ static MANIFEST_OUTPUT: &str = r#" }], "features":{}, "manifest_path":"[..]Cargo.toml", - "metadata": null + "metadata": null, + "publish": null }"#; #[cargo_test] diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 468458563b0..eaeb806138a 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -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, @@ -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,