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 /** | 5 /** |
6 * Attempts to resolve a set of version constraints for a package dependency | 6 * Attempts to resolve a set of version constraints for a package dependency |
7 * graph and select an appropriate set of best specific versions for all | 7 * graph and select an appropriate set of best specific versions for all |
8 * dependent packages. It works iteratively and tries to reach a stable | 8 * dependent packages. It works iteratively and tries to reach a stable |
9 * solution where the constraints of all dependencies are met. If it fails to | 9 * solution where the constraints of all dependencies are met. If it fails to |
10 * reach a solution after a certain number of iterations, it assumes the | 10 * reach a solution after a certain number of iterations, it assumes the |
(...skipping 20 matching lines...) Expand all Loading... |
31 * of the constraints that its depending packages place on it. If that overall | 31 * of the constraints that its depending packages place on it. If that overall |
32 * constraint changes (say from "<3.0.0" to "<2.5.0"), then the currently | 32 * constraint changes (say from "<3.0.0" to "<2.5.0"), then the currently |
33 * picked version for that package may fall outside of the new constraint. If | 33 * picked version for that package may fall outside of the new constraint. If |
34 * that happens, we find the new best version that meets the updated constraint | 34 * that happens, we find the new best version that meets the updated constraint |
35 * and then the change the package to use that version. That cycles back up to | 35 * and then the change the package to use that version. That cycles back up to |
36 * the beginning again. | 36 * the beginning again. |
37 */ | 37 */ |
38 #library('version_solver'); | 38 #library('version_solver'); |
39 | 39 |
40 #import('dart:json'); | 40 #import('dart:json'); |
| 41 #import('dart:math'); |
41 #import('lock_file.dart'); | 42 #import('lock_file.dart'); |
42 #import('package.dart'); | 43 #import('package.dart'); |
43 #import('pubspec.dart'); | 44 #import('pubspec.dart'); |
44 #import('root_source.dart'); | 45 #import('root_source.dart'); |
45 #import('source.dart'); | 46 #import('source.dart'); |
46 #import('source_registry.dart'); | 47 #import('source_registry.dart'); |
47 #import('utils.dart'); | 48 #import('utils.dart'); |
48 #import('version.dart'); | 49 #import('version.dart'); |
49 | 50 |
50 /** | 51 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // Stop if we are done. | 89 // Stop if we are done. |
89 if (_work.isEmpty()) return new Future.immediate(buildResults()); | 90 if (_work.isEmpty()) return new Future.immediate(buildResults()); |
90 | 91 |
91 // If we appear to be stuck in a loop, then we probably have an unstable | 92 // If we appear to be stuck in a loop, then we probably have an unstable |
92 // graph, bail. We guess this based on a rough heuristic that it should | 93 // graph, bail. We guess this based on a rough heuristic that it should |
93 // only take a certain number of steps to solve a graph with a given | 94 // only take a certain number of steps to solve a graph with a given |
94 // number of connections. | 95 // number of connections. |
95 // TODO(rnystrom): These numbers here are magic and arbitrary. Tune | 96 // TODO(rnystrom): These numbers here are magic and arbitrary. Tune |
96 // when we have a better picture of real-world package topologies. | 97 // when we have a better picture of real-world package topologies. |
97 _numIterations++; | 98 _numIterations++; |
98 if (_numIterations > Math.max(50, _packages.length * 5)) { | 99 if (_numIterations > max(50, _packages.length * 5)) { |
99 throw new CouldNotSolveException(); | 100 throw new CouldNotSolveException(); |
100 } | 101 } |
101 | 102 |
102 // Run the first work item. | 103 // Run the first work item. |
103 var future = _work.removeFirst().process(this); | 104 var future = _work.removeFirst().process(this); |
104 | 105 |
105 // If we have an async operation to perform, chain the loop to resume | 106 // If we have an async operation to perform, chain the loop to resume |
106 // when it's done. Otherwise, just loop synchronously. | 107 // when it's done. Otherwise, just loop synchronously. |
107 if (future != null) { | 108 if (future != null) { |
108 return future.chain(processNextWorkItem); | 109 return future.chain(processNextWorkItem); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 final description1; | 574 final description1; |
574 final description2; | 575 final description2; |
575 | 576 |
576 DescriptionMismatchException(this.package, this.description1, | 577 DescriptionMismatchException(this.package, this.description1, |
577 this.description2); | 578 this.description2); |
578 | 579 |
579 // TODO(nweiz): Dump to YAML when that's supported | 580 // TODO(nweiz): Dump to YAML when that's supported |
580 String toString() => "Package '$package' has conflicting descriptions " | 581 String toString() => "Package '$package' has conflicting descriptions " |
581 "'${JSON.stringify(description1)}' and '${JSON.stringify(description2)}'"; | 582 "'${JSON.stringify(description1)}' and '${JSON.stringify(description2)}'"; |
582 } | 583 } |
OLD | NEW |