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

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

Issue 1528523003: Clean up the semantics of package descriptions. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 5 years 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/version_solver.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 29 matching lines...) Expand all
40 import 'package:pub_semver/pub_semver.dart'; 40 import 'package:pub_semver/pub_semver.dart';
41 41
42 import '../barback.dart' as barback; 42 import '../barback.dart' as barback;
43 import '../exceptions.dart'; 43 import '../exceptions.dart';
44 import '../lock_file.dart'; 44 import '../lock_file.dart';
45 import '../log.dart' as log; 45 import '../log.dart' as log;
46 import '../package.dart'; 46 import '../package.dart';
47 import '../pubspec.dart'; 47 import '../pubspec.dart';
48 import '../sdk.dart' as sdk; 48 import '../sdk.dart' as sdk;
49 import '../source_registry.dart'; 49 import '../source_registry.dart';
50 import '../source/hosted.dart';
50 import '../source/unknown.dart'; 51 import '../source/unknown.dart';
51 import '../utils.dart'; 52 import '../utils.dart';
52 import 'version_queue.dart'; 53 import 'version_queue.dart';
53 import 'version_selection.dart'; 54 import 'version_selection.dart';
54 import 'version_solver.dart'; 55 import 'version_solver.dart';
55 56
56 /// The top-level solver. 57 /// The top-level solver.
57 /// 58 ///
58 /// Keeps track of the current potential solution, and the other possible 59 /// Keeps track of the current potential solution, and the other possible
59 /// versions for speculative package selections. Backtracks and advances to the 60 /// versions for speculative package selections. Backtracks and advances to the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 /// not. 116 /// not.
116 VersionSelection _selection; 117 VersionSelection _selection;
117 118
118 /// The number of solutions the solver has tried so far. 119 /// The number of solutions the solver has tried so far.
119 var _attemptedSolutions = 1; 120 var _attemptedSolutions = 1;
120 121
121 /// A pubspec for pub's implicit dependencies on barback and related packages. 122 /// A pubspec for pub's implicit dependencies on barback and related packages.
122 final Pubspec _implicitPubspec = () { 123 final Pubspec _implicitPubspec = () {
123 var dependencies = []; 124 var dependencies = [];
124 barback.pubConstraints.forEach((name, constraint) { 125 barback.pubConstraints.forEach((name, constraint) {
125 dependencies.add(new PackageDep(name, "hosted", constraint, name)); 126 dependencies.add(HostedSource.refFor(name).withConstraint(constraint));
126 }); 127 });
127 128
128 return new Pubspec("pub itself", dependencies: dependencies); 129 return new Pubspec("pub itself", dependencies: dependencies);
129 }(); 130 }();
130 131
131 BacktrackingSolver(SolveType type, SourceRegistry sources, this.root, 132 BacktrackingSolver(SolveType type, SourceRegistry sources, this.root,
132 this.lockFile, List<String> useLatest) 133 this.lockFile, List<String> useLatest)
133 : type = type, 134 : type = type,
134 sources = sources, 135 sources = sources,
135 cache = new SolverCache(type, sources) { 136 cache = new SolverCache(type, sources) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 _validateSdkConstraint(root.pubspec); 168 _validateSdkConstraint(root.pubspec);
168 169
169 logSolve(); 170 logSolve();
170 var packages = await _solve(); 171 var packages = await _solve();
171 172
172 var pubspecs = {}; 173 var pubspecs = {};
173 for (var id in packages) { 174 for (var id in packages) {
174 pubspecs[id.name] = await _getPubspec(id); 175 pubspecs[id.name] = await _getPubspec(id);
175 } 176 }
176 177
177 var resolved = await Future.wait( 178 return new SolveResult.success(sources, root, lockFile, packages,
178 packages.map((id) => sources[id.source].resolveId(id))); 179 overrides, pubspecs, _getAvailableVersions(packages),
179
180 return new SolveResult.success(sources, root, lockFile, resolved,
181 overrides, pubspecs, _getAvailableVersions(resolved),
182 _attemptedSolutions); 180 _attemptedSolutions);
183 } on SolveFailure catch (error) { 181 } on SolveFailure catch (error) {
184 // Wrap a failure in a result so we can attach some other data. 182 // Wrap a failure in a result so we can attach some other data.
185 return new SolveResult.failure(sources, root, lockFile, overrides, 183 return new SolveResult.failure(sources, root, lockFile, overrides,
186 error, _attemptedSolutions); 184 error, _attemptedSolutions);
187 } finally { 185 } finally {
188 // Gather some solving metrics. 186 // Gather some solving metrics.
189 var buffer = new StringBuffer(); 187 var buffer = new StringBuffer();
190 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.'); 188 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.');
191 buffer.writeln(cache.describeResults()); 189 buffer.writeln(cache.describeResults());
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 void _validateSdkConstraint(Pubspec pubspec) { 656 void _validateSdkConstraint(Pubspec pubspec) {
659 if (_overrides.containsKey(pubspec.name)) return; 657 if (_overrides.containsKey(pubspec.name)) return;
660 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; 658 if (pubspec.environment.sdkVersion.allows(sdk.version)) return;
661 659
662 throw new BadSdkVersionException(pubspec.name, 660 throw new BadSdkVersionException(pubspec.name,
663 'Package ${pubspec.name} requires SDK version ' 661 'Package ${pubspec.name} requires SDK version '
664 '${pubspec.environment.sdkVersion} but the current SDK is ' 662 '${pubspec.environment.sdkVersion} but the current SDK is '
665 '${sdk.version}.'); 663 '${sdk.version}.');
666 } 664 }
667 } 665 }
OLDNEW
« no previous file with comments | « lib/src/pubspec.dart ('k') | lib/src/solver/version_solver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698