Skip to content

Commit 0ee14de

Browse files
committed
Auto merge of rust-lang#3562 - matklad:member-workspace, r=alexcrichton
Find workspace via `workspace_root` link in containing member This PR proposes to change the logic for determining workspace members. Here are the algorithms we used previously for this: # [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1525-cargo-workspace.md) flavor If `[members]` key present, it compliantly defines the set of members. Otherwise, members are all (transitive) path dependencies. The problem with this approach is that it violates convention over configuration principle: almost always you want a path dependency to be a member, even if there are some explicit members. Listing **all** path deps is just to much work. # Original implementation So, the actual algorithm **unconditionally** included path dependencies as memebers. This is also problematic, because certain workspace configurations become impossible. In particular, you can't have a path dependency which is not a member of the workspace. This issue was reported in rust-lang#3192. # Current implementation Current implementation (was merged couple of days ago) includes path dependency into the workspace only if is inside the workspace directory. This solves the problem in rust-lang#3192 perfectly. However, some configuration are still impossible: you can't have a non-member path dependency inside a workspace directory. But the thinking is that if you don't want this path-dep to be a member, just don't put it inside the workspace directory. There is another problem with current imlementation. Suppose you have an explicit member which lives alongside the workspace. Suppose this member has a path-dep which lives inside the member's folder. Under current implementation, this path-dep won't be a member of the workspace. It seems logical that it should be though (but we haven't received any actual bug reports yet)! # Implementation in this PR So, with this PR, the logic is as follows: members are explicit members + all path dependencies which reside under any of the explicit members.
2 parents f7fb965 + 3435414 commit 0ee14de

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/cargo/core/workspace.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ impl<'cfg> Workspace<'cfg> {
230230
/// if some other transient error happens.
231231
fn find_root(&mut self, manifest_path: &Path)
232232
-> CargoResult<Option<PathBuf>> {
233+
fn read_root_pointer(member_manifest: &Path, root_link: &str) -> CargoResult<PathBuf> {
234+
let path = member_manifest.parent().unwrap()
235+
.join(root_link)
236+
.join("Cargo.toml");
237+
debug!("find_root - pointer {}", path.display());
238+
return Ok(paths::normalize_path(&path))
239+
};
240+
233241
{
234242
let current = self.packages.load(&manifest_path)?;
235243
match *current.workspace_config() {
@@ -238,11 +246,7 @@ impl<'cfg> Workspace<'cfg> {
238246
return Ok(Some(manifest_path.to_path_buf()))
239247
}
240248
WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
241-
let path = manifest_path.parent().unwrap()
242-
.join(path_to_root)
243-
.join("Cargo.toml");
244-
debug!("find_root - pointer {}", path.display());
245-
return Ok(Some(paths::normalize_path(&path)))
249+
return Ok(Some(read_root_pointer(manifest_path, path_to_root)?))
246250
}
247251
WorkspaceConfig::Member { root: None } => {}
248252
}
@@ -258,6 +262,9 @@ impl<'cfg> Workspace<'cfg> {
258262
debug!("find_root - found");
259263
return Ok(Some(manifest))
260264
}
265+
WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
266+
return Ok(Some(read_root_pointer(&manifest, path_to_root)?))
267+
}
261268
WorkspaceConfig::Member { .. } => {}
262269
}
263270
}

tests/workspaces.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,7 @@ fn test_path_dependency_under_member() {
12271227

12281228
assert_that(p.cargo("build").cwd(p.root().join("foo/bar")),
12291229
execs().with_status(0));
1230-
// Ideally, `foo/bar` should be a member of the workspace,
1231-
// because it is hierarchically under the workspace member.
1232-
assert_that(&p.root().join("foo/bar/Cargo.lock"), existing_file());
1233-
assert_that(&p.root().join("foo/bar/target"), existing_dir());
1230+
1231+
assert_that(&p.root().join("foo/bar/Cargo.lock"), is_not(existing_file()));
1232+
assert_that(&p.root().join("foo/bar/target"), is_not(existing_dir()));
12341233
}

0 commit comments

Comments
 (0)