Skip to content

Commit 59f50ab

Browse files
committed
Auto merge of #7354 - sfackler:publish-in-manifest, r=alexcrichton
Include the publish field in cargo-metadata output r? @alexcrichton
2 parents 4a58255 + 84d08bd commit 59f50ab

File tree

6 files changed

+119
-11
lines changed

6 files changed

+119
-11
lines changed

src/cargo/core/package.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct SerializedPackage<'a> {
6767
features: &'a FeatureMap,
6868
manifest_path: &'a Path,
6969
metadata: Option<&'a toml::Value>,
70+
publish: Option<&'a Vec<String>>,
7071
authors: &'a [String],
7172
categories: &'a [String],
7273
keywords: &'a [String],
@@ -125,6 +126,7 @@ impl ser::Serialize for Package {
125126
edition: &self.manifest.edition().to_string(),
126127
links: self.manifest.links(),
127128
metabuild: self.manifest.metabuild(),
129+
publish: self.publish().as_ref(),
128130
}
129131
.serialize(s)
130132
}

src/doc/man/cargo-metadata.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ The output has the following format:
160160
}
161161
}
162162
},
163+
/* List of registries to which this package may be published.
164+
Publishing is unrestricted if null, and forbidden if an empty array. */
165+
"publish": [
166+
"crates-io"
167+
],
163168
/* Array of authors from the manifest.
164169
Empty array if no authors specified.
165170
*/

tests/testsuite/alt_registry.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ fn alt_reg_metadata() {
824824
"features": {},
825825
"manifest_path": "[..]/foo/Cargo.toml",
826826
"metadata": null,
827+
"publish": null,
827828
"authors": [],
828829
"categories": [],
829830
"keywords": [],
@@ -863,6 +864,7 @@ fn alt_reg_metadata() {
863864
"features": {},
864865
"manifest_path": "[..]/altdep2-0.0.1/Cargo.toml",
865866
"metadata": null,
867+
"publish": null,
866868
"authors": [],
867869
"categories": [],
868870
"keywords": [],
@@ -897,6 +899,7 @@ fn alt_reg_metadata() {
897899
"features": {},
898900
"manifest_path": "[..]/altdep-0.0.1/Cargo.toml",
899901
"metadata": null,
902+
"publish": null,
900903
"authors": [],
901904
"categories": [],
902905
"keywords": [],
@@ -943,6 +946,7 @@ fn alt_reg_metadata() {
943946
"features": {},
944947
"manifest_path": "[..]/foo/Cargo.toml",
945948
"metadata": null,
949+
"publish": null,
946950
"authors": [],
947951
"categories": [],
948952
"keywords": [],
@@ -977,6 +981,7 @@ fn alt_reg_metadata() {
977981
"features": {},
978982
"manifest_path": "[..]/iodep-0.0.1/Cargo.toml",
979983
"metadata": null,
984+
"publish": null,
980985
"authors": [],
981986
"categories": [],
982987
"keywords": [],
@@ -998,6 +1003,7 @@ fn alt_reg_metadata() {
9981003
"features": {},
9991004
"manifest_path": "[..]/bar-0.0.1/Cargo.toml",
10001005
"metadata": null,
1006+
"publish": null,
10011007
"authors": [],
10021008
"categories": [],
10031009
"keywords": [],
@@ -1076,6 +1082,7 @@ fn unknown_registry() {
10761082
"features": {},
10771083
"manifest_path": "[..]",
10781084
"metadata": null,
1085+
"publish": null,
10791086
"authors": [],
10801087
"categories": [],
10811088
"keywords": [],
@@ -1110,6 +1117,7 @@ fn unknown_registry() {
11101117
"features": {},
11111118
"manifest_path": "[..]/foo/Cargo.toml",
11121119
"metadata": null,
1120+
"publish": null,
11131121
"authors": [],
11141122
"categories": [],
11151123
"keywords": [],
@@ -1144,6 +1152,7 @@ fn unknown_registry() {
11441152
"features": {},
11451153
"manifest_path": "[..]",
11461154
"metadata": null,
1155+
"publish": null,
11471156
"authors": [],
11481157
"categories": [],
11491158
"keywords": [],

tests/testsuite/metadata.rs

Lines changed: 99 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fn cargo_metadata_simple() {
4747
],
4848
"features": {},
4949
"manifest_path": "[..]Cargo.toml",
50-
"metadata": null
50+
"metadata": null,
51+
"publish": null
5152
}
5253
],
5354
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
@@ -138,7 +139,8 @@ crate-type = ["lib", "staticlib"]
138139
],
139140
"features": {},
140141
"manifest_path": "[..]Cargo.toml",
141-
"metadata": null
142+
"metadata": null,
143+
"publish": null
142144
}
143145
],
144146
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
@@ -223,7 +225,8 @@ optional_feat = []
223225
"optional_feat": []
224226
},
225227
"manifest_path": "[..]Cargo.toml",
226-
"metadata": null
228+
"metadata": null,
229+
"publish": null
227230
}
228231
],
229232
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
@@ -296,6 +299,7 @@ fn cargo_metadata_with_deps_and_version() {
296299
"links": null,
297300
"manifest_path": "[..]Cargo.toml",
298301
"metadata": null,
302+
"publish": null,
299303
"name": "baz",
300304
"readme": null,
301305
"repository": null,
@@ -355,6 +359,7 @@ fn cargo_metadata_with_deps_and_version() {
355359
"links": null,
356360
"manifest_path": "[..]Cargo.toml",
357361
"metadata": null,
362+
"publish": null,
358363
"name": "foo",
359364
"readme": null,
360365
"repository": null,
@@ -389,6 +394,7 @@ fn cargo_metadata_with_deps_and_version() {
389394
"links": null,
390395
"manifest_path": "[..]Cargo.toml",
391396
"metadata": null,
397+
"publish": null,
392398
"name": "foobar",
393399
"readme": null,
394400
"repository": null,
@@ -436,6 +442,7 @@ fn cargo_metadata_with_deps_and_version() {
436442
"links": null,
437443
"manifest_path": "[..]Cargo.toml",
438444
"metadata": null,
445+
"publish": null,
439446
"name": "bar",
440447
"readme": null,
441448
"repository": null,
@@ -575,7 +582,8 @@ name = "ex"
575582
],
576583
"features": {},
577584
"manifest_path": "[..]Cargo.toml",
578-
"metadata": null
585+
"metadata": null,
586+
"publish": null
579587
}
580588
],
581589
"workspace_members": [
@@ -660,7 +668,8 @@ crate-type = ["rlib", "dylib"]
660668
],
661669
"features": {},
662670
"manifest_path": "[..]Cargo.toml",
663-
"metadata": null
671+
"metadata": null,
672+
"publish": null
664673
}
665674
],
666675
"workspace_members": [
@@ -736,7 +745,8 @@ fn workspace_metadata() {
736745
],
737746
"features": {},
738747
"manifest_path": "[..]bar/Cargo.toml",
739-
"metadata": null
748+
"metadata": null,
749+
"publish": null
740750
},
741751
{
742752
"authors": [
@@ -768,7 +778,8 @@ fn workspace_metadata() {
768778
],
769779
"features": {},
770780
"manifest_path": "[..]baz/Cargo.toml",
771-
"metadata": null
781+
"metadata": null,
782+
"publish": null
772783
}
773784
],
774785
"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() {
848859
],
849860
"features": {},
850861
"manifest_path": "[..]bar/Cargo.toml",
851-
"metadata": null
862+
"metadata": null,
863+
"publish": null
852864
},
853865
{
854866
"authors": [
@@ -880,7 +892,8 @@ fn workspace_metadata_no_deps() {
880892
],
881893
"features": {},
882894
"manifest_path": "[..]baz/Cargo.toml",
883-
"metadata": null
895+
"metadata": null,
896+
"publish": null
884897
}
885898
],
886899
"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#"
938951
"features":{},
939952
"manifest_path":"[..]Cargo.toml",
940953
"metadata": null,
954+
"publish": null,
941955
"readme": null,
942956
"repository": null
943957
}],
@@ -1121,7 +1135,75 @@ fn package_metadata() {
11211135
"bar": {
11221136
"baz": "quux"
11231137
}
1124-
}
1138+
},
1139+
"publish": null
1140+
}
1141+
],
1142+
"workspace_members": ["foo[..]"],
1143+
"resolve": null,
1144+
"target_directory": "[..]foo/target",
1145+
"version": 1,
1146+
"workspace_root": "[..]/foo"
1147+
}"#,
1148+
)
1149+
.run();
1150+
}
1151+
1152+
#[cargo_test]
1153+
fn package_publish() {
1154+
let p = project()
1155+
.file(
1156+
"Cargo.toml",
1157+
r#"
1158+
[package]
1159+
name = "foo"
1160+
version = "0.1.0"
1161+
authors = ["[email protected]"]
1162+
categories = ["database"]
1163+
keywords = ["database"]
1164+
readme = "README.md"
1165+
repository = "https://github.com/rust-lang/cargo"
1166+
publish = ["my-registry"]
1167+
"#,
1168+
)
1169+
.file("src/lib.rs", "")
1170+
.build();
1171+
1172+
p.cargo("metadata --no-deps")
1173+
.with_json(
1174+
r#"
1175+
{
1176+
"packages": [
1177+
{
1178+
"authors": ["[email protected]"],
1179+
"categories": ["database"],
1180+
"name": "foo",
1181+
"readme": "README.md",
1182+
"repository": "https://github.com/rust-lang/cargo",
1183+
"version": "0.1.0",
1184+
"id": "foo[..]",
1185+
"keywords": ["database"],
1186+
"source": null,
1187+
"dependencies": [],
1188+
"edition": "2015",
1189+
"license": null,
1190+
"license_file": null,
1191+
"links": null,
1192+
"description": null,
1193+
"targets": [
1194+
{
1195+
"kind": [ "lib" ],
1196+
"crate_types": [ "lib" ],
1197+
"doctest": true,
1198+
"edition": "2015",
1199+
"name": "foo",
1200+
"src_path": "[..]foo/src/lib.rs"
1201+
}
1202+
],
1203+
"features": {},
1204+
"manifest_path": "[..]foo/Cargo.toml",
1205+
"metadata": null,
1206+
"publish": ["my-registry"]
11251207
}
11261208
],
11271209
"workspace_members": ["foo[..]"],
@@ -1175,6 +1257,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
11751257
"links": null,
11761258
"manifest_path": "[..]Cargo.toml",
11771259
"metadata": null,
1260+
"publish": null,
11781261
"name": "bar",
11791262
"readme": null,
11801263
"repository": null,
@@ -1255,6 +1338,7 @@ fn package_edition_2018() {
12551338
"links": null,
12561339
"manifest_path": "[..]Cargo.toml",
12571340
"metadata": null,
1341+
"publish": null,
12581342
"name": "foo",
12591343
"readme": null,
12601344
"repository": null,
@@ -1339,6 +1423,7 @@ fn target_edition_2018() {
13391423
"links": null,
13401424
"manifest_path": "[..]Cargo.toml",
13411425
"metadata": null,
1426+
"publish": null,
13421427
"name": "foo",
13431428
"readme": null,
13441429
"repository": null,
@@ -1461,6 +1546,7 @@ fn rename_dependency() {
14611546
"links": null,
14621547
"manifest_path": "[..]",
14631548
"metadata": null,
1549+
"publish": null,
14641550
"name": "foo",
14651551
"readme": null,
14661552
"repository": null,
@@ -1495,6 +1581,7 @@ fn rename_dependency() {
14951581
"links": null,
14961582
"manifest_path": "[..]",
14971583
"metadata": null,
1584+
"publish": null,
14981585
"name": "bar",
14991586
"readme": null,
15001587
"repository": null,
@@ -1529,6 +1616,7 @@ fn rename_dependency() {
15291616
"links": null,
15301617
"manifest_path": "[..]",
15311618
"metadata": null,
1619+
"publish": null,
15321620
"name": "bar",
15331621
"readme": null,
15341622
"repository": null,
@@ -1631,6 +1719,7 @@ fn metadata_links() {
16311719
"links": "a",
16321720
"manifest_path": "[..]/foo/Cargo.toml",
16331721
"metadata": null,
1722+
"publish": null,
16341723
"name": "foo",
16351724
"readme": null,
16361725
"repository": null,

tests/testsuite/read_manifest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static MANIFEST_OUTPUT: &str = r#"
2929
}],
3030
"features":{},
3131
"manifest_path":"[..]Cargo.toml",
32-
"metadata": null
32+
"metadata": null,
33+
"publish": null
3334
}"#;
3435

3536
#[cargo_test]

tests/testsuite/update.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ fn update_precise_first_run() {
447447
"links": null,
448448
"manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml",
449449
"metadata": null,
450+
"publish": null,
450451
"name": "serde",
451452
"readme": null,
452453
"repository": null,
@@ -494,6 +495,7 @@ fn update_precise_first_run() {
494495
"links": null,
495496
"manifest_path": "[..]/foo/Cargo.toml",
496497
"metadata": null,
498+
"publish": null,
497499
"name": "bar",
498500
"readme": null,
499501
"repository": null,

0 commit comments

Comments
 (0)