| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #import('version.dart'); | 47 #import('version.dart'); |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Attempts to select the best concrete versions for all of the transitive | 50 * Attempts to select the best concrete versions for all of the transitive |
| 51 * dependencies of [root] taking into account all of the [VersionConstraint]s | 51 * dependencies of [root] taking into account all of the [VersionConstraint]s |
| 52 * that those dependencies place on each other. If successful, completes to a | 52 * that those dependencies place on each other. If successful, completes to a |
| 53 * [Map] that maps package names to the selected version for that package. If | 53 * [Map] that maps package names to the selected version for that package. If |
| 54 * it fails, the future will complete with a [NoVersionException], | 54 * it fails, the future will complete with a [NoVersionException], |
| 55 * [DisjointConstraintException], or [CouldNotSolveException]. | 55 * [DisjointConstraintException], or [CouldNotSolveException]. |
| 56 */ | 56 */ |
| 57 Future<Map<String, Version>> resolveVersions( | 57 Future<List<PackageId>> resolveVersions(SourceRegistry sources, Package root) { |
| 58 SourceRegistry sources, Package root) { | |
| 59 return new VersionSolver(sources, root).solve(); | 58 return new VersionSolver(sources, root).solve(); |
| 60 } | 59 } |
| 61 | 60 |
| 62 class VersionSolver { | 61 class VersionSolver { |
| 63 final SourceRegistry _sources; | 62 final SourceRegistry _sources; |
| 64 final Package _root; | 63 final Package _root; |
| 65 final PubspecCache _pubspecs; | 64 final PubspecCache _pubspecs; |
| 66 final Map<String, Dependency> _packages; | 65 final Map<String, Dependency> _packages; |
| 67 final Queue<WorkItem> _work; | 66 final Queue<WorkItem> _work; |
| 68 int _numIterations = 0; | 67 int _numIterations = 0; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return _packages[package]; | 121 return _packages[package]; |
| 123 } | 122 } |
| 124 | 123 |
| 125 /** | 124 /** |
| 126 * Sets the best selected version of [package] to [version]. | 125 * Sets the best selected version of [package] to [version]. |
| 127 */ | 126 */ |
| 128 void setVersion(String package, Version version) { | 127 void setVersion(String package, Version version) { |
| 129 _packages[package].version = version; | 128 _packages[package].version = version; |
| 130 } | 129 } |
| 131 | 130 |
| 132 Map<String, Version> buildResults() { | 131 List<PackageId> buildResults() { |
| 133 var results = <Version>{}; | 132 return _packages.getValues() |
| 134 _packages.forEach((name, dependency) { | 133 .filter((dep) => dep.isDependedOn) |
| 135 if (dependency.isDependedOn) { | 134 .map((dep) => new PackageId(dep.source, dep.version, dep.description)); |
| 136 results[name] = dependency.version; | |
| 137 } | |
| 138 }); | |
| 139 | |
| 140 return results; | |
| 141 } | 135 } |
| 142 } | 136 } |
| 143 | 137 |
| 144 /** | 138 /** |
| 145 * The constraint solver works by iteratively processing a queue of work items. | 139 * The constraint solver works by iteratively processing a queue of work items. |
| 146 * Each item is a single atomic change to the dependency graph. Handling them | 140 * Each item is a single atomic change to the dependency graph. Handling them |
| 147 * in a queue lets us handle asynchrony (resolving versions requires information | 141 * in a queue lets us handle asynchrony (resolving versions requires information |
| 148 * from servers) as well as avoid deeply nested recursion. | 142 * from servers) as well as avoid deeply nested recursion. |
| 149 */ | 143 */ |
| 150 interface WorkItem { | 144 interface WorkItem { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 final description1; | 546 final description1; |
| 553 final description2; | 547 final description2; |
| 554 | 548 |
| 555 DescriptionMismatchException(this.package, this.description1, | 549 DescriptionMismatchException(this.package, this.description1, |
| 556 this.description2); | 550 this.description2); |
| 557 | 551 |
| 558 // TODO(nweiz): Dump to YAML when that's supported | 552 // TODO(nweiz): Dump to YAML when that's supported |
| 559 String toString() => "Package '$package' has conflicting descriptions " | 553 String toString() => "Package '$package' has conflicting descriptions " |
| 560 "'${JSON.stringify(description1)}' and '${JSON.stringify(description2)}'"; | 554 "'${JSON.stringify(description1)}' and '${JSON.stringify(description2)}'"; |
| 561 } | 555 } |
| OLD | NEW |