From: gibix Date: Fri, 1 Jun 2018 10:38:16 +0000 (+0200) Subject: fix #4746 and add test X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2^2~10^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4f0e13617a293257097a3f9fc44343ea0bff5f7e;p=cargo.git fix #4746 and add test Signed-off-by: gibix --- diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 5e15b2e20..4209f8a5b 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -28,7 +28,7 @@ pub struct Workspace<'cfg> { config: &'cfg Config, // This path is a path to where the current cargo subcommand was invoked - // from. That is, this is the `--manifest-path` argument to Cargo, and + // from. That is the `--manifest-path` argument to Cargo, and // points to the "main crate" that we're going to worry about. current_manifest: PathBuf, @@ -363,6 +363,10 @@ impl<'cfg> Workspace<'cfg> { } for path in paths::ancestors(manifest_path).skip(2) { + if path.ends_with("target/package") { + break; + } + let ances_manifest_path = path.join("Cargo.toml"); debug!("find_root - trying {}", ances_manifest_path.display()); if ances_manifest_path.exists() { diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index f0b5e104b..78b08f9ac 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1027,3 +1027,90 @@ fn package_metadata() { ), ); } + +#[test] +fn cargo_metadata_path_to_cargo_toml_project() { + let p = project("foo") + .file( + "Cargo.toml", + r#" + [workspace] + members = ["bar"] + "#, + ) + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) + .file("bar/src/lib.rs", "") + .build(); + + assert_that( + p.cargo("package") + .arg("--manifest-path") + .arg(p.root().join("bar/Cargo.toml")) + .cwd(p.root().parent().unwrap()), + execs().with_status(0) + ); + + assert_that( + p.cargo("metadata") + .arg("--manifest-path") + .arg(p.root().join("target/package/bar-0.5.0/Cargo.toml")), + execs().with_status(0).with_json( + r#" + { + "packages": [ + { + "authors": [ + "wycats@example.com" + ], + "categories": [], + "dependencies": [], + "description": null, + "features": {}, + "id": "bar 0.5.0 ([..])", + "keywords": [], + "license": null, + "license_file": null, + "manifest_path": "[..]Cargo.toml", + "metadata": null, + "name": "bar", + "readme": null, + "repository": null, + "source": null, + "targets": [ + { + "crate_types": [ + "lib" + ], + "kind": [ + "lib" + ], + "name": "bar", + "src_path": "[..]src[/]lib.rs" + } + ], + "version": "0.5.0" + } + ], + "resolve": { + "nodes": [ + { + "dependencies": [], + "features": [], + "id": "bar 0.5.0 ([..])" + } + ], + "root": "bar 0.5.0 (path+file:[..])" + }, + "target_directory": "[..]", + "version": 1, + "workspace_members": [ + "bar 0.5.0 (path+file:[..])" + ], + "workspace_root": "[..]" + } +"# +), + ); +} + +