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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 enqueue(new UnlockPackage(depender)); | 197 enqueue(new UnlockPackage(depender)); |
198 return true; | 198 return true; |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 return dependency.dependers.map(getDependency).some((subdependency) => | 202 return dependency.dependers.map(getDependency).some((subdependency) => |
203 tryUnlockDepender(subdependency, seen)); | 203 tryUnlockDepender(subdependency, seen)); |
204 } | 204 } |
205 | 205 |
206 List<PackageId> buildResults() { | 206 List<PackageId> buildResults() { |
207 return _packages.getValues().filter((dep) => dep.isDependedOn).map((dep) { | 207 return _packages.values.filter((dep) => dep.isDependedOn).map((dep) { |
208 var description = dep.description; | 208 var description = dep.description; |
209 | 209 |
210 // If the lockfile contains a fully-resolved description for the package, | 210 // If the lockfile contains a fully-resolved description for the package, |
211 // use that. This allows e.g. Git to ensure that the same commit is used. | 211 // use that. This allows e.g. Git to ensure that the same commit is used. |
212 var lockedPackage = lockFile.packages[dep.name]; | 212 var lockedPackage = lockFile.packages[dep.name]; |
213 if (lockedPackage != null && lockedPackage.version == dep.version && | 213 if (lockedPackage != null && lockedPackage.version == dep.version && |
214 lockedPackage.source.name == dep.source.name && | 214 lockedPackage.source.name == dep.source.name && |
215 dep.source.descriptionsEqual( | 215 dep.source.descriptionsEqual( |
216 description, lockedPackage.description)) { | 216 description, lockedPackage.description)) { |
217 description = lockedPackage.description; | 217 description = lockedPackage.description; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 solver.setVersion(package, version); | 271 solver.setVersion(package, version); |
272 | 272 |
273 // The dependencies between the old and new version may be different. Walk | 273 // The dependencies between the old and new version may be different. Walk |
274 // them both and update any constraints that differ between the two. | 274 // them both and update any constraints that differ between the two. |
275 return Futures.wait([ | 275 return Futures.wait([ |
276 getDependencyRefs(solver, oldVersion), | 276 getDependencyRefs(solver, oldVersion), |
277 getDependencyRefs(solver, version)]).transform((list) { | 277 getDependencyRefs(solver, version)]).transform((list) { |
278 var oldDependencyRefs = list[0]; | 278 var oldDependencyRefs = list[0]; |
279 var newDependencyRefs = list[1]; | 279 var newDependencyRefs = list[1]; |
280 | 280 |
281 for (var oldRef in oldDependencyRefs.getValues()) { | 281 for (var oldRef in oldDependencyRefs.values) { |
282 if (newDependencyRefs.containsKey(oldRef.name)) { | 282 if (newDependencyRefs.containsKey(oldRef.name)) { |
283 // The dependency is in both versions of this package, but its | 283 // The dependency is in both versions of this package, but its |
284 // constraint may have changed. | 284 // constraint may have changed. |
285 var newRef = newDependencyRefs.remove(oldRef.name); | 285 var newRef = newDependencyRefs.remove(oldRef.name); |
286 solver.enqueue(new AddConstraint(package, newRef)); | 286 solver.enqueue(new AddConstraint(package, newRef)); |
287 } else { | 287 } else { |
288 // The dependency is not in the new version of the package, so just | 288 // The dependency is not in the new version of the package, so just |
289 // remove its constraint. | 289 // remove its constraint. |
290 solver.enqueue(new RemoveConstraint(package, oldRef.name)); | 290 solver.enqueue(new RemoveConstraint(package, oldRef.name)); |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 // Everything that's left is a depdendency that's only in the new | 294 // Everything that's left is a depdendency that's only in the new |
295 // version of the package. | 295 // version of the package. |
296 for (var newRef in newDependencyRefs.getValues()) { | 296 for (var newRef in newDependencyRefs.values) { |
297 solver.enqueue(new AddConstraint(package, newRef)); | 297 solver.enqueue(new AddConstraint(package, newRef)); |
298 } | 298 } |
299 }); | 299 }); |
300 } | 300 } |
301 | 301 |
302 /** | 302 /** |
303 * Get the dependencies at [version] of the package being changed. | 303 * Get the dependencies at [version] of the package being changed. |
304 */ | 304 */ |
305 Future<Map<String, PackageRef>> getDependencyRefs(VersionSolver solver, | 305 Future<Map<String, PackageRef>> getDependencyRefs(VersionSolver solver, |
306 Version version) { | 306 Version version) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 bool useLatestVersion = false; | 541 bool useLatestVersion = false; |
542 | 542 |
543 /** | 543 /** |
544 * Gets whether or not any other packages are currently depending on this | 544 * Gets whether or not any other packages are currently depending on this |
545 * one. If `false`, then it means this package is not part of the dependency | 545 * one. If `false`, then it means this package is not part of the dependency |
546 * graph and should be omitted. | 546 * graph and should be omitted. |
547 */ | 547 */ |
548 bool get isDependedOn => !_refs.isEmpty; | 548 bool get isDependedOn => !_refs.isEmpty; |
549 | 549 |
550 /** The names of all the packages that depend on this dependency. */ | 550 /** The names of all the packages that depend on this dependency. */ |
551 Collection<String> get dependers => _refs.getKeys(); | 551 Collection<String> get dependers => _refs.keys; |
552 | 552 |
553 /** | 553 /** |
554 * Gets the overall constraint that all packages are placing on this one. | 554 * Gets the overall constraint that all packages are placing on this one. |
555 * If no packages have a constraint on this one (which can happen when this | 555 * If no packages have a constraint on this one (which can happen when this |
556 * package is in the process of being added to the graph), returns `null`. | 556 * package is in the process of being added to the graph), returns `null`. |
557 */ | 557 */ |
558 VersionConstraint get constraint { | 558 VersionConstraint get constraint { |
559 if (_refs.isEmpty) return null; | 559 if (_refs.isEmpty) return null; |
560 return new VersionConstraint.intersect( | 560 return new VersionConstraint.intersect( |
561 _refs.getValues().map((ref) => ref.constraint)); | 561 _refs.values.map((ref) => ref.constraint)); |
562 } | 562 } |
563 | 563 |
564 /// The source of this dependency's package. | 564 /// The source of this dependency's package. |
565 Source get source { | 565 Source get source { |
566 var canonical = _canonicalRef(); | 566 var canonical = _canonicalRef(); |
567 if (canonical == null) return null; | 567 if (canonical == null) return null; |
568 return canonical.source; | 568 return canonical.source; |
569 } | 569 } |
570 | 570 |
571 /// The description of this dependency's package. | 571 /// The description of this dependency's package. |
572 get description { | 572 get description { |
573 var canonical = _canonicalRef(); | 573 var canonical = _canonicalRef(); |
574 if (canonical == null) return null; | 574 if (canonical == null) return null; |
575 return canonical.description; | 575 return canonical.description; |
576 } | 576 } |
577 | 577 |
578 /// Return the PackageRef that has the canonical source and description for | 578 /// Return the PackageRef that has the canonical source and description for |
579 /// this package. If any dependency requires that this package come from a | 579 /// this package. If any dependency requires that this package come from a |
580 /// [RootSource], that will be used; otherwise, it will be the source and | 580 /// [RootSource], that will be used; otherwise, it will be the source and |
581 /// description that all dependencies agree upon. | 581 /// description that all dependencies agree upon. |
582 PackageRef _canonicalRef() { | 582 PackageRef _canonicalRef() { |
583 if (_refs.isEmpty) return null; | 583 if (_refs.isEmpty) return null; |
584 var refs = _refs.getValues(); | 584 var refs = _refs.values; |
585 for (var ref in refs) { | 585 for (var ref in refs) { |
586 if (ref is RootSource) return ref; | 586 if (ref is RootSource) return ref; |
587 } | 587 } |
588 return refs[0]; | 588 return refs[0]; |
589 } | 589 } |
590 | 590 |
591 Dependency(this.name) | 591 Dependency(this.name) |
592 : _refs = <String, PackageRef>{}; | 592 : _refs = <String, PackageRef>{}; |
593 | 593 |
594 Dependency._clone(Dependency other) | 594 Dependency._clone(Dependency other) |
(...skipping 23 matching lines...) Expand all Loading... |
618 } | 618 } |
619 | 619 |
620 _refs[package] = ref; | 620 _refs[package] = ref; |
621 } | 621 } |
622 | 622 |
623 /// Returns a PackageRef whose source and description any new constraints are | 623 /// Returns a PackageRef whose source and description any new constraints are |
624 /// required to match. Returns null if there are no requirements on new | 624 /// required to match. Returns null if there are no requirements on new |
625 /// constraints. | 625 /// constraints. |
626 PackageRef _requiredRef() { | 626 PackageRef _requiredRef() { |
627 if (_refs.isEmpty) return null; | 627 if (_refs.isEmpty) return null; |
628 var refs = _refs.getValues(); | 628 var refs = _refs.values; |
629 var first = refs[0]; | 629 var first = refs[0]; |
630 if (refs.length == 1) { | 630 if (refs.length == 1) { |
631 if (first.source is RootSource) return null; | 631 if (first.source is RootSource) return null; |
632 return first; | 632 return first; |
633 } | 633 } |
634 return refs[1]; | 634 return refs[1]; |
635 } | 635 } |
636 | 636 |
637 /** | 637 /** |
638 * Removes the constraint from [package] onto this. | 638 * Removes the constraint from [package] onto this. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 final description1; | 724 final description1; |
725 final description2; | 725 final description2; |
726 | 726 |
727 DescriptionMismatchException(this.package, this.description1, | 727 DescriptionMismatchException(this.package, this.description1, |
728 this.description2); | 728 this.description2); |
729 | 729 |
730 // TODO(nweiz): Dump to YAML when that's supported | 730 // TODO(nweiz): Dump to YAML when that's supported |
731 String toString() => "Package '$package' has conflicting descriptions " | 731 String toString() => "Package '$package' has conflicting descriptions " |
732 "'${JSON.stringify(description1)}' and '${JSON.stringify(description2)}'"; | 732 "'${JSON.stringify(description1)}' and '${JSON.stringify(description2)}'"; |
733 } | 733 } |
OLD | NEW |