Skip to content

Commit 742a111

Browse files
committed
Abstract away ws_roots
1 parent bfb8479 commit 742a111

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/cargo/core/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@ fn find_workspace_root_with_loader(
20372037
) -> CargoResult<Option<PathBuf>> {
20382038
// Check if there are any workspace roots that have already been found that would work
20392039
{
2040-
let roots = gctx.ws_roots.borrow();
2040+
let roots = gctx.ws_roots();
20412041
// Iterate through the manifests parent directories until we find a workspace
20422042
// root. Note we skip the first item since that is just the path itself
20432043
for current in manifest_path.ancestors().skip(1) {

src/cargo/util/context/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,10 @@ impl GlobalContext {
21332133
Ok(WarningHandling::default())
21342134
}
21352135
}
2136+
2137+
pub fn ws_roots(&self) -> RefMut<'_, HashMap<PathBuf, WorkspaceRootConfig>> {
2138+
self.ws_roots.borrow_mut()
2139+
}
21362140
}
21372141

21382142
/// Internal error for serde errors.

src/cargo/util/toml/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ pub fn read_manifest(
8181
to_workspace_config(&original_toml, path, is_embedded, gctx, &mut warnings)?;
8282
if let WorkspaceConfig::Root(ws_root_config) = &workspace_config {
8383
let package_root = path.parent().unwrap();
84-
gctx.ws_roots
85-
.borrow_mut()
84+
gctx.ws_roots()
8685
.insert(package_root.to_owned(), ws_root_config.clone());
8786
}
8887
let normalized_toml = normalize_toml(
@@ -996,17 +995,15 @@ fn inheritable_from_path(
996995

997996
// Let the borrow exit scope so that it can be picked up if there is a need to
998997
// read a manifest
999-
if let Some(ws_root) = gctx.ws_roots.borrow().get(workspace_path_root) {
998+
if let Some(ws_root) = gctx.ws_roots().get(workspace_path_root) {
1000999
return Ok(ws_root.inheritable().clone());
10011000
};
10021001

10031002
let source_id = SourceId::for_manifest_path(&workspace_path)?;
10041003
let man = read_manifest(&workspace_path, source_id, gctx)?;
10051004
match man.workspace_config() {
10061005
WorkspaceConfig::Root(root) => {
1007-
gctx.ws_roots
1008-
.borrow_mut()
1009-
.insert(workspace_path, root.clone());
1006+
gctx.ws_roots().insert(workspace_path, root.clone());
10101007
Ok(root.inheritable().clone())
10111008
}
10121009
_ => bail!(

0 commit comments

Comments
 (0)