mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(toml): Group workspace inheritance functions
This commit is contained in:
parent
dd8f8dc645
commit
b63e385a89
@ -1228,33 +1228,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>,
|
||||
@ -1561,6 +1534,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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user