gracefully handle cycles in crate graph

rust-lang/rust has absolutely weird setup with rustc-workspace-shim,
which leads to real cycles.
This commit is contained in:
Aleksey Kladov 2019-01-13 12:27:26 +03:00
parent 40686722ba
commit 77f67ca7e2
3 changed files with 78 additions and 41 deletions

View file

@ -73,7 +73,9 @@ impl ServerWorldState {
if let (Some(&from), Some(&to)) =
(sysroot_crates.get(&from), sysroot_crates.get(&to))
{
crate_graph.add_dep(from, name.clone(), to);
if let Err(_) = crate_graph.add_dep(from, name.clone(), to) {
log::error!("cyclic dependency between sysroot crates")
}
}
}
}
@ -108,11 +110,20 @@ impl ServerWorldState {
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
if let Some(to) = lib_tgt {
if to != from {
crate_graph.add_dep(from, pkg.name(&ws.cargo).into(), to);
if let Err(_) =
crate_graph.add_dep(from, pkg.name(&ws.cargo).into(), to)
{
log::error!(
"cyclic dependency between targets of {}",
pkg.name(&ws.cargo)
)
}
}
}
if let Some(std) = libstd {
crate_graph.add_dep(from, "std".into(), std);
if let Err(_) = crate_graph.add_dep(from, "std".into(), std) {
log::error!("cyclic dependency on std for {}", pkg.name(&ws.cargo))
}
}
}
}
@ -123,7 +134,13 @@ impl ServerWorldState {
for dep in pkg.dependencies(&ws.cargo) {
if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
crate_graph.add_dep(from, dep.name.clone(), to);
if let Err(_) = crate_graph.add_dep(from, dep.name.clone(), to) {
log::error!(
"cyclic dependency {} -> {}",
pkg.name(&ws.cargo),
dep.pkg.name(&ws.cargo)
)
}
}
}
}