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

Side by Side Diff: sdk/lib/_internal/pub_generated/lib/src/solver/backtracking_solver.dart

Issue 844263004: Properly update git binary snapshots during pub upgrade. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix tests Created 5 years, 11 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 | Annotate | Revision Log
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 for (var override in root.dependencyOverrides) { 120 for (var override in root.dependencyOverrides) {
121 _overrides[override.name] = override; 121 _overrides[override.name] = override;
122 } 122 }
123 } 123 }
124 124
125 /// Run the solver. 125 /// Run the solver.
126 /// 126 ///
127 /// Completes with a list of specific package versions if successful or an 127 /// Completes with a list of specific package versions if successful or an
128 /// error if it failed to find a solution. 128 /// error if it failed to find a solution.
129 Future<SolveResult> solve() { 129 Future<SolveResult> solve() {
130 var stopwatch = new Stopwatch(); 130 final completer0 = new Completer();
131 131 scheduleMicrotask(() {
132 _logParameters(); 132 try {
133 133 var stopwatch = new Stopwatch();
134 // Sort the overrides by package name to make sure they're deterministic. 134 _logParameters();
135 var overrides = _overrides.values.toList(); 135 var overrides = _overrides.values.toList();
136 overrides.sort((a, b) => a.name.compareTo(b.name)); 136 overrides.sort(((a, b) {
137 137 return a.name.compareTo(b.name);
138 return newFuture(() { 138 }));
139 stopwatch.start(); 139 join0() {
140 140 completer0.complete();
141 // Pre-cache the root package's known pubspec. 141 }
142 cache.cache(new PackageId.root(root), root.pubspec); 142 finally0(cont0) {
143 143 try {
144 _validateSdkConstraint(root.pubspec); 144 var buffer = new StringBuffer();
145 return _traverseSolution(); 145 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.');
146 }).then((packages) { 146 buffer.writeln(cache.describeResults());
147 var pubspecs = new Map.fromIterable( 147 log.solver(buffer);
148 packages, 148 cont0();
149 key: (id) => id.name, 149 } catch (e0, s0) {
150 value: (id) => cache.getCachedPubspec(id)); 150 completer0.completeError(e0, s0);
151 151 }
152 return new SolveResult.success( 152 }
153 sources, 153 catch0(error, s1) {
154 root, 154 try {
155 lockFile, 155 if (error is SolveFailure) {
156 packages, 156 final v0 = new SolveResult.failure(
157 overrides, 157 sources,
158 pubspecs, 158 root,
159 _getAvailableVersions(packages), 159 lockFile,
160 attemptedSolutions); 160 overrides,
161 }).catchError((error) { 161 error,
162 if (error is! SolveFailure) throw error; 162 attemptedSolutions);
163 163 finally0(() {
164 // Wrap a failure in a result so we can attach some other data. 164 completer0.complete(v0);
165 return new SolveResult.failure( 165 });
166 sources, 166 } else {
167 root, 167 throw error;
168 lockFile, 168 }
169 overrides, 169 } catch (error, s1) {
170 error, 170 finally0(() => completer0.completeError(error, s1));
171 attemptedSolutions); 171 }
172 }).whenComplete(() { 172 }
173 // Gather some solving metrics. 173 try {
174 var buffer = new StringBuffer(); 174 stopwatch.start();
175 buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.'); 175 cache.cache(new PackageId.root(root), root.pubspec);
176 buffer.writeln(cache.describeResults()); 176 _validateSdkConstraint(root.pubspec);
177 log.solver(buffer); 177 new Future.value(_traverseSolution()).then((x0) {
178 try {
179 var packages = x0;
180 var pubspecs = new Map.fromIterable(packages, key: ((id) {
181 return id.name;
182 }), value: ((id) {
183 return cache.getCachedPubspec(id);
184 }));
185 new Future.value(Future.wait(packages.map(((id) {
186 return sources[id.source].resolveId(id);
187 })))).then((x1) {
188 try {
189 packages = x1;
190 final v1 = new SolveResult.success(
191 sources,
192 root,
193 lockFile,
194 packages,
195 overrides,
196 pubspecs,
197 _getAvailableVersions(packages),
198 attemptedSolutions);
199 finally0(() {
200 completer0.complete(v1);
201 });
202 } catch (e1, s2) {
203 catch0(e1, s2);
204 }
205 }, onError: catch0);
206 } catch (e2, s3) {
207 catch0(e2, s3);
208 }
209 }, onError: catch0);
210 } catch (e3, s4) {
211 catch0(e3, s4);
212 }
213 } catch (e, s) {
214 completer0.completeError(e, s);
215 }
178 }); 216 });
217 return completer0.future;
179 } 218 }
180 219
181 /// Generates a map containing all of the known available versions for each 220 /// Generates a map containing all of the known available versions for each
182 /// package in [packages]. 221 /// package in [packages].
183 /// 222 ///
184 /// The version list may not always be complete. The the package is the root 223 /// The version list may not always be complete. The the package is the root
185 /// root package, or its a package that we didn't unlock while solving 224 /// root package, or its a package that we didn't unlock while solving
186 /// because we weren't trying to upgrade it, we will just know the current 225 /// because we weren't trying to upgrade it, we will just know the current
187 /// version. 226 /// version.
188 Map<String, List<Version>> _getAvailableVersions(List<PackageId> packages) { 227 Map<String, List<Version>> _getAvailableVersions(List<PackageId> packages) {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 /// 836 ///
798 /// Throws a [SolveFailure] if not. 837 /// Throws a [SolveFailure] if not.
799 void _validateSdkConstraint(Pubspec pubspec) { 838 void _validateSdkConstraint(Pubspec pubspec) {
800 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; 839 if (pubspec.environment.sdkVersion.allows(sdk.version)) return;
801 840
802 throw new BadSdkVersionException( 841 throw new BadSdkVersionException(
803 pubspec.name, 842 pubspec.name,
804 'Package ${pubspec.name} requires SDK version ' 843 'Package ${pubspec.name} requires SDK version '
805 '${pubspec.environment.sdkVersion} but the current SDK is ' '${sdk.ver sion}.'); 844 '${pubspec.environment.sdkVersion} but the current SDK is ' '${sdk.ver sion}.');
806 } 845 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698