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

feat(cargo-metadata): add workspace_default_members #11978

Merged
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/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
Ok(ExportInfo {
packages,
workspace_members: ws.members().map(|pkg| pkg.package_id()).collect(),
workspace_default_members: ws.default_members().map(|pkg| pkg.package_id()).collect(),
resolve,
target_directory: ws.target_dir().into_path_unlocked(),
version: VERSION,
Expand All @@ -58,6 +59,7 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
pub struct ExportInfo {
packages: Vec<SerializedPackage>,
workspace_members: Vec<PackageId>,
workspace_default_members: Vec<PackageId>,
resolve: Option<MetadataResolve>,
target_directory: PathBuf,
version: u32,
Expand Down
6 changes: 6 additions & 0 deletions src/doc/man/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ The output has the following format:
"workspace_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
/* Array of default members of the workspace.
Each entry is the Package ID for the package.
*/
"workspace_default_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
// The resolved dependency graph for the entire workspace. The enabled
// features are based on the enabled features for the "current" package.
// Inactivated optional dependencies are not listed.
Expand Down
6 changes: 6 additions & 0 deletions src/doc/man/generated_txt/cargo-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ OUTPUT FORMAT
"workspace_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
/* Array of default members of the workspace.
Each entry is the Package ID for the package.
*/
"workspace_default_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
// The resolved dependency graph for the entire workspace. The enabled
// features are based on the enabled features for the "current" package.
// Inactivated optional dependencies are not listed.
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ The output has the following format:
"workspace_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
/* Array of default members of the workspace.
Each entry is the Package ID for the package.
*/
"workspace_default_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
// The resolved dependency graph for the entire workspace. The enabled
// features are based on the enabled features for the "current" package.
// Inactivated optional dependencies are not listed.
Expand Down
6 changes: 6 additions & 0 deletions src/etc/man/cargo-metadata.1
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ The output has the following format:
"workspace_members": [
"my\-package 0.1.0 (path+file:///path/to/my\-package)",
],
/* Array of default members of the workspace.
Each entry is the Package ID for the package.
*/
"workspace_default_members": [
"my\-package 0.1.0 (path+file:///path/to/my\-package)",
],
// The resolved dependency graph for the entire workspace. The enabled
// features are based on the enabled features for the "current" package.
// Inactivated optional dependencies are not listed.
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 @@ -902,6 +902,9 @@ fn alt_reg_metadata() {
"workspace_members": [
"foo 0.0.1 (path+file:[..]/foo)"
],
"workspace_default_members": [
"foo 0.0.1 (path+file:[..]/foo)"
],
"resolve": null,
"target_directory": "[..]/foo/target",
"version": 1,
Expand Down Expand Up @@ -1102,6 +1105,9 @@ fn alt_reg_metadata() {
"workspace_members": [
"foo 0.0.1 (path+file:[..]/foo)"
],
"workspace_default_members": [
"foo 0.0.1 (path+file:[..]/foo)"
],
"resolve": "{...}",
"target_directory": "[..]/foo/target",
"version": 1,
Expand Down Expand Up @@ -1265,6 +1271,9 @@ fn unknown_registry() {
"workspace_members": [
"foo 0.0.1 (path+file://[..]/foo)"
],
"workspace_default_members": [
"foo 0.0.1 (path+file://[..]/foo)"
],
"resolve": "{...}",
"target_directory": "[..]/foo/target",
"version": 1,
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ fn json_exposed() {
}
],
"workspace_members": "{...}",
"workspace_default_members": "{...}",
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,9 @@ fn metadata_master_consistency() {
"workspace_members": [
"foo 0.1.0 [..]"
],
"workspace_default_members": [
"foo 0.1.0 [..]"
],
"resolve": {
"nodes": [
{
Expand Down
58 changes: 58 additions & 0 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn cargo_metadata_simple() {
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -164,6 +165,7 @@ crate-type = ["lib", "staticlib"]
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -257,6 +259,7 @@ optional_feat = []
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
"workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -587,6 +590,9 @@ fn cargo_metadata_with_deps_and_version() {
"workspace_members": [
"foo 0.5.0 (path+file:[..]foo)"
],
"workspace_default_members": [
"foo 0.5.0 (path+file:[..]foo)"
],
"workspace_root": "[..]/foo",
"metadata": null
}"#,
Expand Down Expand Up @@ -668,6 +674,9 @@ name = "ex"
"workspace_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
"workspace_default_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
"resolve": {
"root": "foo 0.1.0 (path+file://[..]foo)",
"nodes": [
Expand Down Expand Up @@ -762,6 +771,9 @@ crate-type = ["rlib", "dylib"]
],
"workspace_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
"workspace_default_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
"resolve": {
"root": "foo 0.1.0 (path+file://[..]foo)",
Expand Down Expand Up @@ -892,6 +904,7 @@ fn workspace_metadata() {
}
],
"workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
"workspace_default_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -1123,6 +1136,11 @@ fn workspace_metadata_with_dependencies_no_deps() {
"artifact 0.5.0 (path+file:[..]/foo/artifact)",
"baz 0.5.0 (path+file:[..]baz)"
],
"workspace_default_members": [
"bar 0.5.0 (path+file:[..]bar)",
"artifact 0.5.0 (path+file:[..]/foo/artifact)",
"baz 0.5.0 (path+file:[..]baz)"
],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
Expand Down Expand Up @@ -1755,6 +1773,12 @@ fn workspace_metadata_with_dependencies_and_resolve() {
"bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
"non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)"
],
"workspace_default_members": [
"bar 0.5.0 (path+file://[..]/foo/bar)",
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
"bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
"non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)"
],
"workspace_root": "[..]/foo"
}
"#,
Expand Down Expand Up @@ -1953,6 +1977,7 @@ const MANIFEST_OUTPUT: &str = r#"
"documentation": null
}],
"workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
"workspace_default_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
Expand Down Expand Up @@ -2147,6 +2172,7 @@ fn package_metadata() {
}
],
"workspace_members": ["foo[..]"],
"workspace_default_members": ["foo[..]"],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
Expand Down Expand Up @@ -2222,6 +2248,7 @@ fn package_publish() {
}
],
"workspace_members": ["foo[..]"],
"workspace_default_members": ["foo[..]"],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
Expand Down Expand Up @@ -2317,6 +2344,9 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"workspace_members": [
"bar 0.5.0 (path+file:[..])"
],
"workspace_default_members": [
"bar 0.5.0 (path+file:[..])"
],
"workspace_root": "[..]",
"metadata": null
}
Expand Down Expand Up @@ -2405,6 +2435,9 @@ fn package_edition_2018() {
"workspace_members": [
"foo 0.1.0 (path+file:[..])"
],
"workspace_default_members": [
"foo 0.1.0 (path+file:[..])"
],
"workspace_root": "[..]",
"metadata": null
}
Expand Down Expand Up @@ -2553,6 +2586,9 @@ fn target_edition_2018() {
"workspace_members": [
"foo 0.1.0 (path+file:[..])"
],
"workspace_default_members": [
"foo 0.1.0 (path+file:[..])"
],
"workspace_root": "[..]",
"metadata": null
}
Expand Down Expand Up @@ -2789,6 +2825,9 @@ fn rename_dependency() {
"workspace_members": [
"foo 0.0.1[..]"
],
"workspace_default_members": [
"foo 0.0.1[..]"
],
"workspace_root": "[..]",
"metadata": null
}"#,
Expand Down Expand Up @@ -2889,6 +2928,9 @@ fn metadata_links() {
"workspace_members": [
"foo 0.5.0 [..]"
],
"workspace_default_members": [
"foo 0.5.0 [..]"
],
"workspace_root": "[..]/foo",
"metadata": null
}
Expand Down Expand Up @@ -2979,6 +3021,9 @@ fn deps_with_bin_only() {
"workspace_members": [
"foo 0.1.0 ([..])"
],
"workspace_default_members": [
"foo 0.1.0 ([..])"
],
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -3358,6 +3403,9 @@ fn filter_platform() {
"workspace_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
"workspace_default_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -3477,6 +3525,7 @@ fn filter_platform() {
$NORMAL_DEP
],
"workspace_members": "{...}",
"workspace_default_members": "{...}",
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -3558,6 +3607,7 @@ fn filter_platform() {
$NORMAL_DEP
],
"workspace_members": "{...}",
"workspace_default_members": "{...}",
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -3642,6 +3692,7 @@ fn filter_platform() {
$NORMAL_DEP
],
"workspace_members": "{...}",
"workspace_default_members": "{...}",
"resolve": {
"nodes": [
{
Expand Down Expand Up @@ -3756,6 +3807,7 @@ fn dep_kinds() {
{
"packages": "{...}",
"workspace_members": "{...}",
"workspace_default_members": "{...}",
"target_directory": "{...}",
"version": 1,
"workspace_root": "{...}",
Expand Down Expand Up @@ -3871,6 +3923,7 @@ fn dep_kinds_workspace() {
{
"packages": "{...}",
"workspace_members": "{...}",
"workspace_default_members": "{...}",
"target_directory": "[..]/foo/target",
"version": 1,
"workspace_root": "[..]/foo",
Expand Down Expand Up @@ -4184,6 +4237,11 @@ fn workspace_metadata_with_dependencies_no_deps_artifact() {
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
"baz 0.5.0 (path+file://[..]/foo/baz)"
],
"workspace_default_members": [
"bar 0.5.0 (path+file://[..]/foo/bar)",
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
"baz 0.5.0 (path+file://[..]/foo/baz)"
],
"workspace_root": "[..]/foo"
}
"#,
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ fn update_precise_first_run() {
"workspace_members": [
"bar 0.0.1 (path+file://[..]/foo)"
],
"workspace_default_members": [
"bar 0.0.1 (path+file://[..]/foo)"
],
"workspace_root": "[..]/foo",
"metadata": null
}"#,
Expand Down