Skip to content

Commit

Permalink
Find workspace via workspace_root link in containing member
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jan 19, 2017
1 parent 4d7b49b commit 3435414
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ impl<'cfg> Workspace<'cfg> {
/// if some other transient error happens.
fn find_root(&mut self, manifest_path: &Path)
-> CargoResult<Option<PathBuf>> {
fn read_root_pointer(member_manifest: &Path, root_link: &str) -> CargoResult<PathBuf> {
let path = member_manifest.parent().unwrap()
.join(root_link)
.join("Cargo.toml");
debug!("find_root - pointer {}", path.display());
return Ok(paths::normalize_path(&path))
};

{
let current = self.packages.load(&manifest_path)?;
match *current.workspace_config() {
Expand All @@ -238,11 +246,7 @@ impl<'cfg> Workspace<'cfg> {
return Ok(Some(manifest_path.to_path_buf()))
}
WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
let path = manifest_path.parent().unwrap()
.join(path_to_root)
.join("Cargo.toml");
debug!("find_root - pointer {}", path.display());
return Ok(Some(paths::normalize_path(&path)))
return Ok(Some(read_root_pointer(manifest_path, path_to_root)?))
}
WorkspaceConfig::Member { root: None } => {}
}
Expand All @@ -258,6 +262,9 @@ impl<'cfg> Workspace<'cfg> {
debug!("find_root - found");
return Ok(Some(manifest))
}
WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
return Ok(Some(read_root_pointer(&manifest, path_to_root)?))
}
WorkspaceConfig::Member { .. } => {}
}
}
Expand Down
7 changes: 3 additions & 4 deletions tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,7 @@ fn test_path_dependency_under_member() {

assert_that(p.cargo("build").cwd(p.root().join("foo/bar")),
execs().with_status(0));
// Ideally, `foo/bar` should be a member of the workspace,
// because it is hierarchically under the workspace member.
assert_that(&p.root().join("foo/bar/Cargo.lock"), existing_file());
assert_that(&p.root().join("foo/bar/target"), existing_dir());

assert_that(&p.root().join("foo/bar/Cargo.lock"), is_not(existing_file()));
assert_that(&p.root().join("foo/bar/target"), is_not(existing_dir()));
}

0 comments on commit 3435414

Please sign in to comment.