Chromium Code Reviews| Index: utils/pub/solver/version_solver.dart |
| diff --git a/utils/pub/solver/version_solver.dart b/utils/pub/solver/version_solver.dart |
| index 1169ae20f988533cf46d1e81eb4e6ce33402d69b..fbf996ee4a5ed50d9689e982625d85ae8cf38faa 100644 |
| --- a/utils/pub/solver/version_solver.dart |
| +++ b/utils/pub/solver/version_solver.dart |
| @@ -11,6 +11,7 @@ import '../lock_file.dart'; |
| import '../log.dart' as log; |
| import '../package.dart'; |
| import '../pubspec.dart'; |
| +import '../sdk.dart' as sdk; |
| import '../source.dart'; |
| import '../source_registry.dart'; |
| import '../version.dart'; |
| @@ -46,6 +47,17 @@ Future<SolveResult> resolveVersions(SourceRegistry sources, Package root, |
| return solver.solve(); |
| } |
| +/// Ensures that if [pubspec] has an SDK constraint, then it is compatible |
| +/// with the current SDK. Throws a [SolverFailure] if not. |
| +void validateSdkConstraint(Pubspec pubspec) { |
|
nweiz
2013/04/16 23:52:32
It seems really weird that this is a top-level, pu
Bob Nystrom
2013/04/17 17:28:44
It was being used by both VersionSolver and Backtr
|
| + if (pubspec.environment.sdkVersion.allows(sdk.version)) return; |
| + |
| + throw new CouldNotSolveException( |
| + 'Package "{pubspec.name} requires SDK version ' |
| + '${pubspec.environment.sdkVersion} but the current SDK is ' |
| + '${sdk.version}.'); |
| +} |
| + |
| /// Base class for an implementation of the version constraint solver. |
| class VersionSolver { |
| final SourceRegistry sources; |
| @@ -73,12 +85,16 @@ class VersionSolver { |
| /// successful or an error if it failed to find a solution. |
| Future<SolveResult> solve() { |
| var stopwatch = new Stopwatch(); |
| - stopwatch.start(); |
| - // Pre-cache the root package's known pubspec. |
| - cache.cache(new PackageId.root(root), root.pubspec); |
| + return new Future(() { |
| + stopwatch.start(); |
| - return runSolver().then((packages) { |
| + // Pre-cache the root package's known pubspec. |
| + cache.cache(new PackageId.root(root), root.pubspec); |
| + |
| + validateSdkConstraint(root.pubspec); |
| + return runSolver(); |
| + }).then((packages) { |
| return new SolveResult(packages, null, attemptedSolutions); |
| }).catchError((error) { |
| if (error is! SolveFailure) throw error; |
| @@ -304,12 +320,13 @@ class SolveFailure implements Exception { |
| /// Exception thrown when the [VersionSolver] fails to find a solution after a |
| /// certain number of iterations. |
| class CouldNotSolveException extends SolveFailure { |
| - CouldNotSolveException() |
| - : super(null, null); |
| + CouldNotSolveException([String message]) |
| + : super(null, null), |
| + _message = (message != null) ? message : |
| + "Could not find a solution that met all constraints."; |
| /// A message describing the specific kind of solve failure. |
| - String get _message => |
| - "Could not find a solution that met all constraints."; |
| + final String _message; |
| } |
| /// Exception thrown when the [VersionConstraint] used to match a package is |