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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/version_solver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 pub.solver.version_solver; 5 library pub.solver.version_solver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import "dart:convert"; 8 import "dart:convert";
9 9
10 import '../lock_file.dart'; 10 import '../lock_file.dart';
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return source.describe(id).then((pubspec) { 114 return source.describe(id).then((pubspec) {
115 _pubspecs[id] = pubspec; 115 _pubspecs[id] = pubspec;
116 return pubspec; 116 return pubspec;
117 }); 117 });
118 } 118 }
119 119
120 /// Returns the previously cached pubspec for the package identified by [id] 120 /// Returns the previously cached pubspec for the package identified by [id]
121 /// or returns `null` if not in the cache. 121 /// or returns `null` if not in the cache.
122 Pubspec getCachedPubspec(PackageId id) => _pubspecs[id]; 122 Pubspec getCachedPubspec(PackageId id) => _pubspecs[id];
123 123
124 /// Gets the list of versions for [package] in descending order. 124 /// Gets the list of versions for [package].
125 ///
126 /// Packages are sorted in descending version order with all "stable"
127 /// versions (i.e. ones without a prerelease suffix) before pre-release
128 /// versions. This ensures that the solver prefers stable packages over
129 /// unstable ones.
125 Future<List<PackageId>> getVersions(PackageRef package) { 130 Future<List<PackageId>> getVersions(PackageRef package) {
126 if (package.isRoot) { 131 if (package.isRoot) {
127 throw new StateError("Cannot get versions for root package $package."); 132 throw new StateError("Cannot get versions for root package $package.");
128 } 133 }
129 134
130 // See if we have it cached. 135 // See if we have it cached.
131 var versions = _versions[package]; 136 var versions = _versions[package];
132 if (versions != null) { 137 if (versions != null) {
133 versionCacheHits++; 138 versionCacheHits++;
134 return new Future.value(versions); 139 return new Future.value(versions);
135 } 140 }
136 141
137 versionCacheMisses++; 142 versionCacheMisses++;
138 143
139 var source = _sources[package.source]; 144 var source = _sources[package.source];
140 return source.getVersions(package.name, package.description) 145 return source.getVersions(package.name, package.description)
141 .then((versions) { 146 .then((versions) {
142 // Sort by descending version so we try newer versions first. 147 // Sort by descending version so we try newer versions first.
143 versions.sort((a, b) => b.compareTo(a)); 148 versions.sort((a, b) {
149 // Sort all prerelease versions after all normal versions. This way
150 // the solver will prefer stable packages over unstable ones.
151 if (a.isPreRelease && !b.isPreRelease) return 1;
152 if (!a.isPreRelease && b.isPreRelease) return -1;
153
154 return b.compareTo(a);
155 });
144 156
145 var ids = versions.map((version) => package.atVersion(version)).toList(); 157 var ids = versions.map((version) => package.atVersion(version)).toList();
146 _versions[package] = ids; 158 _versions[package] = ids;
147 return ids; 159 return ids;
148 }); 160 });
149 } 161 }
150 } 162 }
151 163
152 /// A reference from a depending package to a package that it depends on. 164 /// A reference from a depending package to a package that it depends on.
153 class Dependency { 165 class Dependency {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 Iterable<Dependency> dependencies) 302 Iterable<Dependency> dependencies)
291 : super(package, dependencies); 303 : super(package, dependencies);
292 304
293 String get _message => "Incompatible dependencies on '$package'"; 305 String get _message => "Incompatible dependencies on '$package'";
294 306
295 String _describeDependency(PackageDep dep) { 307 String _describeDependency(PackageDep dep) {
296 // TODO(nweiz): Dump descriptions to YAML when that's supported. 308 // TODO(nweiz): Dump descriptions to YAML when that's supported.
297 return "depends on it with description ${JSON.encode(dep.description)}"; 309 return "depends on it with description ${JSON.encode(dep.description)}";
298 } 310 }
299 } 311 }
OLDNEW
« 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