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 /// A back-tracking depth-first solver. Attempts to find the best solution for | 5 /// A back-tracking depth-first solver. Attempts to find the best solution for |
6 /// a root package's transitive dependency graph, where a "solution" is a set | 6 /// a root package's transitive dependency graph, where a "solution" is a set |
7 /// of concrete package versions. A valid solution will select concrete | 7 /// of concrete package versions. A valid solution will select concrete |
8 /// versions for every package reached from the root package's dependency graph, | 8 /// versions for every package reached from the root package's dependency graph, |
9 /// and each of those packages will fit the version constraints placed on it. | 9 /// and each of those packages will fit the version constraints placed on it. |
10 /// | 10 /// |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // Given a package dep, returns a future that completes to a pair of the | 397 // Given a package dep, returns a future that completes to a pair of the |
398 // dep and the number of versions available for it. | 398 // dep and the number of versions available for it. |
399 getNumVersions(PackageDep dep) { | 399 getNumVersions(PackageDep dep) { |
400 // There is only ever one version of the root package. | 400 // There is only ever one version of the root package. |
401 if (dep.isRoot) { | 401 if (dep.isRoot) { |
402 return new Future.value(new Pair<PackageDep, int>(dep, 1)); | 402 return new Future.value(new Pair<PackageDep, int>(dep, 1)); |
403 } | 403 } |
404 | 404 |
405 return _solver.cache.getVersions(dep.toRef()).then((versions) { | 405 return _solver.cache.getVersions(dep.toRef()).then((versions) { |
406 return new Pair<PackageDep, int>(dep, versions.length); | 406 return new Pair<PackageDep, int>(dep, versions.length); |
407 }).catchError((error) { | 407 }).catchError((error, trace) { |
408 // If it fails for any reason, just treat that as no versions. This | 408 // If it fails for any reason, just treat that as no versions. This |
409 // will sort this reference higher so that we can traverse into it | 409 // will sort this reference higher so that we can traverse into it |
410 // and report the error more properly. | 410 // and report the error more properly. |
411 log.solver("Could not get versions for $dep:\n$error\n\n" | 411 log.solver("Could not get versions for $dep:\n$error\n\n$trace"); |
412 "${getAttachedStackTrace(error)}"); | |
413 return new Pair<PackageDep, int>(dep, 0); | 412 return new Pair<PackageDep, int>(dep, 0); |
414 }); | 413 }); |
415 } | 414 } |
416 | 415 |
417 return Future.wait(deps.map(getNumVersions)).then((pairs) { | 416 return Future.wait(deps.map(getNumVersions)).then((pairs) { |
418 // Future.wait() returns an immutable list, so make a copy. | 417 // Future.wait() returns an immutable list, so make a copy. |
419 pairs = pairs.toList(); | 418 pairs = pairs.toList(); |
420 | 419 |
421 // Sort in best-first order to minimize backtracking. | 420 // Sort in best-first order to minimize backtracking. |
422 pairs.sort((a, b) { | 421 pairs.sort((a, b) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 // know what they're doing. | 635 // know what they're doing. |
637 if (sdk.isBleedingEdge) return; | 636 if (sdk.isBleedingEdge) return; |
638 | 637 |
639 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; | 638 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; |
640 | 639 |
641 throw new BadSdkVersionException(pubspec.name, | 640 throw new BadSdkVersionException(pubspec.name, |
642 'Package ${pubspec.name} requires SDK version ' | 641 'Package ${pubspec.name} requires SDK version ' |
643 '${pubspec.environment.sdkVersion} but the current SDK is ' | 642 '${pubspec.environment.sdkVersion} but the current SDK is ' |
644 '${sdk.version}.'); | 643 '${sdk.version}.'); |
645 } | 644 } |
OLD | NEW |