Chromium Code Reviews| 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 library entrypoint; | 5 library entrypoint; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'io.dart'; | 8 import 'io.dart'; |
| 9 import 'lock_file.dart'; | 9 import 'lock_file.dart'; |
| 10 import 'log.dart' as log; | 10 import 'log.dart' as log; |
| 11 import 'package.dart'; | 11 import 'package.dart'; |
| 12 import 'sdk.dart' as sdk; | |
| 12 import 'system_cache.dart'; | 13 import 'system_cache.dart'; |
| 13 import 'utils.dart'; | 14 import 'utils.dart'; |
| 14 import 'version.dart'; | 15 import 'version.dart'; |
| 15 import 'version_solver.dart'; | 16 import 'version_solver.dart'; |
| 16 | 17 |
| 17 /// Pub operates over a directed graph of dependencies that starts at a root | 18 /// Pub operates over a directed graph of dependencies that starts at a root |
| 18 /// "entrypoint" package. This is typically the package where the current | 19 /// "entrypoint" package. This is typically the package where the current |
| 19 /// working directory is located. An entrypoint knows the [root] package it is | 20 /// working directory is located. An entrypoint knows the [root] package it is |
| 20 /// associated with and is responsible for managing the "packages" directory | 21 /// associated with and is responsible for managing the "packages" directory |
| 21 /// for it. | 22 /// for it. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 return cleanDir(path).then((_) { | 133 return cleanDir(path).then((_) { |
| 133 return Future.wait(packageVersions.mappedBy((id) { | 134 return Future.wait(packageVersions.mappedBy((id) { |
| 134 if (id.isRoot) return new Future.immediate(id); | 135 if (id.isRoot) return new Future.immediate(id); |
| 135 return install(id); | 136 return install(id); |
| 136 })); | 137 })); |
| 137 }).then(_saveLockFile) | 138 }).then(_saveLockFile) |
| 138 .then(_installSelfReference) | 139 .then(_installSelfReference) |
| 139 .then(_linkSecondaryPackageDirs); | 140 .then(_linkSecondaryPackageDirs); |
| 140 } | 141 } |
| 141 | 142 |
| 143 /// Traverses the root's package dependency graph and loads each of the | |
| 144 /// reached packages. This should only be called after the lockfile has been | |
| 145 /// successfully generated. | |
| 146 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
| |
| 147 return loadLockFile().then((lockFile) { | |
| 148 var group = new FutureGroup<Package>(); | |
| 149 var visited = new Set<String>(); | |
| 150 | |
| 151 // Include the root package in the results. | |
| 152 group.add(new Future.immediate(root)); | |
| 153 | |
| 154 visitPackage(Package package) { | |
| 155 for (var ref in package.dependencies) { | |
| 156 if (visited.contains(ref.name)) continue; | |
| 157 | |
| 158 // Look up the concrete version. | |
| 159 var id = lockFile.packages[ref.name]; | |
| 160 | |
| 161 visited.add(ref.name); | |
| 162 var future = cache.describe(id); | |
| 163 group.add(future.then(visitPackage)); | |
| 164 } | |
| 165 | |
| 166 return package; | |
| 167 } | |
| 168 | |
| 169 visitPackage(root); | |
| 170 return group.future; | |
| 171 }); | |
| 172 } | |
| 173 | |
| 174 /// Validates that the current Dart SDK version matches the SDK constraints | |
| 175 /// of every package in the dependency graph. If a package's constraint does | |
| 176 /// not match, prints an error. | |
| 177 Future validateSdkConstraints() { | |
| 178 return walkDependencies().then((packages) { | |
| 179 var errors = []; | |
| 180 | |
| 181 for (var package in packages) { | |
| 182 var sdkConstraint = package.pubspec.environment.sdkVersion; | |
| 183 if (!sdkConstraint.allows(sdk.version)) { | |
| 184 errors.add("- '${package.name}' requires ${sdkConstraint}"); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 if (errors.length > 0) { | |
| 189 log.error("Some packages are not compatible with SDK version " | |
| 190 "${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.
| |
| 191 "You may be able to resolve this by upgrading to the latest Dart " | |
| 192 "SDK\n" | |
| 193 "or adding a version constraint to use an older version of a " | |
| 194 "package."); | |
| 195 } | |
| 196 }); | |
| 197 } | |
| 198 | |
| 142 /// Loads the list of concrete package versions from the `pubspec.lock`, if it | 199 /// Loads the list of concrete package versions from the `pubspec.lock`, if it |
| 143 /// exists. If it doesn't, this completes to an empty [LockFile]. | 200 /// exists. If it doesn't, this completes to an empty [LockFile]. |
| 144 Future<LockFile> loadLockFile() { | 201 Future<LockFile> loadLockFile() { |
| 145 var lockFilePath = join(root.dir, 'pubspec.lock'); | 202 var lockFilePath = join(root.dir, 'pubspec.lock'); |
| 146 | 203 |
| 147 log.fine("Loading lockfile."); | 204 log.fine("Loading lockfile."); |
| 148 return fileExists(lockFilePath).then((exists) { | 205 return fileExists(lockFilePath).then((exists) { |
| 149 if (!exists) { | 206 if (!exists) { |
| 150 log.fine("No lock file at $lockFilePath, creating empty one."); | 207 log.fine("No lock file at $lockFilePath, creating empty one."); |
| 151 return new LockFile.empty(); | 208 return new LockFile.empty(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 | 295 |
| 239 /// Creates a symlink to the `packages` directory in [dir] if none exists. | 296 /// Creates a symlink to the `packages` directory in [dir] if none exists. |
| 240 Future _linkSecondaryPackageDir(String dir) { | 297 Future _linkSecondaryPackageDir(String dir) { |
| 241 var to = join(dir, 'packages'); | 298 var to = join(dir, 'packages'); |
| 242 return exists(to).then((exists) { | 299 return exists(to).then((exists) { |
| 243 if (exists) return; | 300 if (exists) return; |
| 244 return createSymlink(path, to); | 301 return createSymlink(path, to); |
| 245 }); | 302 }); |
| 246 } | 303 } |
| 247 } | 304 } |
| OLD | NEW |