Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Unified Diff: sdk/lib/_internal/pub/lib/src/solver/version_solver.dart

Issue 64213004: Prefer stable versions over pre-release versions in the solver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/version_solver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
diff --git a/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart b/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
index 7e1c52e3a878f4fef9cda0f47f19a12b7e5d1201..83c33256d949159f71364f80ac9a899ab8369325 100644
--- a/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
+++ b/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
@@ -121,7 +121,12 @@ class PubspecCache {
/// or returns `null` if not in the cache.
Pubspec getCachedPubspec(PackageId id) => _pubspecs[id];
- /// Gets the list of versions for [package] in descending order.
+ /// Gets the list of versions for [package].
+ ///
+ /// Packages are sorted in descending version order with all "stable"
+ /// versions (i.e. ones without a prerelease suffix) before pre-release
+ /// versions. This ensures that the solver prefers stable packages over
+ /// unstable ones.
Future<List<PackageId>> getVersions(PackageRef package) {
if (package.isRoot) {
throw new StateError("Cannot get versions for root package $package.");
@@ -140,7 +145,14 @@ class PubspecCache {
return source.getVersions(package.name, package.description)
.then((versions) {
// Sort by descending version so we try newer versions first.
- versions.sort((a, b) => b.compareTo(a));
+ versions.sort((a, b) {
+ // Sort all prerelease versions after all normal versions. This way
+ // the solver will prefer stable packages over unstable ones.
+ if (a.isPreRelease && !b.isPreRelease) return 1;
+ if (!a.isPreRelease && b.isPreRelease) return -1;
+
+ return b.compareTo(a);
+ });
var ids = versions.map((version) => package.atVersion(version)).toList();
_versions[package] = ids;
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/version_solver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698