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 pub.entrypoint; | 5 library pub.entrypoint; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:package_config/packages_file.dart' as packages_file; | 10 import 'package:package_config/packages_file.dart' as packages_file; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return; | 166 return; |
167 } | 167 } |
168 | 168 |
169 // Install the packages and maybe link them into the entrypoint. | 169 // Install the packages and maybe link them into the entrypoint. |
170 if (_packageSymlinks) { | 170 if (_packageSymlinks) { |
171 cleanDir(packagesDir); | 171 cleanDir(packagesDir); |
172 } else { | 172 } else { |
173 deleteEntry(packagesDir); | 173 deleteEntry(packagesDir); |
174 } | 174 } |
175 | 175 |
176 var ids = await Future.wait(result.packages.map(_get)); | 176 await Future.wait(result.packages.map(_get)); |
177 _saveLockFile(ids); | 177 _saveLockFile(result.packages); |
178 | 178 |
179 if (_packageSymlinks) _linkSelf(); | 179 if (_packageSymlinks) _linkSelf(); |
180 _linkOrDeleteSecondaryPackageDirs(); | 180 _linkOrDeleteSecondaryPackageDirs(); |
181 | 181 |
182 result.summarizeChanges(type, dryRun: dryRun); | 182 result.summarizeChanges(type, dryRun: dryRun); |
183 | 183 |
184 /// Build a package graph from the version solver results so we don't | 184 /// Build a package graph from the version solver results so we don't |
185 /// have to reload and reparse all the pubspecs. | 185 /// have to reload and reparse all the pubspecs. |
186 _packageGraph = new PackageGraph.fromSolveResult(this, result); | 186 _packageGraph = new PackageGraph.fromSolveResult(this, result); |
187 packageGraph.loadTransformerCache().clearIfOutdated(result.changedPackages); | 187 packageGraph.loadTransformerCache().clearIfOutdated(result.changedPackages); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 // Otherwise, we don't need to recompile. | 387 // Otherwise, we don't need to recompile. |
388 return []; | 388 return []; |
389 } | 389 } |
390 | 390 |
391 /// Makes sure the package at [id] is locally available. | 391 /// Makes sure the package at [id] is locally available. |
392 /// | 392 /// |
393 /// This automatically downloads the package to the system-wide cache as well | 393 /// This automatically downloads the package to the system-wide cache as well |
394 /// if it requires network access to retrieve (specifically, if the package's | 394 /// if it requires network access to retrieve (specifically, if the package's |
395 /// source is a [CachedSource]). | 395 /// source is a [CachedSource]). |
396 Future<PackageId> _get(PackageId id) { | 396 Future _get(PackageId id) async { |
397 if (id.isRoot) return new Future.value(id); | 397 if (id.isRoot) return; |
398 | 398 |
399 var source = cache.sources[id.source]; | 399 var source = cache.sources[id.source]; |
400 return new Future.sync(() { | 400 if (!_packageSymlinks) { |
401 if (!_packageSymlinks) { | 401 if (source is CachedSource) await source.downloadToSystemCache(id); |
402 if (source is! CachedSource) return null; | 402 return; |
403 return source.downloadToSystemCache(id); | 403 } |
404 } | |
405 | 404 |
406 var packageDir = p.join(packagesDir, id.name); | 405 var packageDir = p.join(packagesDir, id.name); |
407 if (entryExists(packageDir)) deleteEntry(packageDir); | 406 if (entryExists(packageDir)) deleteEntry(packageDir); |
408 return source.get(id, packageDir); | 407 await source.get(id, packageDir); |
409 }).then((_) => source.resolveId(id)); | |
410 } | 408 } |
411 | 409 |
412 /// Throws a [DataError] if the `.packages` file doesn't exist or if it's | 410 /// Throws a [DataError] if the `.packages` file doesn't exist or if it's |
413 /// out-of-date relative to the lockfile or the pubspec. | 411 /// out-of-date relative to the lockfile or the pubspec. |
414 void assertUpToDate() { | 412 void assertUpToDate() { |
415 if (_inMemory) return; | 413 if (_inMemory) return; |
416 | 414 |
417 if (!entryExists(lockFilePath)) { | 415 if (!entryExists(lockFilePath)) { |
418 dataError('No pubspec.lock file found, please run "pub get" first.'); | 416 dataError('No pubspec.lock file found, please run "pub get" first.'); |
419 } | 417 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 605 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
608 /// directory in [dir]. | 606 /// directory in [dir]. |
609 /// | 607 /// |
610 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 608 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
611 void _linkOrDeleteSecondaryPackageDir(String dir) { | 609 void _linkOrDeleteSecondaryPackageDir(String dir) { |
612 var symlink = p.join(dir, 'packages'); | 610 var symlink = p.join(dir, 'packages'); |
613 if (entryExists(symlink)) deleteEntry(symlink); | 611 if (entryExists(symlink)) deleteEntry(symlink); |
614 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 612 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
615 } | 613 } |
616 } | 614 } |
OLD | NEW |