| 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('io.dart'); | 7 #import('io.dart'); |
| 8 #import('lock_file.dart'); | 8 #import('lock_file.dart'); |
| 9 #import('package.dart'); | 9 #import('package.dart'); |
| 10 #import('root_source.dart'); | 10 #import('root_source.dart'); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return _loadLockFile().chain((lockFile) { | 130 return _loadLockFile().chain((lockFile) { |
| 131 var versionSolver = new VersionSolver(cache.sources, root, lockFile); | 131 var versionSolver = new VersionSolver(cache.sources, root, lockFile); |
| 132 for (var dependency in dependencies) { | 132 for (var dependency in dependencies) { |
| 133 versionSolver.useLatestVersion(dependency); | 133 versionSolver.useLatestVersion(dependency); |
| 134 } | 134 } |
| 135 return versionSolver.solve(); | 135 return versionSolver.solve(); |
| 136 }).chain(_installDependencies); | 136 }).chain(_installDependencies); |
| 137 } | 137 } |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * Installs all dependencies listed in [packageVersions] and writes a | 140 * Removes the old packages directory, installs all dependencies listed in |
| 141 * [LockFile]. | 141 * [packageVersions], and writes a [LockFile]. |
| 142 */ | 142 */ |
| 143 Future _installDependencies(List<PackageId> packageVersions) { | 143 Future _installDependencies(List<PackageId> packageVersions) { |
| 144 return _removeUnusedDependencies(packageVersions).chain((_) { | 144 return cleanDir(path).chain((_) { |
| 145 return Futures.wait(packageVersions.map((id) { | 145 return Futures.wait(packageVersions.map((id) { |
| 146 if (id.source is RootSource) return new Future.immediate(id); | 146 if (id.source is RootSource) return new Future.immediate(id); |
| 147 return install(id); | 147 return install(id); |
| 148 })); | 148 })); |
| 149 }).chain(_saveLockFile) | 149 }).chain(_saveLockFile) |
| 150 .chain(_installSelfReference) | 150 .chain(_installSelfReference) |
| 151 .chain(_linkSecondaryPackageDirs); | 151 .chain(_linkSecondaryPackageDirs); |
| 152 } | 152 } |
| 153 | 153 |
| 154 /** | 154 /** |
| (...skipping 20 matching lines...) Expand all Loading... |
| 175 | 175 |
| 176 return true; | 176 return true; |
| 177 }); | 177 }); |
| 178 | 178 |
| 179 future.then((text) => | 179 future.then((text) => |
| 180 completer.complete(new LockFile.parse(text, cache.sources))); | 180 completer.complete(new LockFile.parse(text, cache.sources))); |
| 181 return completer.future; | 181 return completer.future; |
| 182 } | 182 } |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * Removes all dependencies that are no longer depended on from the `packages` | |
| 186 * directory. [packageIds] is a list of all packages that are still depended | |
| 187 * on. | |
| 188 */ | |
| 189 Future _removeUnusedDependencies(List<PackageId> packageIds) { | |
| 190 var dependenciesToKeep = packageIds.map((id) => id.name); | |
| 191 | |
| 192 return dirExists(path).chain((exists) { | |
| 193 if (exists) return listDir(path); | |
| 194 return new Future.immediate([]); | |
| 195 }).chain((existingDependencies) { | |
| 196 existingDependencies = existingDependencies.map(basename); | |
| 197 var dependenciesToRemove = | |
| 198 new List.from(setMinus(existingDependencies, dependenciesToKeep)); | |
| 199 return Futures.wait(dependenciesToRemove.map((dependency) { | |
| 200 return deleteDir(join(path, dependency)); | |
| 201 })); | |
| 202 }); | |
| 203 } | |
| 204 | |
| 205 /** | |
| 206 * Saves a list of concrete package versions to the `pubspec.lock` file. | 185 * Saves a list of concrete package versions to the `pubspec.lock` file. |
| 207 */ | 186 */ |
| 208 Future _saveLockFile(List<PackageId> packageIds) { | 187 Future _saveLockFile(List<PackageId> packageIds) { |
| 209 var lockFile = new LockFile.empty(); | 188 var lockFile = new LockFile.empty(); |
| 210 for (var id in packageIds) { | 189 for (var id in packageIds) { |
| 211 if (id.source is! RootSource) lockFile.packages[id.name] = id; | 190 if (id.source is! RootSource) lockFile.packages[id.name] = id; |
| 212 } | 191 } |
| 213 | 192 |
| 214 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); | 193 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); |
| 215 } | 194 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 * Creates a symlink to the `packages` directory in [dir] if none exists. | 269 * Creates a symlink to the `packages` directory in [dir] if none exists. |
| 291 */ | 270 */ |
| 292 Future _linkSecondaryPackageDir(String dir) { | 271 Future _linkSecondaryPackageDir(String dir) { |
| 293 var to = join(dir, 'packages'); | 272 var to = join(dir, 'packages'); |
| 294 return exists(to).chain((exists) { | 273 return exists(to).chain((exists) { |
| 295 if (exists) return new Future.immediate(null); | 274 if (exists) return new Future.immediate(null); |
| 296 return createSymlink(path, to); | 275 return createSymlink(path, to); |
| 297 }); | 276 }); |
| 298 } | 277 } |
| 299 } | 278 } |
| OLD | NEW |