Skip to content

Commit e0ed18d

Browse files
committed
Auto merge of #5686 - alexcrichton:beta-next, r=alexcrichton
[beta] Fix `cargo install` using a workspace target dir Backport of #5685
2 parents f6719ff + 1484c3f commit e0ed18d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,14 @@ fn install_one(
224224
Some(Filesystem::new(config.cwd().join("target-install")))
225225
};
226226

227-
let ws = Workspace::ephemeral(pkg, config, overidden_target_dir, false)?;
227+
let ws = match overidden_target_dir {
228+
Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?,
229+
None => {
230+
let mut ws = Workspace::new(pkg.manifest_path(), config)?;
231+
ws.set_require_optional_deps(false);
232+
ws
233+
}
234+
};
228235
let pkg = ws.current()?;
229236

230237
if from_cwd {

tests/testsuite/install.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,3 +1581,47 @@ fn git_repo_replace() {
15811581
.contains(&format!("{}", new_rev))
15821582
);
15831583
}
1584+
1585+
#[test]
1586+
fn workspace_uses_workspace_target_dir() {
1587+
let p = project("foo")
1588+
.file(
1589+
"Cargo.toml",
1590+
r#"
1591+
[package]
1592+
name = "foo"
1593+
version = "0.1.0"
1594+
authors = []
1595+
1596+
[workspace]
1597+
1598+
[dependencies]
1599+
bar = { path = 'bar' }
1600+
"#,
1601+
)
1602+
.file("src/main.rs", "fn main() {}")
1603+
.file(
1604+
"bar/Cargo.toml",
1605+
r#"
1606+
[package]
1607+
name = "bar"
1608+
version = "0.1.0"
1609+
authors = []
1610+
"#,
1611+
)
1612+
.file("bar/src/main.rs", "fn main() {}")
1613+
.build();
1614+
1615+
assert_that(p.cargo("build").cwd(p.root().join("bar")).arg("--release"),
1616+
execs().with_status(0));
1617+
assert_that(
1618+
cargo_process("install").arg("--path").arg(p.root().join("bar")),
1619+
execs().with_status(0).with_stderr(
1620+
"[INSTALLING] [..]
1621+
[FINISHED] release [optimized] target(s) in [..]
1622+
[INSTALLING] [..]
1623+
warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
1624+
",
1625+
),
1626+
);
1627+
}

0 commit comments

Comments
 (0)