| 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 /// Attempts to resolve a set of version constraints for a package dependency | 5 /// Attempts to resolve a set of version constraints for a package dependency |
| 6 /// graph and select an appropriate set of best specific versions for all | 6 /// graph and select an appropriate set of best specific versions for all |
| 7 /// dependent packages. It works iteratively and tries to reach a stable | 7 /// dependent packages. It works iteratively and tries to reach a stable |
| 8 /// solution where the constraints of all dependencies are met. If it fails to | 8 /// solution where the constraints of all dependencies are met. If it fails to |
| 9 /// reach a solution after a certain number of iterations, it assumes the | 9 /// reach a solution after a certain number of iterations, it assumes the |
| 10 /// dependency graph is unstable and reports and error. | 10 /// dependency graph is unstable and reports and error. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 /// first, followed by transitive dependers. | 176 /// first, followed by transitive dependers. |
| 177 bool tryUnlockDepender(Dependency dependency, [Set<String> seen]) { | 177 bool tryUnlockDepender(Dependency dependency, [Set<String> seen]) { |
| 178 if (seen == null) seen = new Set(); | 178 if (seen == null) seen = new Set(); |
| 179 // Avoid an infinite loop if there are circular dependencies. | 179 // Avoid an infinite loop if there are circular dependencies. |
| 180 if (seen.contains(dependency.name)) return false; | 180 if (seen.contains(dependency.name)) return false; |
| 181 seen.add(dependency.name); | 181 seen.add(dependency.name); |
| 182 | 182 |
| 183 for (var dependerName in dependency.dependers) { | 183 for (var dependerName in dependency.dependers) { |
| 184 var depender = getDependency(dependerName); | 184 var depender = getDependency(dependerName); |
| 185 var locked = lockFile.packages[dependerName]; | 185 var locked = lockFile.packages[dependerName]; |
| 186 if (locked != null && depender.version == locked.version) { | 186 if (locked != null && depender.version == locked.version && |
| 187 lockedPackage.source.name == dep.source.name) { |
| 187 enqueue(new UnlockPackage(depender)); | 188 enqueue(new UnlockPackage(depender)); |
| 188 return true; | 189 return true; |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 return dependency.dependers.map(getDependency).any((subdependency) => | 193 return dependency.dependers.map(getDependency).any((subdependency) => |
| 193 tryUnlockDepender(subdependency, seen)); | 194 tryUnlockDepender(subdependency, seen)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 List<PackageId> buildResults() { | 197 List<PackageId> buildResults() { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // anything since it's already at the best version. | 354 // anything since it's already at the best version. |
| 354 if (name == solver._root.name) { | 355 if (name == solver._root.name) { |
| 355 solver.enqueue(new ChangeVersion( | 356 solver.enqueue(new ChangeVersion( |
| 356 name, source, description, solver._root.version)); | 357 name, source, description, solver._root.version)); |
| 357 return null; | 358 return null; |
| 358 } | 359 } |
| 359 | 360 |
| 360 // If the dependency is on a package in the lockfile, use the lockfile's | 361 // If the dependency is on a package in the lockfile, use the lockfile's |
| 361 // version for that package if it's valid given the other constraints. | 362 // version for that package if it's valid given the other constraints. |
| 362 var lockedPackage = solver.lockFile.packages[name]; | 363 var lockedPackage = solver.lockFile.packages[name]; |
| 363 if (lockedPackage != null) { | 364 if (lockedPackage != null && newDependency.source == lockedPackage.source) { |
| 364 var lockedVersion = lockedPackage.version; | 365 var lockedVersion = lockedPackage.version; |
| 365 if (newConstraint.allows(lockedVersion)) { | 366 if (newConstraint.allows(lockedVersion)) { |
| 366 solver.enqueue( | 367 solver.enqueue( |
| 367 new ChangeVersion(name, source, description, lockedVersion)); | 368 new ChangeVersion(name, source, description, lockedVersion)); |
| 368 return null; | 369 return null; |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 | 372 |
| 372 // The constraint has changed, so see what the best version of the package | 373 // The constraint has changed, so see what the best version of the package |
| 373 // that meets the new constraint is. | 374 // that meets the new constraint is. |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 706 |
| 706 String toString() { | 707 String toString() { |
| 707 // TODO(nweiz): Dump descriptions to YAML when that's supported. | 708 // TODO(nweiz): Dump descriptions to YAML when that's supported. |
| 708 return "Incompatible dependencies on '$package':\n" | 709 return "Incompatible dependencies on '$package':\n" |
| 709 "- '$depender1' depends on it with description " | 710 "- '$depender1' depends on it with description " |
| 710 "${json.stringify(description1)}\n" | 711 "${json.stringify(description1)}\n" |
| 711 "- '$depender2' depends on it with description " | 712 "- '$depender2' depends on it with description " |
| 712 "${json.stringify(description2)}"; | 713 "${json.stringify(description2)}"; |
| 713 } | 714 } |
| 714 } | 715 } |
| OLD | NEW |