From b34e65544b24c44f07b81a4ae8b42355aec80a2f Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Tue, 12 Jul 2022 03:05:34 +0300 Subject: [PATCH] Fixed simulation and dependency resolution bugs --- lib/state/component.dart | 34 +++++++++++++++++++++++++--------- lib/utils/simulation.dart | 4 +++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/state/component.dart b/lib/state/component.dart index 9e6c728..251a8bb 100644 --- a/lib/state/component.dart +++ b/lib/state/component.dart @@ -37,7 +37,7 @@ class ComponentState extends ChangeNotifier { await state.setCurrentComponent( project: proj, component: comp, - onDependencyNeeded: (projId, compId) async => _dependenciesMap['$projId/$compId'], + onDependencyNeeded: (projId, compId) async => _dependenciesMap['${projId == "self" ? proj.projectId : projId}/$compId'], ); } return SimulatedComponent( @@ -108,14 +108,30 @@ class ComponentState extends ChangeNotifier { // Load dependencies final unsatisfiedDependencies = []; - for (final depId in component.dependencies) { - final splitted = depId.split('/'); - final maybeDep = await onDependencyNeeded(splitted[0], splitted[1]); - if (maybeDep == null) { - unsatisfiedDependencies.add(depId); - } - else { - addDependency(depId, maybeDep); + final neededDependencies = component.dependencies.toList(); + while (neededDependencies.isNotEmpty) { + final tmp = neededDependencies.toList(); + neededDependencies.clear(); + for (final depId in tmp) { + if (!hasDependency(depId)) { + final splitted = depId.split('/'); + final maybeDep = await onDependencyNeeded(splitted[0], splitted[1]); + if (maybeDep == null) { + unsatisfiedDependencies.add(depId); + } + else { + addDependency(depId, maybeDep); + neededDependencies.addAll( + maybeDep.item2.dependencies + .map((depId) { + final splitted = depId.split('/'); + final projectId = splitted[0] == 'self' ? maybeDep.item1.projectId : splitted[0]; + return '$projectId/${splitted[1]}'; + }) + .where((depId) => !hasDependency(depId)) + ); + } + } } } if (unsatisfiedDependencies.isNotEmpty) { diff --git a/lib/utils/simulation.dart b/lib/utils/simulation.dart index 25b3260..7a5895f 100644 --- a/lib/utils/simulation.dart +++ b/lib/utils/simulation.dart @@ -24,7 +24,9 @@ class SimulatedComponent { String instanceId, String? depId) async { if (!_instances.containsKey(instanceId)) { if (depId != null) { - _instances[instanceId] = await onRequiredDependency(depId); + final splitted = depId.split('/'); + final projectId = splitted[0] == 'self' ? project.projectId : splitted[0]; + _instances[instanceId] = await onRequiredDependency('$projectId/${splitted[1]}'); } else { throw Exception('Attempted to get instance of unknown component'); }