| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 }).chain((_) => id.resolved); | 96 }).chain((_) => id.resolved); |
| 97 | 97 |
| 98 _installs[id] = future; | 98 _installs[id] = future; |
| 99 | 99 |
| 100 return future; | 100 return future; |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * Installs all dependencies of the [root] package to its "packages" | 104 * Installs all dependencies of the [root] package to its "packages" |
| 105 * directory. Returns a [Future] that completes when all dependencies are | 105 * directory, respecting the [LockFile] if present. Returns a [Future] that |
| 106 * installed. | 106 * completes when all dependencies are installed. |
| 107 */ | 107 */ |
| 108 Future installDependencies() { | 108 Future installDependencies() { |
| 109 return _getResolvedDependencies().chain((packageVersions) { | 109 return _loadLockFile() |
| 110 return Futures.wait(packageVersions.map((id) { | 110 .chain((lockFile) => resolveVersions(cache.sources, root, lockFile)) |
| 111 if (id.source is RootSource) return new Future.immediate(id); | 111 .chain(_installDependencies); |
| 112 return install(id); | |
| 113 })); | |
| 114 }).chain(_saveLockFile); | |
| 115 } | 112 } |
| 116 | 113 |
| 117 /** | 114 /** |
| 118 * Gets a list of all the [PackageId]s that this entrypoint transitively | 115 * Installs the latest available versions of all dependencies of the [root] |
| 119 * depends on. The concrete versions of these ids are given by the | 116 * package to its "package" directory, writing a new [LockFile]. Returns a |
| 120 * [VersionSolver] and the `pubspec.lock` file, if it exists. | 117 * [Future] that completes when all dependencies are installed. |
| 121 */ | 118 */ |
| 122 Future<List<PackageId>> _getResolvedDependencies() { | 119 Future updateDependencies() { |
| 123 return _loadLockFile().chain((lockFile) => | 120 return resolveVersions(cache.sources, root, new LockFile.empty()). |
| 124 resolveVersions(cache.sources, root, lockFile)); | 121 chain(_installDependencies); |
| 125 } | 122 } |
| 126 | 123 |
| 127 /** | 124 /** |
| 125 * Installs all dependencies listed in [packageVersions] and writes a |
| 126 * [LockFile]. |
| 127 */ |
| 128 Future _installDependencies(List<PackageId> packageVersions) { |
| 129 return Futures.wait(packageVersions.map((id) { |
| 130 if (id.source is RootSource) return new Future.immediate(id); |
| 131 return install(id); |
| 132 })).chain(_saveLockFile); |
| 133 } |
| 134 |
| 135 /** |
| 128 * Loads the list of concrete package versions from the `pubspec.lock`, if it | 136 * Loads the list of concrete package versions from the `pubspec.lock`, if it |
| 129 * exists. If it doesn't, this completes to an empty [LockFile]. | 137 * exists. If it doesn't, this completes to an empty [LockFile]. |
| 130 * | 138 * |
| 131 * If there's an error reading the `pubspec.lock` file, this will print a | 139 * If there's an error reading the `pubspec.lock` file, this will print a |
| 132 * warning message and act as though the file doesn't exist. | 140 * warning message and act as though the file doesn't exist. |
| 133 */ | 141 */ |
| 134 Future<LockFile> _loadLockFile() { | 142 Future<LockFile> _loadLockFile() { |
| 135 var completer = new Completer<LockFile>(); | 143 var completer = new Completer<LockFile>(); |
| 136 var lockFilePath = join(root.dir, 'pubspec.lock'); | 144 var lockFilePath = join(root.dir, 'pubspec.lock'); |
| 137 var future = readTextFile(lockFilePath); | 145 var future = readTextFile(lockFilePath); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 159 */ | 167 */ |
| 160 Future _saveLockFile(List<PackageId> packageIds) { | 168 Future _saveLockFile(List<PackageId> packageIds) { |
| 161 var lockFile = new LockFile.empty(); | 169 var lockFile = new LockFile.empty(); |
| 162 for (var id in packageIds) { | 170 for (var id in packageIds) { |
| 163 if (id.source is! RootSource) lockFile.packages[id.name] = id; | 171 if (id.source is! RootSource) lockFile.packages[id.name] = id; |
| 164 } | 172 } |
| 165 | 173 |
| 166 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); | 174 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); |
| 167 } | 175 } |
| 168 } | 176 } |
| OLD | NEW |