Abstract away ws_roots

This commit is contained in:
Ed Page 2025-09-22 10:13:23 -05:00
parent bfb8479d83
commit 742a111df3
3 changed files with 8 additions and 7 deletions

View File

@ -2037,7 +2037,7 @@ fn find_workspace_root_with_loader(
) -> CargoResult<Option<PathBuf>> {
// Check if there are any workspace roots that have already been found that would work
{
let roots = gctx.ws_roots.borrow();
let roots = gctx.ws_roots();
// Iterate through the manifests parent directories until we find a workspace
// root. Note we skip the first item since that is just the path itself
for current in manifest_path.ancestors().skip(1) {

View File

@ -2133,6 +2133,10 @@ impl GlobalContext {
Ok(WarningHandling::default())
}
}
pub fn ws_roots(&self) -> RefMut<'_, HashMap<PathBuf, WorkspaceRootConfig>> {
self.ws_roots.borrow_mut()
}
}
/// Internal error for serde errors.

View File

@ -81,8 +81,7 @@ pub fn read_manifest(
to_workspace_config(&original_toml, path, is_embedded, gctx, &mut warnings)?;
if let WorkspaceConfig::Root(ws_root_config) = &workspace_config {
let package_root = path.parent().unwrap();
gctx.ws_roots
.borrow_mut()
gctx.ws_roots()
.insert(package_root.to_owned(), ws_root_config.clone());
}
let normalized_toml = normalize_toml(
@ -996,7 +995,7 @@ fn inheritable_from_path(
// Let the borrow exit scope so that it can be picked up if there is a need to
// read a manifest
if let Some(ws_root) = gctx.ws_roots.borrow().get(workspace_path_root) {
if let Some(ws_root) = gctx.ws_roots().get(workspace_path_root) {
return Ok(ws_root.inheritable().clone());
};
@ -1004,9 +1003,7 @@ fn inheritable_from_path(
let man = read_manifest(&workspace_path, source_id, gctx)?;
match man.workspace_config() {
WorkspaceConfig::Root(root) => {
gctx.ws_roots
.borrow_mut()
.insert(workspace_path, root.clone());
gctx.ws_roots().insert(workspace_path, root.clone());
Ok(root.inheritable().clone())
}
_ => bail!(