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 | 8 |
9 import 'package:pathos/path.dart' as path; | 9 import 'package:pathos/path.dart' as path; |
10 | 10 |
11 import 'io.dart'; | 11 import 'io.dart'; |
12 import 'lock_file.dart'; | 12 import 'lock_file.dart'; |
13 import 'log.dart' as log; | 13 import 'log.dart' as log; |
14 import 'package.dart'; | 14 import 'package.dart'; |
15 import 'pubspec.dart'; | 15 import 'pubspec.dart'; |
16 import 'sdk.dart' as sdk; | 16 import 'sdk.dart' as sdk; |
17 import 'system_cache.dart'; | 17 import 'system_cache.dart'; |
18 import 'utils.dart'; | 18 import 'utils.dart'; |
19 import 'version.dart'; | 19 import 'version.dart'; |
20 import 'version_solver.dart'; | 20 import 'solver/version_solver.dart'; |
21 | 21 |
22 /// Pub operates over a directed graph of dependencies that starts at a root | 22 /// Pub operates over a directed graph of dependencies that starts at a root |
23 /// "entrypoint" package. This is typically the package where the current | 23 /// "entrypoint" package. This is typically the package where the current |
24 /// working directory is located. An entrypoint knows the [root] package it is | 24 /// working directory is located. An entrypoint knows the [root] package it is |
25 /// associated with and is responsible for managing the "packages" directory | 25 /// associated with and is responsible for managing the "packages" directory |
26 /// for it. | 26 /// for it. |
27 /// | 27 /// |
28 /// That directory contains symlinks to all packages used by an app. These links | 28 /// That directory contains symlinks to all packages used by an app. These links |
29 /// point either to the [SystemCache] or to some other location on the local | 29 /// point either to the [SystemCache] or to some other location on the local |
30 /// filesystem. | 30 /// filesystem. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 _installs[id] = future; | 96 _installs[id] = future; |
97 | 97 |
98 return future; | 98 return future; |
99 } | 99 } |
100 | 100 |
101 /// Installs all dependencies of the [root] package to its "packages" | 101 /// Installs all dependencies of the [root] package to its "packages" |
102 /// directory, respecting the [LockFile] if present. Returns a [Future] that | 102 /// directory, respecting the [LockFile] if present. Returns a [Future] that |
103 /// completes when all dependencies are installed. | 103 /// completes when all dependencies are installed. |
104 Future installDependencies() { | 104 Future installDependencies() { |
105 return new Future.of(() { | 105 return new Future.of(() { |
106 return resolveVersions(cache.sources, root, loadLockFile()); | 106 return resolveVersions(cache.sources, root, lockFile: loadLockFile()); |
107 }).then(_installDependencies); | 107 }).then(_installDependencies); |
108 } | 108 } |
109 | 109 |
110 /// Installs the latest available versions of all dependencies of the [root] | 110 /// Installs the latest available versions of all dependencies of the [root] |
111 /// package to its "package" directory, writing a new [LockFile]. Returns a | 111 /// package to its "package" directory, writing a new [LockFile]. Returns a |
112 /// [Future] that completes when all dependencies are installed. | 112 /// [Future] that completes when all dependencies are installed. |
113 Future updateAllDependencies() { | 113 Future updateAllDependencies() { |
114 return resolveVersions(cache.sources, root, new LockFile.empty()) | 114 return resolveVersions(cache.sources, root).then(_installDependencies); |
115 .then(_installDependencies); | |
116 } | 115 } |
117 | 116 |
118 /// Installs the latest available versions of [dependencies], while leaving | 117 /// Installs the latest available versions of [dependencies], while leaving |
119 /// other dependencies as specified by the [LockFile] if possible. Returns a | 118 /// other dependencies as specified by the [LockFile] if possible. Returns a |
120 /// [Future] that completes when all dependencies are installed. | 119 /// [Future] that completes when all dependencies are installed. |
121 Future updateDependencies(List<String> dependencies) { | 120 Future updateDependencies(List<String> dependencies) { |
122 return new Future.of(() { | 121 return new Future.of(() { |
123 var solver = new VersionSolver(cache.sources, root, loadLockFile()); | 122 return resolveVersions(cache.sources, root, |
124 for (var dependency in dependencies) { | 123 lockFile: loadLockFile(), useLatest: dependencies); |
125 solver.useLatestVersion(dependency); | |
126 } | |
127 return solver.solve(); | |
128 }).then(_installDependencies); | 124 }).then(_installDependencies); |
129 } | 125 } |
130 | 126 |
131 /// Removes the old packages directory, installs all dependencies listed in | 127 /// Removes the old packages directory, installs all dependencies listed in |
132 /// [packageVersions], and writes a [LockFile]. | 128 /// [solution], and writes a [LockFile]. |
133 Future _installDependencies(List<PackageId> packageVersions) { | 129 Future _installDependencies(SolveResult solution) { |
134 return new Future.of(() { | 130 return new Future.of(() { |
135 cleanDir(packagesDir); | 131 cleanDir(packagesDir); |
136 return Future.wait(packageVersions.map((id) { | 132 return Future.wait(solution.packages.map((id) { |
137 if (id.isRoot) return new Future.immediate(id); | 133 if (id.isRoot) return new Future.immediate(id); |
138 return install(id); | 134 return install(id); |
139 }).toList()); | 135 }).toList()); |
140 }).then((ids) { | 136 }).then((ids) { |
141 _saveLockFile(ids); | 137 _saveLockFile(ids); |
142 _installSelfReference(); | 138 _installSelfReference(); |
143 _linkSecondaryPackageDirs(); | 139 _linkSecondaryPackageDirs(); |
144 }); | 140 }); |
145 } | 141 } |
146 | 142 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 274 } |
279 | 275 |
280 /// Creates a symlink to the `packages` directory in [dir]. Will replace one | 276 /// Creates a symlink to the `packages` directory in [dir]. Will replace one |
281 /// if already there. | 277 /// if already there. |
282 void _linkSecondaryPackageDir(String dir) { | 278 void _linkSecondaryPackageDir(String dir) { |
283 var symlink = path.join(dir, 'packages'); | 279 var symlink = path.join(dir, 'packages'); |
284 if (entryExists(symlink)) deleteEntry(symlink); | 280 if (entryExists(symlink)) deleteEntry(symlink); |
285 createSymlink(packagesDir, symlink, relative: true); | 281 createSymlink(packagesDir, symlink, relative: true); |
286 } | 282 } |
287 } | 283 } |
OLD | NEW |