verifyTaskPhasesConsistency function
Verify that all tasks in taskMap
lie in phases that are consistent with
their dependencies.
No task can depend on another task that belongs to a build phase that runs after its own.
Tasks cannot be executed on a Zone that does not include its phase.
Any inconsistencies will cause a DartleException to be thrown by this method.
Implementation
Future<void> verifyTaskPhasesConsistency(
Map<String, TaskWithDeps> taskMap) async {
final errors = <String>{};
// a task's dependencies must be in the same or earlier phases
for (final task in taskMap.values) {
task.dependencies.where((dep) => dep.phase.isAfter(task.phase)).forEach(
(t) => errors.add("Task '${task.name}' in phase '${task.phase.name}' "
"cannot depend on '${t.name}' in phase '${t.phase.name}'"));
}
if (errors.isNotEmpty) {
throw DartleException(
message: "The following tasks have dependency on tasks which are in an "
"incompatible build phase:\n"
'${errors.map((e) => ' * $e.').join('\n')}\n');
}
final phases = TaskPhase.currentZoneTaskPhases;
for (final task in taskMap.values) {
if (!phases.contains(task.phase)) {
errors.add("Task '${task.name}' belongs to phase '${task.phase.name}'.");
}
}
if (errors.isNotEmpty) {
final phaseNames = phases.map((p) => p.name).join(', ');
throw DartleException(
message: "The following tasks do not belong to any of the phases in "
"the current Dart Zone, which are $phaseNames}:\n"
'${errors.map((e) => ' * $e.').join('\n')}\n');
}
}