Fix `cargo install` using a workspace target dir
authorAlex Crichton <alex@alexcrichton.com>
Thu, 5 Jul 2018 19:05:50 +0000 (12:05 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 5 Jul 2018 19:56:19 +0000 (12:56 -0700)
Closes #5662

src/cargo/ops/cargo_install.rs
tests/testsuite/install.rs

index 9516aac0917627029f880d21f4fa484a3fff4f7f..60c43321a678361548bc0504c06a4d3f862f95a4 100644 (file)
@@ -224,7 +224,14 @@ fn install_one(
         Some(Filesystem::new(config.cwd().join("target-install")))
     };
 
-    let ws = Workspace::ephemeral(pkg, config, overidden_target_dir, false)?;
+    let ws = match overidden_target_dir {
+        Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?,
+        None => {
+            let mut ws = Workspace::new(pkg.manifest_path(), config)?;
+            ws.set_require_optional_deps(false);
+            ws
+        }
+    };
     let pkg = ws.current()?;
 
     if from_cwd {
index 6c24e17f0c2a197dec7676a74ef64636710d4644..b26721d354131071f7b94415a0779c11f61e2740 100644 (file)
@@ -1581,3 +1581,47 @@ fn git_repo_replace() {
             .contains(&format!("{}", new_rev))
     );
 }
+
+#[test]
+fn workspace_uses_workspace_target_dir() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+                [package]
+                name = "foo"
+                version = "0.1.0"
+                authors = []
+
+                [workspace]
+
+                [dependencies]
+                bar = { path = 'bar' }
+            "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .file(
+            "bar/Cargo.toml",
+            r#"
+                [package]
+                name = "bar"
+                version = "0.1.0"
+                authors = []
+            "#,
+        )
+        .file("bar/src/main.rs", "fn main() {}")
+        .build();
+
+    assert_that(p.cargo("build").cwd(p.root().join("bar")).arg("--release"),
+                execs().with_status(0));
+    assert_that(
+        cargo_process("install").arg("--path").arg(p.root().join("bar")),
+        execs().with_status(0).with_stderr(
+            "[INSTALLING] [..]
+[FINISHED] release [optimized] target(s) in [..]
+[INSTALLING] [..]
+warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
+",
+        ),
+    );
+}