OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Attempts to resolve a set of version constraints for a package dependency | 5 /// Attempts to resolve a set of version constraints for a package dependency |
6 /// graph and select an appropriate set of best specific versions for all | 6 /// graph and select an appropriate set of best specific versions for all |
7 /// dependent packages. It works iteratively and tries to reach a stable | 7 /// dependent packages. It works iteratively and tries to reach a stable |
8 /// solution where the constraints of all dependencies are met. If it fails to | 8 /// solution where the constraints of all dependencies are met. If it fails to |
9 /// reach a solution after a certain number of iterations, it assumes the | 9 /// reach a solution after a certain number of iterations, it assumes the |
10 /// dependency graph is unstable and reports and error. | 10 /// dependency graph is unstable and reports and error. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Future<List<PackageId>> solve() { | 90 Future<List<PackageId>> solve() { |
91 // Kick off the work by adding the root package at its concrete version to | 91 // Kick off the work by adding the root package at its concrete version to |
92 // the dependency graph. | 92 // the dependency graph. |
93 var ref = new PackageRef.root(_root); | 93 var ref = new PackageRef.root(_root); |
94 enqueue(new AddConstraint('(entrypoint)', ref)); | 94 enqueue(new AddConstraint('(entrypoint)', ref)); |
95 _pubspecs.cache(ref.atVersion(_root.version), _root.pubspec); | 95 _pubspecs.cache(ref.atVersion(_root.version), _root.pubspec); |
96 | 96 |
97 Future processNextWorkItem(_) { | 97 Future processNextWorkItem(_) { |
98 while (true) { | 98 while (true) { |
99 // Stop if we are done. | 99 // Stop if we are done. |
100 if (_work.isEmpty) return new Future.immediate(buildResults()); | 100 if (_work.isEmpty) return new Future.value(buildResults()); |
101 | 101 |
102 // If we appear to be stuck in a loop, then we probably have an unstable | 102 // If we appear to be stuck in a loop, then we probably have an unstable |
103 // graph, bail. We guess this based on a rough heuristic that it should | 103 // graph, bail. We guess this based on a rough heuristic that it should |
104 // only take a certain number of steps to solve a graph with a given | 104 // only take a certain number of steps to solve a graph with a given |
105 // number of connections. | 105 // number of connections. |
106 // TODO(rnystrom): These numbers here are magic and arbitrary. Tune | 106 // TODO(rnystrom): These numbers here are magic and arbitrary. Tune |
107 // when we have a better picture of real-world package topologies. | 107 // when we have a better picture of real-world package topologies. |
108 _numIterations++; | 108 _numIterations++; |
109 if (_numIterations > max(50, _packages.length * 5)) { | 109 if (_numIterations > max(50, _packages.length * 5)) { |
110 throw new CouldNotSolveException(); | 110 throw new CouldNotSolveException(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 solver.enqueue(new AddConstraint(package, newRef)); | 277 solver.enqueue(new AddConstraint(package, newRef)); |
278 } | 278 } |
279 }); | 279 }); |
280 } | 280 } |
281 | 281 |
282 /// Get the dependencies at [version] of the package being changed. | 282 /// Get the dependencies at [version] of the package being changed. |
283 Future<Map<String, PackageRef>> getDependencyRefs(VersionSolver solver, | 283 Future<Map<String, PackageRef>> getDependencyRefs(VersionSolver solver, |
284 Version version) { | 284 Version version) { |
285 // If there is no version, it means no package, so no dependencies. | 285 // If there is no version, it means no package, so no dependencies. |
286 if (version == null) { | 286 if (version == null) { |
287 return new Future<Map<String, PackageRef>>.immediate( | 287 return new Future<Map<String, PackageRef>>.value(<String, PackageRef>{}); |
288 <String, PackageRef>{}); | |
289 } | 288 } |
290 | 289 |
291 var id = new PackageId(package, source, version, description); | 290 var id = new PackageId(package, source, version, description); |
292 return solver._pubspecs.load(id).then((pubspec) { | 291 return solver._pubspecs.load(id).then((pubspec) { |
293 var dependencies = <String, PackageRef>{}; | 292 var dependencies = <String, PackageRef>{}; |
294 for (var dependency in pubspec.dependencies) { | 293 for (var dependency in pubspec.dependencies) { |
295 dependencies[dependency.name] = dependency; | 294 dependencies[dependency.name] = dependency; |
296 } | 295 } |
297 | 296 |
298 // Include dev dependencies only from the root package. | 297 // Include dev dependencies only from the root package. |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 467 |
469 /// Caches [pubspec] as the [Pubspec] for the package identified by [id]. | 468 /// Caches [pubspec] as the [Pubspec] for the package identified by [id]. |
470 void cache(PackageId id, Pubspec pubspec) { | 469 void cache(PackageId id, Pubspec pubspec) { |
471 _pubspecs[id] = pubspec; | 470 _pubspecs[id] = pubspec; |
472 } | 471 } |
473 | 472 |
474 /// Loads the pubspec for the package identified by [id]. | 473 /// Loads the pubspec for the package identified by [id]. |
475 Future<Pubspec> load(PackageId id) { | 474 Future<Pubspec> load(PackageId id) { |
476 // Complete immediately if it's already cached. | 475 // Complete immediately if it's already cached. |
477 if (_pubspecs.containsKey(id)) { | 476 if (_pubspecs.containsKey(id)) { |
478 return new Future<Pubspec>.immediate(_pubspecs[id]); | 477 return new Future<Pubspec>.value(_pubspecs[id]); |
479 } | 478 } |
480 | 479 |
481 return id.describe().then((pubspec) { | 480 return id.describe().then((pubspec) { |
482 // Cache it. | 481 // Cache it. |
483 _pubspecs[id] = pubspec; | 482 _pubspecs[id] = pubspec; |
484 return pubspec; | 483 return pubspec; |
485 }); | 484 }); |
486 } | 485 } |
487 } | 486 } |
488 | 487 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 705 |
707 String toString() { | 706 String toString() { |
708 // TODO(nweiz): Dump descriptions to YAML when that's supported. | 707 // TODO(nweiz): Dump descriptions to YAML when that's supported. |
709 return "Incompatible dependencies on '$package':\n" | 708 return "Incompatible dependencies on '$package':\n" |
710 "- '$depender1' depends on it with description " | 709 "- '$depender1' depends on it with description " |
711 "${json.stringify(description1)}\n" | 710 "${json.stringify(description1)}\n" |
712 "- '$depender2' depends on it with description " | 711 "- '$depender2' depends on it with description " |
713 "${json.stringify(description2)}"; | 712 "${json.stringify(description2)}"; |
714 } | 713 } |
715 } | 714 } |
OLD | NEW |