OLD | NEW |
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 /// | 224 /// |
225 /// Returns `null` if it isn't in the lockfile (or has been unlocked). | 225 /// Returns `null` if it isn't in the lockfile (or has been unlocked). |
226 PackageId getLocked(String package) { | 226 PackageId getLocked(String package) { |
227 if (type == SolveType.GET) return lockFile.packages[package]; | 227 if (type == SolveType.GET) return lockFile.packages[package]; |
228 | 228 |
229 // When downgrading, we don't want to force the latest versions of | 229 // When downgrading, we don't want to force the latest versions of |
230 // non-hosted packages, since they don't support multiple versions and thus | 230 // non-hosted packages, since they don't support multiple versions and thus |
231 // can't be downgraded. | 231 // can't be downgraded. |
232 if (type == SolveType.DOWNGRADE) { | 232 if (type == SolveType.DOWNGRADE) { |
233 var locked = lockFile.packages[package]; | 233 var locked = lockFile.packages[package]; |
234 if (locked != null && | 234 if (locked != null && !locked.source.hasMultipleVersions) return locked; |
235 !systemCache.sources[locked.source].hasMultipleVersions) { | |
236 return locked; | |
237 } | |
238 } | 235 } |
239 | 236 |
240 if (_forceLatest.isEmpty || _forceLatest.contains(package)) return null; | 237 if (_forceLatest.isEmpty || _forceLatest.contains(package)) return null; |
241 return lockFile.packages[package]; | 238 return lockFile.packages[package]; |
242 } | 239 } |
243 | 240 |
244 /// Gets the package [name] that's currently contained in the lockfile if it | 241 /// Gets the package [name] that's currently contained in the lockfile if it |
245 /// matches the current constraint and has the same source and description as | 242 /// matches the current constraint and has the same source and description as |
246 /// other references to that package. | 243 /// other references to that package. |
247 /// | 244 /// |
248 /// Returns `null` otherwise. | 245 /// Returns `null` otherwise. |
249 PackageId _getValidLocked(String name) { | 246 PackageId _getValidLocked(String name) { |
250 var package = getLocked(name); | 247 var package = getLocked(name); |
251 if (package == null) return null; | 248 if (package == null) return null; |
252 | 249 |
253 var constraint = _selection.getConstraint(name); | 250 var constraint = _selection.getConstraint(name); |
254 if (!constraint.allows(package.version)) { | 251 if (!constraint.allows(package.version)) { |
255 logSolve('$package is locked but does not match $constraint'); | 252 logSolve('$package is locked but does not match $constraint'); |
256 return null; | 253 return null; |
257 } else { | 254 } else { |
258 logSolve('$package is locked'); | 255 logSolve('$package is locked'); |
259 } | 256 } |
260 | 257 |
261 var required = _selection.getRequiredDependency(name); | 258 var required = _selection.getRequiredDependency(name); |
262 if (required != null) { | 259 if (required != null && !package.samePackage(required.dep)) return null; |
263 if (package.source != required.dep.source) return null; | |
264 | |
265 var source = systemCache.sources[package.source]; | |
266 if (!source.descriptionsEqual( | |
267 package.description, required.dep.description)) return null; | |
268 } | |
269 | 260 |
270 return package; | 261 return package; |
271 } | 262 } |
272 | 263 |
273 /// Tries to find the best set of versions that meet the constraints. | 264 /// Tries to find the best set of versions that meet the constraints. |
274 /// | 265 /// |
275 /// Selects matching versions of unselected packages, or backtracks if there | 266 /// Selects matching versions of unselected packages, or backtracks if there |
276 /// are no such versions. | 267 /// are no such versions. |
277 Future<List<PackageId>> _solve() async { | 268 Future<List<PackageId>> _solve() async { |
278 // TODO(nweiz): Use real while loops when issue 23394 is fixed. | 269 // TODO(nweiz): Use real while loops when issue 23394 is fixed. |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 _fail(otherDep.depender.name); | 520 _fail(otherDep.depender.name); |
530 } | 521 } |
531 | 522 |
532 logSolve( | 523 logSolve( |
533 'inconsistent source "${dep.source}" for ${dep.name}:\n' | 524 'inconsistent source "${dep.source}" for ${dep.name}:\n' |
534 ' $dependency\n' + | 525 ' $dependency\n' + |
535 _selection.describeDependencies(dep.name)); | 526 _selection.describeDependencies(dep.name)); |
536 throw new SourceMismatchException(dep.name, allDeps); | 527 throw new SourceMismatchException(dep.name, allDeps); |
537 } | 528 } |
538 | 529 |
539 var source = systemCache.sources[dep.source]; | 530 if (!dep.samePackage(required.dep)) { |
540 if (!source.descriptionsEqual( | |
541 dep.description, required.dep.description)) { | |
542 // Mark the dependers as failing rather than the package itself, because | 531 // Mark the dependers as failing rather than the package itself, because |
543 // no version with this description will be compatible. | 532 // no version with this description will be compatible. |
544 for (var otherDep in _selection.getDependenciesOn(dep.name)) { | 533 for (var otherDep in _selection.getDependenciesOn(dep.name)) { |
545 _fail(otherDep.depender.name); | 534 _fail(otherDep.depender.name); |
546 } | 535 } |
547 | 536 |
548 logSolve( | 537 logSolve( |
549 'inconsistent description "${dep.description}" for ${dep.name}:\n' | 538 'inconsistent description "${dep.description}" for ${dep.name}:\n' |
550 ' $dependency\n' + | 539 ' $dependency\n' + |
551 _selection.describeDependencies(dep.name)); | 540 _selection.describeDependencies(dep.name)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // Not overridden. | 577 // Not overridden. |
589 return dep; | 578 return dep; |
590 }).toSet(); | 579 }).toSet(); |
591 } else { | 580 } else { |
592 // Ignore any overridden dependencies. | 581 // Ignore any overridden dependencies. |
593 deps.removeWhere((dep) => _overrides.containsKey(dep.name)); | 582 deps.removeWhere((dep) => _overrides.containsKey(dep.name)); |
594 } | 583 } |
595 | 584 |
596 // Make sure the package doesn't have any bad dependencies. | 585 // Make sure the package doesn't have any bad dependencies. |
597 for (var dep in deps.toSet()) { | 586 for (var dep in deps.toSet()) { |
598 if (!dep.isRoot && systemCache.sources[dep.source] is UnknownSource) { | 587 if (!dep.isRoot && dep.source is UnknownSource) { |
599 throw new UnknownSourceException(id.name, [new Dependency(id, dep)]); | 588 throw new UnknownSourceException(id.name, [new Dependency(id, dep)]); |
600 } | 589 } |
601 | 590 |
602 if (dep.name == 'barback') { | 591 if (dep.name == 'barback') { |
603 deps.add(new PackageDep.magic('pub itself')); | 592 deps.add(new PackageDep.magic('pub itself')); |
604 } | 593 } |
605 } | 594 } |
606 | 595 |
607 return deps; | 596 return deps; |
608 } | 597 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 void _validateSdkConstraint(Pubspec pubspec) { | 647 void _validateSdkConstraint(Pubspec pubspec) { |
659 if (_overrides.containsKey(pubspec.name)) return; | 648 if (_overrides.containsKey(pubspec.name)) return; |
660 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; | 649 if (pubspec.environment.sdkVersion.allows(sdk.version)) return; |
661 | 650 |
662 throw new BadSdkVersionException(pubspec.name, | 651 throw new BadSdkVersionException(pubspec.name, |
663 'Package ${pubspec.name} requires SDK version ' | 652 'Package ${pubspec.name} requires SDK version ' |
664 '${pubspec.environment.sdkVersion} but the current SDK is ' | 653 '${pubspec.environment.sdkVersion} but the current SDK is ' |
665 '${sdk.version}.'); | 654 '${sdk.version}.'); |
666 } | 655 } |
667 } | 656 } |
OLD | NEW |