fix #4746 and add test
authorgibix <gibix@riseup.net>
Fri, 1 Jun 2018 10:38:16 +0000 (12:38 +0200)
committergibix <gibix@riseup.net>
Fri, 1 Jun 2018 14:10:55 +0000 (16:10 +0200)
Signed-off-by: gibix <gibix@riseup.net>
src/cargo/core/workspace.rs
tests/testsuite/metadata.rs

index 5e15b2e205932e733b661c4892c1b6930e203c28..4209f8a5b525e02ad1824fdbe66e53571fe5893a 100644 (file)
@@ -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() {
index f0b5e104be0e9d40bfb5f1a830782cf8683a8788..78b08f9acfb0036ad62c98156a56bdb9d8553391 100644 (file)
@@ -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": "[..]"
+        }
+"#
+),
+    );
+}
+
+