Fix cyclic dependencies
This commit is contained in:
@@ -280,6 +280,7 @@ class ModList {
|
|||||||
loadOrder.errors.add(
|
loadOrder.errors.add(
|
||||||
"Cyclic dependency detected: ${cyclePath.join(' -> ')}",
|
"Cyclic dependency detected: ${cyclePath.join(' -> ')}",
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mod.visited) {
|
if (!mod.visited) {
|
||||||
@@ -514,11 +515,16 @@ class ModList {
|
|||||||
LoadOrder? loadOrder,
|
LoadOrder? loadOrder,
|
||||||
List<String>? toEnable,
|
List<String>? toEnable,
|
||||||
Map<String, bool>? seen,
|
Map<String, bool>? seen,
|
||||||
|
List<String>? cyclePath,
|
||||||
]) {
|
]) {
|
||||||
final mod = mods[modId]!;
|
final mod = mods[modId]!;
|
||||||
loadOrder ??= LoadOrder();
|
loadOrder ??= LoadOrder();
|
||||||
toEnable ??= <String>[];
|
toEnable ??= <String>[];
|
||||||
seen ??= <String, bool>{};
|
seen ??= <String, bool>{};
|
||||||
|
cyclePath ??= <String>[];
|
||||||
|
|
||||||
|
// Add current mod to cycle path
|
||||||
|
cyclePath.add(modId);
|
||||||
|
|
||||||
for (final dep in mod.dependencies) {
|
for (final dep in mod.dependencies) {
|
||||||
if (!mods.containsKey(dep)) {
|
if (!mods.containsKey(dep)) {
|
||||||
@@ -529,12 +535,20 @@ class ModList {
|
|||||||
}
|
}
|
||||||
final depMod = mods[dep]!;
|
final depMod = mods[dep]!;
|
||||||
if (seen[dep] == true) {
|
if (seen[dep] == true) {
|
||||||
loadOrder.errors.add('Cyclic dependency detected: $modId -> $dep');
|
// Find the start of the cycle
|
||||||
|
int cycleStart = cyclePath.indexOf(dep);
|
||||||
|
if (cycleStart >= 0) {
|
||||||
|
// Extract the cycle part
|
||||||
|
List<String> cycleIds = [...cyclePath.sublist(cycleStart), modId];
|
||||||
|
loadOrder.errors.add('Cyclic dependency detected: ${cycleIds.join(' -> ')}');
|
||||||
|
} else {
|
||||||
|
loadOrder.errors.add('Cyclic dependency detected: $modId -> $dep');
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
seen[dep] = true;
|
seen[dep] = true;
|
||||||
toEnable.add(depMod.id);
|
toEnable.add(depMod.id);
|
||||||
loadDependencies(depMod.id, loadOrder, toEnable, seen);
|
loadDependencies(depMod.id, loadOrder, toEnable, seen, List.from(cyclePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadOrder;
|
return loadOrder;
|
||||||
|
Reference in New Issue
Block a user