Skip to content

Commit

Permalink
refactor(toml): Group workspace inheritance functions
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 27, 2024
1 parent e409385 commit ccc2d32
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,33 +1221,6 @@ fn to_workspace_config(
ws_root_config
}

fn load_inheritable_fields(
gctx: &GlobalContext,
resolved_path: &Path,
workspace_config: &WorkspaceConfig,
) -> CargoResult<InheritableFields> {
match workspace_config {
WorkspaceConfig::Root(root) => Ok(root.inheritable().clone()),
WorkspaceConfig::Member {
root: Some(ref path_to_root),
} => {
let path = resolved_path
.parent()
.unwrap()
.join(path_to_root)
.join("Cargo.toml");
let root_path = paths::normalize_path(&path);
inheritable_from_path(gctx, root_path)
}
WorkspaceConfig::Member { root: None } => {
match find_workspace_root(&resolved_path, gctx)? {
Some(path_to_root) => inheritable_from_path(gctx, path_to_root),
None => Err(anyhow!("failed to find a workspace root")),
}
}
}
}

fn to_virtual_manifest(
contents: String,
document: toml_edit::ImDocument<String>,
Expand Down Expand Up @@ -1554,6 +1527,33 @@ fn unused_dep_keys(
}
}

fn load_inheritable_fields(
gctx: &GlobalContext,
resolved_path: &Path,
workspace_config: &WorkspaceConfig,
) -> CargoResult<InheritableFields> {
match workspace_config {
WorkspaceConfig::Root(root) => Ok(root.inheritable().clone()),
WorkspaceConfig::Member {
root: Some(ref path_to_root),
} => {
let path = resolved_path
.parent()
.unwrap()
.join(path_to_root)
.join("Cargo.toml");
let root_path = paths::normalize_path(&path);
inheritable_from_path(gctx, root_path)
}
WorkspaceConfig::Member { root: None } => {
match find_workspace_root(&resolved_path, gctx)? {
Some(path_to_root) => inheritable_from_path(gctx, path_to_root),
None => Err(anyhow!("failed to find a workspace root")),
}
}
}
}

fn inheritable_from_path(
gctx: &GlobalContext,
workspace_path: PathBuf,
Expand Down

0 comments on commit ccc2d32

Please sign in to comment.