Skip to content

Commit cddf9ad

Browse files
committed
Auto merge of #5599 - gibix:fix/4746, r=alexcrichton
fix #4746 and add test
2 parents 5fc6ead + 4f0e136 commit cddf9ad

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

src/cargo/core/workspace.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Workspace<'cfg> {
2828
config: &'cfg Config,
2929

3030
// This path is a path to where the current cargo subcommand was invoked
31-
// from. That is, this is the `--manifest-path` argument to Cargo, and
31+
// from. That is the `--manifest-path` argument to Cargo, and
3232
// points to the "main crate" that we're going to worry about.
3333
current_manifest: PathBuf,
3434

@@ -363,6 +363,10 @@ impl<'cfg> Workspace<'cfg> {
363363
}
364364

365365
for path in paths::ancestors(manifest_path).skip(2) {
366+
if path.ends_with("target/package") {
367+
break;
368+
}
369+
366370
let ances_manifest_path = path.join("Cargo.toml");
367371
debug!("find_root - trying {}", ances_manifest_path.display());
368372
if ances_manifest_path.exists() {

tests/testsuite/metadata.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,3 +1027,90 @@ fn package_metadata() {
10271027
),
10281028
);
10291029
}
1030+
1031+
#[test]
1032+
fn cargo_metadata_path_to_cargo_toml_project() {
1033+
let p = project("foo")
1034+
.file(
1035+
"Cargo.toml",
1036+
r#"
1037+
[workspace]
1038+
members = ["bar"]
1039+
"#,
1040+
)
1041+
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
1042+
.file("bar/src/lib.rs", "")
1043+
.build();
1044+
1045+
assert_that(
1046+
p.cargo("package")
1047+
.arg("--manifest-path")
1048+
.arg(p.root().join("bar/Cargo.toml"))
1049+
.cwd(p.root().parent().unwrap()),
1050+
execs().with_status(0)
1051+
);
1052+
1053+
assert_that(
1054+
p.cargo("metadata")
1055+
.arg("--manifest-path")
1056+
.arg(p.root().join("target/package/bar-0.5.0/Cargo.toml")),
1057+
execs().with_status(0).with_json(
1058+
r#"
1059+
{
1060+
"packages": [
1061+
{
1062+
"authors": [
1063+
"wycats@example.com"
1064+
],
1065+
"categories": [],
1066+
"dependencies": [],
1067+
"description": null,
1068+
"features": {},
1069+
"id": "bar 0.5.0 ([..])",
1070+
"keywords": [],
1071+
"license": null,
1072+
"license_file": null,
1073+
"manifest_path": "[..]Cargo.toml",
1074+
"metadata": null,
1075+
"name": "bar",
1076+
"readme": null,
1077+
"repository": null,
1078+
"source": null,
1079+
"targets": [
1080+
{
1081+
"crate_types": [
1082+
"lib"
1083+
],
1084+
"kind": [
1085+
"lib"
1086+
],
1087+
"name": "bar",
1088+
"src_path": "[..]src[/]lib.rs"
1089+
}
1090+
],
1091+
"version": "0.5.0"
1092+
}
1093+
],
1094+
"resolve": {
1095+
"nodes": [
1096+
{
1097+
"dependencies": [],
1098+
"features": [],
1099+
"id": "bar 0.5.0 ([..])"
1100+
}
1101+
],
1102+
"root": "bar 0.5.0 (path+file:[..])"
1103+
},
1104+
"target_directory": "[..]",
1105+
"version": 1,
1106+
"workspace_members": [
1107+
"bar 0.5.0 (path+file:[..])"
1108+
],
1109+
"workspace_root": "[..]"
1110+
}
1111+
"#
1112+
),
1113+
);
1114+
}
1115+
1116+

0 commit comments

Comments
 (0)