Skip to content

Commit cc37b90

Browse files
committed
Add workspace root to metadata command.
Fixes #4933
1 parent a88fbac commit cc37b90

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn metadata_no_deps(ws: &Workspace,
3939
resolve: None,
4040
target_directory: ws.target_dir().display().to_string(),
4141
version: VERSION,
42+
workspace_root: ws.root().display().to_string(),
4243
})
4344
}
4445

@@ -66,6 +67,7 @@ fn metadata_full(ws: &Workspace,
6667
}),
6768
target_directory: ws.target_dir().display().to_string(),
6869
version: VERSION,
70+
workspace_root: ws.root().display().to_string(),
6971
})
7072
}
7173

@@ -76,6 +78,7 @@ pub struct ExportInfo {
7678
resolve: Option<MetadataResolve>,
7779
target_directory: String,
7880
version: u32,
81+
workspace_root: String,
7982
}
8083

8184
/// Newtype wrapper to provide a custom `Serialize` implementation.

tests/metadata.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ fn cargo_metadata_simple() {
5151
"root": "foo 0.5.0 (path+file:[..]foo)"
5252
},
5353
"target_directory": "[..]foo[/]target",
54-
"version": 1
54+
"version": 1,
55+
"workspace_root": "[..][/]foo"
5556
}"#));
5657
}
5758

@@ -125,7 +126,8 @@ crate-type = ["lib", "staticlib"]
125126
"root": "foo 0.5.0 (path+file:[..]foo)"
126127
},
127128
"target_directory": "[..]foo[/]target",
128-
"version": 1
129+
"version": 1,
130+
"workspace_root": "[..][/]foo"
129131
}"#));
130132
}
131133

@@ -275,7 +277,8 @@ fn cargo_metadata_with_deps_and_version() {
275277
"root": "foo 0.5.0 (path+file:[..]foo)"
276278
},
277279
"target_directory": "[..]foo[/]target",
278-
"version": 1
280+
"version": 1,
281+
"workspace_root": "[..][/]foo"
279282
}"#));
280283
}
281284

@@ -337,7 +340,8 @@ name = "ex"
337340
]
338341
},
339342
"target_directory": "[..]foo[/]target",
340-
"version": 1
343+
"version": 1,
344+
"workspace_root": "[..][/]foo"
341345
}"#));
342346
}
343347

@@ -400,7 +404,8 @@ crate-type = ["rlib", "dylib"]
400404
]
401405
},
402406
"target_directory": "[..]foo[/]target",
403-
"version": 1
407+
"version": 1,
408+
"workspace_root": "[..][/]foo"
404409
}"#));
405410
}
406411

@@ -476,7 +481,8 @@ fn workspace_metadata() {
476481
"root": null
477482
},
478483
"target_directory": "[..]foo[/]target",
479-
"version": 1
484+
"version": 1,
485+
"workspace_root": "[..][/]foo"
480486
}"#))
481487
}
482488

@@ -540,7 +546,8 @@ fn workspace_metadata_no_deps() {
540546
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
541547
"resolve": null,
542548
"target_directory": "[..]foo[/]target",
543-
"version": 1
549+
"version": 1,
550+
"workspace_root": "[..][/]foo"
544551
}"#))
545552
}
546553

@@ -582,7 +589,8 @@ const MANIFEST_OUTPUT: &'static str=
582589
"workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
583590
"resolve": null,
584591
"target_directory": "[..]foo[/]target",
585-
"version": 1
592+
"version": 1,
593+
"workspace_root": "[..][/]foo"
586594
}"#;
587595

588596
#[test]

0 commit comments

Comments
 (0)