| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 * package to its "package" directory, writing a new [LockFile]. Returns a | 116 * package to its "package" directory, writing a new [LockFile]. Returns a |
| 117 * [Future] that completes when all dependencies are installed. | 117 * [Future] that completes when all dependencies are installed. |
| 118 */ | 118 */ |
| 119 Future updateAllDependencies() { | 119 Future updateAllDependencies() { |
| 120 return resolveVersions(cache.sources, root, new LockFile.empty()). | 120 return resolveVersions(cache.sources, root, new LockFile.empty()). |
| 121 chain(_installDependencies); | 121 chain(_installDependencies); |
| 122 } | 122 } |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * Installs the latest available versions of [dependencies], while leaving | 125 * Installs the latest available versions of [dependencies], while leaving |
| 126 * other dependencies as specified by the [LockFile]. Returns a [Future] that | 126 * other dependencies as specified by the [LockFile] if possible. Returns a |
| 127 * completes when all dependencies are installed. | 127 * [Future] that completes when all dependencies are installed. |
| 128 */ | 128 */ |
| 129 Future updateDependencies(List<String> dependencies) { | 129 Future updateDependencies(List<String> dependencies) { |
| 130 return _loadLockFile().chain((lockFile) { | 130 return _loadLockFile().chain((lockFile) { |
| 131 var versionSolver = new VersionSolver(cache.sources, root, lockFile); |
| 131 for (var dependency in dependencies) { | 132 for (var dependency in dependencies) { |
| 132 // TODO(nweiz): How do we want to detect and handle unknown | 133 versionSolver.useBestVersion(dependency); |
| 133 // dependencies here? | |
| 134 lockFile.packages.remove(dependency); | |
| 135 } | 134 } |
| 136 return resolveVersions(cache.sources, root, lockFile); | 135 return versionSolver.solve(); |
| 137 }).chain(_installDependencies); | 136 }).chain(_installDependencies); |
| 138 } | 137 } |
| 139 | 138 |
| 140 /** | 139 /** |
| 141 * Installs all dependencies listed in [packageVersions] and writes a | 140 * Installs all dependencies listed in [packageVersions] and writes a |
| 142 * [LockFile]. | 141 * [LockFile]. |
| 143 */ | 142 */ |
| 144 Future _installDependencies(List<PackageId> packageVersions) { | 143 Future _installDependencies(List<PackageId> packageVersions) { |
| 145 return Futures.wait(packageVersions.map((id) { | 144 return Futures.wait(packageVersions.map((id) { |
| 146 if (id.source is RootSource) return new Future.immediate(id); | 145 if (id.source is RootSource) return new Future.immediate(id); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 */ | 182 */ |
| 184 Future _saveLockFile(List<PackageId> packageIds) { | 183 Future _saveLockFile(List<PackageId> packageIds) { |
| 185 var lockFile = new LockFile.empty(); | 184 var lockFile = new LockFile.empty(); |
| 186 for (var id in packageIds) { | 185 for (var id in packageIds) { |
| 187 if (id.source is! RootSource) lockFile.packages[id.name] = id; | 186 if (id.source is! RootSource) lockFile.packages[id.name] = id; |
| 188 } | 187 } |
| 189 | 188 |
| 190 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); | 189 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); |
| 191 } | 190 } |
| 192 } | 191 } |
| OLD | NEW |