Skip to content

Commit 4f28bc1

Browse files
committed
Defer bailing out workspace root probing
This commit alters the logic to bail out on probing for `CARGO_HOME` to do it a little later rather than early on in the loop iteration, notably allowing members to reside in `CARGO_HOME` itself. Closes #4815
1 parent bda218f commit 4f28bc1

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/cargo/core/workspace.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,6 @@ impl<'cfg> Workspace<'cfg> {
333333
}
334334

335335
for path in paths::ancestors(manifest_path).skip(2) {
336-
if self.config.home() == path {
337-
return Ok(None);
338-
}
339336
let ances_manifest_path = path.join("Cargo.toml");
340337
debug!("find_root - trying {}", ances_manifest_path.display());
341338
if ances_manifest_path.exists() {
@@ -354,6 +351,15 @@ impl<'cfg> Workspace<'cfg> {
354351
WorkspaceConfig::Member { .. } => {}
355352
}
356353
}
354+
355+
// Don't walk across `CARGO_HOME` when we're looking for the
356+
// workspace root. Sometimes a project will be organized with
357+
// `CARGO_HOME` pointing inside of the workspace root or in the
358+
// current project, but we don't want to mistakenly try to put
359+
// crates.io crates into the workspace by accident.
360+
if self.config.home() == path {
361+
break
362+
}
357363
}
358364

359365
Ok(None)

tests/workspaces.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,3 +1782,28 @@ fn include_and_exclude() {
17821782
assert_that(&p.root().join("foo/bar/target"), existing_dir());
17831783
}
17841784
*/
1785+
1786+
#[test]
1787+
fn cargo_home_at_root_works() {
1788+
let p = project("lib")
1789+
.file("Cargo.toml", r#"
1790+
[package]
1791+
name = "lib"
1792+
version = "0.1.0"
1793+
1794+
[workspace]
1795+
members = ["a"]
1796+
"#)
1797+
.file("src/lib.rs", "")
1798+
.file("a/Cargo.toml", r#"
1799+
[package]
1800+
name = "a"
1801+
version = "0.1.0"
1802+
"#)
1803+
.file("a/src/lib.rs", "");
1804+
let p = p.build();
1805+
1806+
assert_that(p.cargo("build"), execs().with_status(0));
1807+
assert_that(p.cargo("build").arg("--frozen").env("CARGO_HOME", p.root()),
1808+
execs().with_status(0));
1809+
}

0 commit comments

Comments
 (0)