From 3435414edbf3bdcf5b2ec2655ab3cd3dbccbf1b9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 17 Jan 2017 01:30:59 +0300 Subject: [PATCH] Find workspace via `workspace_root` link in containing member --- src/cargo/core/workspace.rs | 17 ++++++++++++----- tests/workspaces.rs | 7 +++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index fdd14ee23e3..8a4cb0165d0 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -230,6 +230,14 @@ impl<'cfg> Workspace<'cfg> { /// if some other transient error happens. fn find_root(&mut self, manifest_path: &Path) -> CargoResult> { + fn read_root_pointer(member_manifest: &Path, root_link: &str) -> CargoResult { + 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() { @@ -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 } => {} } @@ -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 { .. } => {} } } diff --git a/tests/workspaces.rs b/tests/workspaces.rs index 1b2797f979d..dc3860f273a 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -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())); }