Index: utils/pub/entrypoint.dart |
diff --git a/utils/pub/entrypoint.dart b/utils/pub/entrypoint.dart |
index 30bfeb1650a37f6af89274ae9180f255b30578eb..9a68c12e7bf7f299aed2d3fd46bf5be066bc836c 100644 |
--- a/utils/pub/entrypoint.dart |
+++ b/utils/pub/entrypoint.dart |
@@ -9,6 +9,7 @@ import 'io.dart'; |
import 'lock_file.dart'; |
import 'log.dart' as log; |
import 'package.dart'; |
+import 'sdk.dart' as sdk; |
import 'system_cache.dart'; |
import 'utils.dart'; |
import 'version.dart'; |
@@ -139,6 +140,62 @@ class Entrypoint { |
.then(_linkSecondaryPackageDirs); |
} |
+ /// Traverses the root's package dependency graph and loads each of the |
+ /// reached packages. This should only be called after the lockfile has been |
+ /// successfully generated. |
+ Future<List<Package>> walkDependencies() { |
nweiz
2013/01/31 22:38:53
Maybe this and validateSdkConstraints should be me
Bob Nystrom
2013/02/01 16:53:29
I put it here because walking the locked transitiv
nweiz
2013/02/01 22:24:54
I'd like to at least get an exception if this is c
Bob Nystrom
2013/02/02 00:02:31
It should fail if called with an out of date lockf
|
+ return loadLockFile().then((lockFile) { |
+ var group = new FutureGroup<Package>(); |
+ var visited = new Set<String>(); |
+ |
+ // Include the root package in the results. |
+ group.add(new Future.immediate(root)); |
+ |
+ visitPackage(Package package) { |
+ for (var ref in package.dependencies) { |
+ if (visited.contains(ref.name)) continue; |
+ |
+ // Look up the concrete version. |
+ var id = lockFile.packages[ref.name]; |
+ |
+ visited.add(ref.name); |
+ var future = cache.describe(id); |
+ group.add(future.then(visitPackage)); |
+ } |
+ |
+ return package; |
+ } |
+ |
+ visitPackage(root); |
+ return group.future; |
+ }); |
+ } |
+ |
+ /// Validates that the current Dart SDK version matches the SDK constraints |
+ /// of every package in the dependency graph. If a package's constraint does |
+ /// not match, prints an error. |
+ Future validateSdkConstraints() { |
+ return walkDependencies().then((packages) { |
+ var errors = []; |
+ |
+ for (var package in packages) { |
+ var sdkConstraint = package.pubspec.environment.sdkVersion; |
+ if (!sdkConstraint.allows(sdk.version)) { |
+ errors.add("- '${package.name}' requires ${sdkConstraint}"); |
+ } |
+ } |
+ |
+ if (errors.length > 0) { |
+ log.error("Some packages are not compatible with SDK version " |
+ "${sdk.version}:\n${errors.join('\n')}\n\n" |
nweiz
2013/01/31 22:38:53
When I'm formatting multiline strings like this, I
Bob Nystrom
2013/02/01 16:53:29
Done and done.
|
+ "You may be able to resolve this by upgrading to the latest Dart " |
+ "SDK\n" |
+ "or adding a version constraint to use an older version of a " |
+ "package."); |
+ } |
+ }); |
+ } |
+ |
/// Loads the list of concrete package versions from the `pubspec.lock`, if it |
/// exists. If it doesn't, this completes to an empty [LockFile]. |
Future<LockFile> loadLockFile() { |