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('package.dart'); | 8 #import('package.dart'); |
| 9 #import('root_source.dart'); |
9 #import('system_cache.dart'); | 10 #import('system_cache.dart'); |
10 #import('version.dart'); | 11 #import('version.dart'); |
| 12 #import('version_solver.dart'); |
11 #import('utils.dart'); | 13 #import('utils.dart'); |
12 | 14 |
13 /** | 15 /** |
14 * Pub operates over a directed graph of dependencies that starts at a root | 16 * Pub operates over a directed graph of dependencies that starts at a root |
15 * "entrypoint" package. This is typically the package where the current | 17 * "entrypoint" package. This is typically the package where the current |
16 * working directory is located. An entrypoint knows the [root] package it is | 18 * working directory is located. An entrypoint knows the [root] package it is |
17 * associated with and is responsible for managing the "packages" directory | 19 * associated with and is responsible for managing the "packages" directory |
18 * for it. | 20 * for it. |
19 * | 21 * |
20 * That directory contains symlinks to all packages used by an app. These links | 22 * That directory contains symlinks to all packages used by an app. These links |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 107 |
106 return future; | 108 return future; |
107 } | 109 } |
108 | 110 |
109 /** | 111 /** |
110 * Installs all dependencies of the [root] package to its "packages" | 112 * Installs all dependencies of the [root] package to its "packages" |
111 * directory. Returns a [Future] that completes when all dependencies are | 113 * directory. Returns a [Future] that completes when all dependencies are |
112 * installed. | 114 * installed. |
113 */ | 115 */ |
114 Future installDependencies() { | 116 Future installDependencies() { |
115 var seen = new Set<PackageId>(); | 117 return resolveVersions(cache.sources, root).chain((packageVersions) { |
116 | 118 // TODO(nweiz): persist packageVersions to a lockfile. |
117 Future helper(List<PackageRef> packages) { | 119 return Futures.wait(packageVersions.map((id) { |
118 return Futures.wait(packages.map((ref) { | 120 if (id.source is RootSource) return new Future.immediate(null); |
119 return resolve(ref).chain((id) { | 121 return install(id); |
120 if (seen.contains(id)) return new Future.immediate(null); | |
121 seen.add(id); | |
122 | |
123 return install(id).chain((package) { | |
124 return helper(package.dependencies); | |
125 }); | |
126 }); | |
127 })); | 122 })); |
128 } | 123 }); |
129 | |
130 return helper(root.dependencies); | |
131 } | |
132 | |
133 /** | |
134 * Given [ref], which ambiguously identifies a dependent package, selects an | |
135 * appropriate precise package to use when this is the entrypoint. In other | |
136 * words, given a loose refence like "foo >= 2.0", figures out what concrete | |
137 * package we should use starting from this entrypoint. | |
138 */ | |
139 Future<PackageId> resolve(PackageRef ref) { | |
140 // TODO(rnystrom): This should use the lockfile to select the right version | |
141 // once that's implemented. If the lockfile doesn't exist, it should | |
142 // generate it. In the meantime, here's a dumb implementation: | |
143 return new Future.immediate(ref.atVersion(ref.constraint)); | |
144 } | 124 } |
145 } | 125 } |
OLD | NEW |