| 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 library version_solver; | 5 library version_solver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:json' as json; | 8 import 'dart:json' as json; |
| 9 | 9 |
| 10 import '../lock_file.dart'; | 10 import '../lock_file.dart'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 /// The number of solutions the solver has tried so far. | 66 /// The number of solutions the solver has tried so far. |
| 67 int get attemptedSolutions; | 67 int get attemptedSolutions; |
| 68 | 68 |
| 69 /// Force the solver to upgrade [package] to the latest available version. | 69 /// Force the solver to upgrade [package] to the latest available version. |
| 70 void forceLatestVersion(String package); | 70 void forceLatestVersion(String package); |
| 71 | 71 |
| 72 /// Run the solver. Completes with a list of specific package versions if | 72 /// Run the solver. Completes with a list of specific package versions if |
| 73 /// successful or an error if it failed to find a solution. | 73 /// successful or an error if it failed to find a solution. |
| 74 Future<SolveResult> solve() { | 74 Future<SolveResult> solve() { |
| 75 var stopwatch = new Stopwatch(); | 75 var stopwatch = new Stopwatch(); |
| 76 stopwatch.start(); | |
| 77 | 76 |
| 78 // Pre-cache the root package's known pubspec. | 77 return new Future(() { |
| 79 cache.cache(new PackageId.root(root), root.pubspec); | 78 stopwatch.start(); |
| 80 | 79 |
| 81 return runSolver().then((packages) { | 80 // Pre-cache the root package's known pubspec. |
| 81 cache.cache(new PackageId.root(root), root.pubspec); |
| 82 return runSolver(); |
| 83 }).then((packages) { |
| 82 return new SolveResult(packages, null, attemptedSolutions); | 84 return new SolveResult(packages, null, attemptedSolutions); |
| 83 }).catchError((error) { | 85 }).catchError((error) { |
| 84 if (error is! SolveFailure) throw error; | 86 if (error is! SolveFailure) throw error; |
| 85 | 87 |
| 86 // Wrap a failure in a result so we can attach some other data. | 88 // Wrap a failure in a result so we can attach some other data. |
| 87 return new SolveResult(null, error, attemptedSolutions); | 89 return new SolveResult(null, error, attemptedSolutions); |
| 88 }).whenComplete(() { | 90 }).whenComplete(() { |
| 89 // Gather some solving metrics. | 91 // Gather some solving metrics. |
| 90 var buffer = new StringBuffer(); | 92 var buffer = new StringBuffer(); |
| 91 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.'); | 93 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.'); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 299 |
| 298 /// Describes a dependencie's reference in the output message. Override this | 300 /// Describes a dependencie's reference in the output message. Override this |
| 299 /// to highlight which aspect of [ref] led to the failure. | 301 /// to highlight which aspect of [ref] led to the failure. |
| 300 String _describeDependency(PackageRef ref) => | 302 String _describeDependency(PackageRef ref) => |
| 301 "depends on version ${ref.constraint}"; | 303 "depends on version ${ref.constraint}"; |
| 302 } | 304 } |
| 303 | 305 |
| 304 /// Exception thrown when the [VersionSolver] fails to find a solution after a | 306 /// Exception thrown when the [VersionSolver] fails to find a solution after a |
| 305 /// certain number of iterations. | 307 /// certain number of iterations. |
| 306 class CouldNotSolveException extends SolveFailure { | 308 class CouldNotSolveException extends SolveFailure { |
| 307 CouldNotSolveException() | 309 CouldNotSolveException([String message]) |
| 308 : super(null, null); | 310 : super(null, null), |
| 311 _message = (message != null) ? message : |
| 312 "Could not find a solution that met all constraints."; |
| 309 | 313 |
| 310 /// A message describing the specific kind of solve failure. | 314 /// A message describing the specific kind of solve failure. |
| 311 String get _message => | 315 final String _message; |
| 312 "Could not find a solution that met all constraints."; | |
| 313 } | 316 } |
| 314 | 317 |
| 315 /// Exception thrown when the [VersionConstraint] used to match a package is | 318 /// Exception thrown when the [VersionConstraint] used to match a package is |
| 316 /// valid (i.e. non-empty), but there are no available versions of the package | 319 /// valid (i.e. non-empty), but there are no available versions of the package |
| 317 /// that fit that constraint. | 320 /// that fit that constraint. |
| 318 class NoVersionException extends SolveFailure { | 321 class NoVersionException extends SolveFailure { |
| 319 final VersionConstraint constraint; | 322 final VersionConstraint constraint; |
| 320 | 323 |
| 321 NoVersionException(String package, this.constraint, | 324 NoVersionException(String package, this.constraint, |
| 322 Iterable<Dependency> dependencies) | 325 Iterable<Dependency> dependencies) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 Iterable<Dependency> dependencies) | 373 Iterable<Dependency> dependencies) |
| 371 : super(package, dependencies); | 374 : super(package, dependencies); |
| 372 | 375 |
| 373 String get _message => "Incompatible dependencies on '$package'"; | 376 String get _message => "Incompatible dependencies on '$package'"; |
| 374 | 377 |
| 375 String _describeDependency(PackageRef ref) { | 378 String _describeDependency(PackageRef ref) { |
| 376 // TODO(nweiz): Dump descriptions to YAML when that's supported. | 379 // TODO(nweiz): Dump descriptions to YAML when that's supported. |
| 377 return "depends on it with description ${json.stringify(ref.description)}"; | 380 return "depends on it with description ${json.stringify(ref.description)}"; |
| 378 } | 381 } |
| 379 } | 382 } |
| OLD | NEW |