Skip to content

Commit 6240788

Browse files
committed
Auto merge of #11978 - charles-r-earp:metadata_workspace_default_members, r=weihanglo
feat(cargo-metadata): add `workspace_default_members` ### What does this PR try to resolve? Fixes #8033. ### How should we test and review this PR? I fixed one test "cargo_metadata_simple". Other tests haven't been updated, and potentially additional tests could be added to test the new functionality specifically. ### Additional information More tests would have to be updated. This change adds "workspace_default_members" to the ExportInfo struct which is serialized to json. I would imagine this could break existing testing infrastructure, but existing crates / apps reading this output should presumably expect that additional fields / data could be added.
2 parents 9984c88 + 61df6bb commit 6240788

File tree

10 files changed

+100
-0
lines changed

10 files changed

+100
-0
lines changed

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
4343
Ok(ExportInfo {
4444
packages,
4545
workspace_members: ws.members().map(|pkg| pkg.package_id()).collect(),
46+
workspace_default_members: ws.default_members().map(|pkg| pkg.package_id()).collect(),
4647
resolve,
4748
target_directory: ws.target_dir().into_path_unlocked(),
4849
version: VERSION,
@@ -58,6 +59,7 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
5859
pub struct ExportInfo {
5960
packages: Vec<SerializedPackage>,
6061
workspace_members: Vec<PackageId>,
62+
workspace_default_members: Vec<PackageId>,
6163
resolve: Option<MetadataResolve>,
6264
target_directory: PathBuf,
6365
version: u32,

src/doc/man/cargo-metadata.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ The output has the following format:
212212
"workspace_members": [
213213
"my-package 0.1.0 (path+file:///path/to/my-package)",
214214
],
215+
/* Array of default members of the workspace.
216+
Each entry is the Package ID for the package.
217+
*/
218+
"workspace_default_members": [
219+
"my-package 0.1.0 (path+file:///path/to/my-package)",
220+
],
215221
// The resolved dependency graph for the entire workspace. The enabled
216222
// features are based on the enabled features for the "current" package.
217223
// Inactivated optional dependencies are not listed.

src/doc/man/generated_txt/cargo-metadata.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ OUTPUT FORMAT
207207
"workspace_members": [
208208
"my-package 0.1.0 (path+file:///path/to/my-package)",
209209
],
210+
/* Array of default members of the workspace.
211+
Each entry is the Package ID for the package.
212+
*/
213+
"workspace_default_members": [
214+
"my-package 0.1.0 (path+file:///path/to/my-package)",
215+
],
210216
// The resolved dependency graph for the entire workspace. The enabled
211217
// features are based on the enabled features for the "current" package.
212218
// Inactivated optional dependencies are not listed.

src/doc/src/commands/cargo-metadata.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ The output has the following format:
212212
"workspace_members": [
213213
"my-package 0.1.0 (path+file:///path/to/my-package)",
214214
],
215+
/* Array of default members of the workspace.
216+
Each entry is the Package ID for the package.
217+
*/
218+
"workspace_default_members": [
219+
"my-package 0.1.0 (path+file:///path/to/my-package)",
220+
],
215221
// The resolved dependency graph for the entire workspace. The enabled
216222
// features are based on the enabled features for the "current" package.
217223
// Inactivated optional dependencies are not listed.

src/etc/man/cargo-metadata.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ The output has the following format:
209209
"workspace_members": [
210210
"my\-package 0.1.0 (path+file:///path/to/my\-package)",
211211
],
212+
/* Array of default members of the workspace.
213+
Each entry is the Package ID for the package.
214+
*/
215+
"workspace_default_members": [
216+
"my\-package 0.1.0 (path+file:///path/to/my\-package)",
217+
],
212218
// The resolved dependency graph for the entire workspace. The enabled
213219
// features are based on the enabled features for the "current" package.
214220
// Inactivated optional dependencies are not listed.

tests/testsuite/alt_registry.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ fn alt_reg_metadata() {
902902
"workspace_members": [
903903
"foo 0.0.1 (path+file:[..]/foo)"
904904
],
905+
"workspace_default_members": [
906+
"foo 0.0.1 (path+file:[..]/foo)"
907+
],
905908
"resolve": null,
906909
"target_directory": "[..]/foo/target",
907910
"version": 1,
@@ -1102,6 +1105,9 @@ fn alt_reg_metadata() {
11021105
"workspace_members": [
11031106
"foo 0.0.1 (path+file:[..]/foo)"
11041107
],
1108+
"workspace_default_members": [
1109+
"foo 0.0.1 (path+file:[..]/foo)"
1110+
],
11051111
"resolve": "{...}",
11061112
"target_directory": "[..]/foo/target",
11071113
"version": 1,
@@ -1265,6 +1271,9 @@ fn unknown_registry() {
12651271
"workspace_members": [
12661272
"foo 0.0.1 (path+file://[..]/foo)"
12671273
],
1274+
"workspace_default_members": [
1275+
"foo 0.0.1 (path+file://[..]/foo)"
1276+
],
12681277
"resolve": "{...}",
12691278
"target_directory": "[..]/foo/target",
12701279
"version": 1,

tests/testsuite/features_namespaced.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ fn json_exposed() {
609609
}
610610
],
611611
"workspace_members": "{...}",
612+
"workspace_default_members": "{...}",
612613
"resolve": null,
613614
"target_directory": "[..]foo/target",
614615
"version": 1,

tests/testsuite/git.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,9 @@ fn metadata_master_consistency() {
33373337
"workspace_members": [
33383338
"foo 0.1.0 [..]"
33393339
],
3340+
"workspace_default_members": [
3341+
"foo 0.1.0 [..]"
3342+
],
33403343
"resolve": {
33413344
"nodes": [
33423345
{

tests/testsuite/metadata.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fn cargo_metadata_simple() {
6565
}
6666
],
6767
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
68+
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
6869
"resolve": {
6970
"nodes": [
7071
{
@@ -164,6 +165,7 @@ crate-type = ["lib", "staticlib"]
164165
}
165166
],
166167
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
168+
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
167169
"resolve": {
168170
"nodes": [
169171
{
@@ -257,6 +259,7 @@ optional_feat = []
257259
}
258260
],
259261
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
262+
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
260263
"resolve": {
261264
"nodes": [
262265
{
@@ -587,6 +590,9 @@ fn cargo_metadata_with_deps_and_version() {
587590
"workspace_members": [
588591
"foo 0.5.0 (path+file:[..]foo)"
589592
],
593+
"workspace_default_members": [
594+
"foo 0.5.0 (path+file:[..]foo)"
595+
],
590596
"workspace_root": "[..]/foo",
591597
"metadata": null
592598
}"#,
@@ -668,6 +674,9 @@ name = "ex"
668674
"workspace_members": [
669675
"foo 0.1.0 (path+file:[..]foo)"
670676
],
677+
"workspace_default_members": [
678+
"foo 0.1.0 (path+file:[..]foo)"
679+
],
671680
"resolve": {
672681
"root": "foo 0.1.0 (path+file://[..]foo)",
673682
"nodes": [
@@ -762,6 +771,9 @@ crate-type = ["rlib", "dylib"]
762771
],
763772
"workspace_members": [
764773
"foo 0.1.0 (path+file:[..]foo)"
774+
],
775+
"workspace_default_members": [
776+
"foo 0.1.0 (path+file:[..]foo)"
765777
],
766778
"resolve": {
767779
"root": "foo 0.1.0 (path+file://[..]foo)",
@@ -892,6 +904,7 @@ fn workspace_metadata() {
892904
}
893905
],
894906
"workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
907+
"workspace_default_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
895908
"resolve": {
896909
"nodes": [
897910
{
@@ -1123,6 +1136,11 @@ fn workspace_metadata_with_dependencies_no_deps() {
11231136
"artifact 0.5.0 (path+file:[..]/foo/artifact)",
11241137
"baz 0.5.0 (path+file:[..]baz)"
11251138
],
1139+
"workspace_default_members": [
1140+
"bar 0.5.0 (path+file:[..]bar)",
1141+
"artifact 0.5.0 (path+file:[..]/foo/artifact)",
1142+
"baz 0.5.0 (path+file:[..]baz)"
1143+
],
11261144
"resolve": null,
11271145
"target_directory": "[..]foo/target",
11281146
"version": 1,
@@ -1755,6 +1773,12 @@ fn workspace_metadata_with_dependencies_and_resolve() {
17551773
"bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
17561774
"non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)"
17571775
],
1776+
"workspace_default_members": [
1777+
"bar 0.5.0 (path+file://[..]/foo/bar)",
1778+
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
1779+
"bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
1780+
"non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)"
1781+
],
17581782
"workspace_root": "[..]/foo"
17591783
}
17601784
"#,
@@ -1953,6 +1977,7 @@ const MANIFEST_OUTPUT: &str = r#"
19531977
"documentation": null
19541978
}],
19551979
"workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
1980+
"workspace_default_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
19561981
"resolve": null,
19571982
"target_directory": "[..]foo/target",
19581983
"version": 1,
@@ -2147,6 +2172,7 @@ fn package_metadata() {
21472172
}
21482173
],
21492174
"workspace_members": ["foo[..]"],
2175+
"workspace_default_members": ["foo[..]"],
21502176
"resolve": null,
21512177
"target_directory": "[..]foo/target",
21522178
"version": 1,
@@ -2222,6 +2248,7 @@ fn package_publish() {
22222248
}
22232249
],
22242250
"workspace_members": ["foo[..]"],
2251+
"workspace_default_members": ["foo[..]"],
22252252
"resolve": null,
22262253
"target_directory": "[..]foo/target",
22272254
"version": 1,
@@ -2317,6 +2344,9 @@ fn cargo_metadata_path_to_cargo_toml_project() {
23172344
"workspace_members": [
23182345
"bar 0.5.0 (path+file:[..])"
23192346
],
2347+
"workspace_default_members": [
2348+
"bar 0.5.0 (path+file:[..])"
2349+
],
23202350
"workspace_root": "[..]",
23212351
"metadata": null
23222352
}
@@ -2405,6 +2435,9 @@ fn package_edition_2018() {
24052435
"workspace_members": [
24062436
"foo 0.1.0 (path+file:[..])"
24072437
],
2438+
"workspace_default_members": [
2439+
"foo 0.1.0 (path+file:[..])"
2440+
],
24082441
"workspace_root": "[..]",
24092442
"metadata": null
24102443
}
@@ -2553,6 +2586,9 @@ fn target_edition_2018() {
25532586
"workspace_members": [
25542587
"foo 0.1.0 (path+file:[..])"
25552588
],
2589+
"workspace_default_members": [
2590+
"foo 0.1.0 (path+file:[..])"
2591+
],
25562592
"workspace_root": "[..]",
25572593
"metadata": null
25582594
}
@@ -2789,6 +2825,9 @@ fn rename_dependency() {
27892825
"workspace_members": [
27902826
"foo 0.0.1[..]"
27912827
],
2828+
"workspace_default_members": [
2829+
"foo 0.0.1[..]"
2830+
],
27922831
"workspace_root": "[..]",
27932832
"metadata": null
27942833
}"#,
@@ -2889,6 +2928,9 @@ fn metadata_links() {
28892928
"workspace_members": [
28902929
"foo 0.5.0 [..]"
28912930
],
2931+
"workspace_default_members": [
2932+
"foo 0.5.0 [..]"
2933+
],
28922934
"workspace_root": "[..]/foo",
28932935
"metadata": null
28942936
}
@@ -2979,6 +3021,9 @@ fn deps_with_bin_only() {
29793021
"workspace_members": [
29803022
"foo 0.1.0 ([..])"
29813023
],
3024+
"workspace_default_members": [
3025+
"foo 0.1.0 ([..])"
3026+
],
29823027
"resolve": {
29833028
"nodes": [
29843029
{
@@ -3358,6 +3403,9 @@ fn filter_platform() {
33583403
"workspace_members": [
33593404
"foo 0.1.0 (path+file:[..]foo)"
33603405
],
3406+
"workspace_default_members": [
3407+
"foo 0.1.0 (path+file:[..]foo)"
3408+
],
33613409
"resolve": {
33623410
"nodes": [
33633411
{
@@ -3477,6 +3525,7 @@ fn filter_platform() {
34773525
$NORMAL_DEP
34783526
],
34793527
"workspace_members": "{...}",
3528+
"workspace_default_members": "{...}",
34803529
"resolve": {
34813530
"nodes": [
34823531
{
@@ -3558,6 +3607,7 @@ fn filter_platform() {
35583607
$NORMAL_DEP
35593608
],
35603609
"workspace_members": "{...}",
3610+
"workspace_default_members": "{...}",
35613611
"resolve": {
35623612
"nodes": [
35633613
{
@@ -3642,6 +3692,7 @@ fn filter_platform() {
36423692
$NORMAL_DEP
36433693
],
36443694
"workspace_members": "{...}",
3695+
"workspace_default_members": "{...}",
36453696
"resolve": {
36463697
"nodes": [
36473698
{
@@ -3756,6 +3807,7 @@ fn dep_kinds() {
37563807
{
37573808
"packages": "{...}",
37583809
"workspace_members": "{...}",
3810+
"workspace_default_members": "{...}",
37593811
"target_directory": "{...}",
37603812
"version": 1,
37613813
"workspace_root": "{...}",
@@ -3871,6 +3923,7 @@ fn dep_kinds_workspace() {
38713923
{
38723924
"packages": "{...}",
38733925
"workspace_members": "{...}",
3926+
"workspace_default_members": "{...}",
38743927
"target_directory": "[..]/foo/target",
38753928
"version": 1,
38763929
"workspace_root": "[..]/foo",
@@ -4184,6 +4237,11 @@ fn workspace_metadata_with_dependencies_no_deps_artifact() {
41844237
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
41854238
"baz 0.5.0 (path+file://[..]/foo/baz)"
41864239
],
4240+
"workspace_default_members": [
4241+
"bar 0.5.0 (path+file://[..]/foo/bar)",
4242+
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
4243+
"baz 0.5.0 (path+file://[..]/foo/baz)"
4244+
],
41874245
"workspace_root": "[..]/foo"
41884246
}
41894247
"#,

tests/testsuite/update.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ fn update_precise_first_run() {
633633
"workspace_members": [
634634
"bar 0.0.1 (path+file://[..]/foo)"
635635
],
636+
"workspace_default_members": [
637+
"bar 0.0.1 (path+file://[..]/foo)"
638+
],
636639
"workspace_root": "[..]/foo",
637640
"metadata": null
638641
}"#,

0 commit comments

Comments
 (0)