| 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.map((id) { | 134 return Future.wait(packageVersions.map((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() { |
| 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 your SDK version " |
| 190 "${sdk.version}:\n" |
| 191 "${errors.join('\n')}\n\n" |
| 192 "You may be able to resolve this by upgrading to the latest Dart " |
| 193 "SDK\n" |
| 194 "or adding a version constraint to use an older version of a " |
| 195 "package."); |
| 196 } |
| 197 }); |
| 198 } |
| 199 |
| 142 /// Loads the list of concrete package versions from the `pubspec.lock`, if it | 200 /// 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]. | 201 /// exists. If it doesn't, this completes to an empty [LockFile]. |
| 144 Future<LockFile> loadLockFile() { | 202 Future<LockFile> loadLockFile() { |
| 145 var lockFilePath = join(root.dir, 'pubspec.lock'); | 203 var lockFilePath = join(root.dir, 'pubspec.lock'); |
| 146 | 204 |
| 147 log.fine("Loading lockfile."); | 205 log.fine("Loading lockfile."); |
| 148 return fileExists(lockFilePath).then((exists) { | 206 return fileExists(lockFilePath).then((exists) { |
| 149 if (!exists) { | 207 if (!exists) { |
| 150 log.fine("No lock file at $lockFilePath, creating empty one."); | 208 log.fine("No lock file at $lockFilePath, creating empty one."); |
| 151 return new LockFile.empty(); | 209 return new LockFile.empty(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 296 |
| 239 /// Creates a symlink to the `packages` directory in [dir] if none exists. | 297 /// Creates a symlink to the `packages` directory in [dir] if none exists. |
| 240 Future _linkSecondaryPackageDir(String dir) { | 298 Future _linkSecondaryPackageDir(String dir) { |
| 241 var to = join(dir, 'packages'); | 299 var to = join(dir, 'packages'); |
| 242 return exists(to).then((exists) { | 300 return exists(to).then((exists) { |
| 243 if (exists) return; | 301 if (exists) return; |
| 244 return createSymlink(path, to); | 302 return createSymlink(path, to); |
| 245 }); | 303 }); |
| 246 } | 304 } |
| 247 } | 305 } |
| OLD | NEW |