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 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (id.isRoot) return new Future.value(id); | 135 if (id.isRoot) return new Future.value(id); |
136 return install(id); | 136 return install(id); |
137 }).toList()); | 137 }).toList()); |
138 }).then((ids) { | 138 }).then((ids) { |
139 _saveLockFile(ids); | 139 _saveLockFile(ids); |
140 _installSelfReference(); | 140 _installSelfReference(); |
141 _linkSecondaryPackageDirs(); | 141 _linkSecondaryPackageDirs(); |
142 }); | 142 }); |
143 } | 143 } |
144 | 144 |
145 /// Traverses the root's package dependency graph and loads each of the | |
146 /// reached packages. This should only be called after the lockfile has been | |
147 /// successfully generated. | |
148 Future<List<Pubspec>> walkDependencies() { | |
149 return new Future.sync(() { | |
150 var lockFile = loadLockFile(); | |
151 var group = new FutureGroup<Pubspec>(); | |
152 var visited = new Set<String>(); | |
153 | |
154 // Include the root package in the results. | |
155 group.add(new Future.value(root.pubspec)); | |
156 | |
157 visitPackage(Pubspec pubspec) { | |
158 for (var ref in pubspec.dependencies) { | |
159 if (visited.contains(ref.name)) continue; | |
160 | |
161 // Look up the concrete version. | |
162 var id = lockFile.packages[ref.name]; | |
163 | |
164 visited.add(ref.name); | |
165 var future; | |
166 if (ref.name == root.name) { | |
167 future = new Future<Pubspec>.value(root.pubspec); | |
168 } else { | |
169 future = cache.describe(id); | |
170 } | |
171 group.add(future.then(visitPackage)); | |
172 } | |
173 | |
174 return pubspec; | |
175 } | |
176 | |
177 visited.add(root.name); | |
178 visitPackage(root.pubspec); | |
179 return group.future; | |
180 }); | |
181 } | |
182 | |
183 /// Validates that the current Dart SDK version matches the SDK constraints | |
184 /// of every package in the dependency graph. If a package's constraint does | |
185 /// not match, prints an error. | |
186 Future validateSdkConstraints() { | |
187 return walkDependencies().then((pubspecs) { | |
188 var errors = []; | |
189 | |
190 for (var pubspec in pubspecs) { | |
191 var sdkConstraint = pubspec.environment.sdkVersion; | |
192 if (!sdkConstraint.allows(sdk.version)) { | |
193 errors.add("- '${pubspec.name}' requires ${sdkConstraint}"); | |
194 } | |
195 } | |
196 | |
197 if (errors.length > 0) { | |
198 log.error("Some packages that were installed are not compatible with " | |
199 "your SDK version ${sdk.version} and may not work:\n" | |
200 "${errors.join('\n')}\n\n" | |
201 "You may be able to resolve this by upgrading to the latest Dart " | |
202 "SDK\n" | |
203 "or adding a version constraint to use an older version of a " | |
204 "package."); | |
205 } | |
206 }); | |
207 } | |
208 | |
209 /// Loads the list of concrete package versions from the `pubspec.lock`, if it | 145 /// Loads the list of concrete package versions from the `pubspec.lock`, if it |
210 /// exists. If it doesn't, this completes to an empty [LockFile]. | 146 /// exists. If it doesn't, this completes to an empty [LockFile]. |
211 LockFile loadLockFile() { | 147 LockFile loadLockFile() { |
212 var lockFilePath = path.join(root.dir, 'pubspec.lock'); | 148 var lockFilePath = path.join(root.dir, 'pubspec.lock'); |
213 if (!entryExists(lockFilePath)) return new LockFile.empty(); | 149 if (!entryExists(lockFilePath)) return new LockFile.empty(); |
214 return new LockFile.load(lockFilePath, cache.sources); | 150 return new LockFile.load(lockFilePath, cache.sources); |
215 } | 151 } |
216 | 152 |
217 /// Saves a list of concrete package versions to the `pubspec.lock` file. | 153 /// Saves a list of concrete package versions to the `pubspec.lock` file. |
218 void _saveLockFile(List<PackageId> packageIds) { | 154 void _saveLockFile(List<PackageId> packageIds) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 } | 212 } |
277 | 213 |
278 /// Creates a symlink to the `packages` directory in [dir]. Will replace one | 214 /// Creates a symlink to the `packages` directory in [dir]. Will replace one |
279 /// if already there. | 215 /// if already there. |
280 void _linkSecondaryPackageDir(String dir) { | 216 void _linkSecondaryPackageDir(String dir) { |
281 var symlink = path.join(dir, 'packages'); | 217 var symlink = path.join(dir, 'packages'); |
282 if (entryExists(symlink)) deleteEntry(symlink); | 218 if (entryExists(symlink)) deleteEntry(symlink); |
283 createSymlink(packagesDir, symlink, relative: true); | 219 createSymlink(packagesDir, symlink, relative: true); |
284 } | 220 } |
285 } | 221 } |
OLD | NEW |