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

Side by Side Diff: lib/src/solver/backtracking_solver.dart

Issue 2184303002: Make pub strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 4 months 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
« no previous file with comments | « lib/src/pubspec.dart ('k') | lib/src/solver/solve_report.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 /// A back-tracking depth-first solver. 5 /// A back-tracking depth-first solver.
6 /// 6 ///
7 /// Attempts to find the best solution for a root package's transitive 7 /// Attempts to find the best solution for a root package's transitive
8 /// dependency graph, where a "solution" is a set of concrete package versions. 8 /// dependency graph, where a "solution" is a set of concrete package versions.
9 /// A valid solution will select concrete versions for every package reached 9 /// A valid solution will select concrete versions for every package reached
10 /// from the root package's dependency graph, and each of those packages will 10 /// from the root package's dependency graph, and each of those packages will
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 _forceLatest.add(package); 132 _forceLatest.add(package);
133 } 133 }
134 134
135 for (var override in root.dependencyOverrides) { 135 for (var override in root.dependencyOverrides) {
136 _overrides[override.name] = override; 136 _overrides[override.name] = override;
137 } 137 }
138 } 138 }
139 139
140 /// Creates [_implicitPubspec]. 140 /// Creates [_implicitPubspec].
141 static Pubspec _makeImplicitPubspec(SystemCache systemCache) { 141 static Pubspec _makeImplicitPubspec(SystemCache systemCache) {
142 var dependencies = []; 142 var dependencies = <PackageDep>[];
143 barback.pubConstraints.forEach((name, constraint) { 143 barback.pubConstraints.forEach((name, constraint) {
144 dependencies.add( 144 dependencies.add(
145 systemCache.sources.hosted.refFor(name) 145 systemCache.sources.hosted.refFor(name)
146 .withConstraint(constraint)); 146 .withConstraint(constraint));
147 }); 147 });
148 148
149 return new Pubspec("pub itself", dependencies: dependencies); 149 return new Pubspec("pub itself", dependencies: dependencies);
150 } 150 }
151 151
152 /// Run the solver. 152 /// Run the solver.
(...skipping 14 matching lines...) Expand all
167 167
168 // Pre-cache the root package's known pubspec. 168 // Pre-cache the root package's known pubspec.
169 var rootID = new PackageId.root(root); 169 var rootID = new PackageId.root(root);
170 await _selection.select(rootID); 170 await _selection.select(rootID);
171 171
172 _validateSdkConstraint(root.pubspec); 172 _validateSdkConstraint(root.pubspec);
173 173
174 logSolve(); 174 logSolve();
175 var packages = await _solve(); 175 var packages = await _solve();
176 176
177 var pubspecs = {}; 177 var pubspecs = <String, Pubspec>{};
178 for (var id in packages) { 178 for (var id in packages) {
179 pubspecs[id.name] = await _getPubspec(id); 179 pubspecs[id.name] = await _getPubspec(id);
180 } 180 }
181 181
182 return new SolveResult.success(systemCache.sources, root, lockFile, 182 return new SolveResult.success(systemCache.sources, root, lockFile,
183 packages, overrides, pubspecs, _getAvailableVersions(packages), 183 packages, overrides, pubspecs, _getAvailableVersions(packages),
184 _attemptedSolutions); 184 _attemptedSolutions);
185 } on SolveFailure catch (error) { 185 } on SolveFailure catch (error) {
186 // Wrap a failure in a result so we can attach some other data. 186 // Wrap a failure in a result so we can attach some other data.
187 return new SolveResult.failure(systemCache.sources, root, lockFile, 187 return new SolveResult.failure(systemCache.sources, root, lockFile,
188 overrides, error, _attemptedSolutions); 188 overrides, error, _attemptedSolutions);
189 } finally { 189 } finally {
190 // Gather some solving metrics. 190 // Gather some solving metrics.
191 var buffer = new StringBuffer(); 191 var buffer = new StringBuffer();
192 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.'); 192 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.');
193 buffer.writeln('- Tried $_attemptedSolutions solutions'); 193 buffer.writeln('- Tried $_attemptedSolutions solutions');
194 buffer.writeln(cache.describeResults()); 194 buffer.writeln(cache.describeResults());
195 log.solver(buffer); 195 log.solver(buffer);
196 } 196 }
197 } 197 }
198 198
199 /// Generates a map containing all of the known available versions for each 199 /// Generates a map containing all of the known available versions for each
200 /// package in [packages]. 200 /// package in [packages].
201 /// 201 ///
202 /// The version list may not always be complete. If the package is the root 202 /// The version list may not always be complete. If the package is the root
203 /// root package, or if it's a package that we didn't unlock while solving 203 /// root package, or if it's a package that we didn't unlock while solving
204 /// because we weren't trying to upgrade it, we will just know the current 204 /// because we weren't trying to upgrade it, we will just know the current
205 /// version. 205 /// version.
206 Map<String, List<Version>> _getAvailableVersions(List<PackageId> packages) { 206 Map<String, List<Version>> _getAvailableVersions(List<PackageId> packages) {
207 var availableVersions = new Map<String, List<Version>>(); 207 var availableVersions = <String, List<Version>>{};
208 for (var package in packages) { 208 for (var package in packages) {
209 var cached = cache.getCachedVersions(package.toRef()); 209 var cached = cache.getCachedVersions(package.toRef());
210 var versions; 210 // If the version list was never requested, just use the one known
211 if (cached != null) { 211 // version.
212 versions = cached.map((id) => id.version).toList(); 212 var versions = cached == null
213 } else { 213 ? [package.version]
214 // If the version list was never requested, just use the one known 214 : cached.map((id) => id.version).toList();
215 // version.
216 versions = [package.version];
217 }
218 215
219 availableVersions[package.name] = versions; 216 availableVersions[package.name] = versions;
220 } 217 }
221 218
222 return availableVersions; 219 return availableVersions;
223 } 220 }
224 221
225 /// Gets the version of [package] currently locked in the lock file. 222 /// Gets the version of [package] currently locked in the lock file.
226 /// 223 ///
227 /// Returns `null` if it isn't in the lockfile (or has been unlocked). 224 /// Returns `null` if it isn't in the lockfile (or has been unlocked).
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 662
666 if (!pubspec.flutterSdkConstraint.allows(flutter.version)) { 663 if (!pubspec.flutterSdkConstraint.allows(flutter.version)) {
667 throw new BadSdkVersionException(pubspec.name, 664 throw new BadSdkVersionException(pubspec.name,
668 'Package ${pubspec.name} requires Flutter SDK version ' 665 'Package ${pubspec.name} requires Flutter SDK version '
669 '${pubspec.flutterSdkConstraint} but the current SDK is ' 666 '${pubspec.flutterSdkConstraint} but the current SDK is '
670 '${flutter.version}.'); 667 '${flutter.version}.');
671 } 668 }
672 } 669 }
673 } 670 }
674 } 671 }
OLDNEW
« no previous file with comments | « lib/src/pubspec.dart ('k') | lib/src/solver/solve_report.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698