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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
9 import 'package:package_config/packages_file.dart' as packages_file; | 9 import 'package:package_config/packages_file.dart' as packages_file; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 /// The package graph for the application and all of its transitive | 101 /// The package graph for the application and all of its transitive |
102 /// dependencies. | 102 /// dependencies. |
103 /// | 103 /// |
104 /// Throws a [DataError] if the `.packages` file isn't up-to-date relative to | 104 /// Throws a [DataError] if the `.packages` file isn't up-to-date relative to |
105 /// the pubspec and the lockfile. | 105 /// the pubspec and the lockfile. |
106 PackageGraph get packageGraph { | 106 PackageGraph get packageGraph { |
107 if (_packageGraph != null) return _packageGraph; | 107 if (_packageGraph != null) return _packageGraph; |
108 | 108 |
109 assertUpToDate(); | 109 assertUpToDate(); |
110 var packages = new Map.fromIterable(lockFile.packages.values, | 110 var packages = new Map<String, Package>.fromIterable( |
| 111 lockFile.packages.values, |
111 key: (id) => id.name, | 112 key: (id) => id.name, |
112 value: (id) => cache.load(id)); | 113 value: (id) => cache.load(id)); |
113 packages[root.name] = root; | 114 packages[root.name] = root; |
114 | 115 |
115 _packageGraph = new PackageGraph(this, lockFile, packages); | 116 _packageGraph = new PackageGraph(this, lockFile, packages); |
116 return _packageGraph; | 117 return _packageGraph; |
117 } | 118 } |
118 PackageGraph _packageGraph; | 119 PackageGraph _packageGraph; |
119 | 120 |
120 /// The path to the entrypoint's "packages" directory. | 121 /// The path to the entrypoint's "packages" directory. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 deleteEntry(p.join(_precompiledDepsPath, package)); | 288 deleteEntry(p.join(_precompiledDepsPath, package)); |
288 } | 289 } |
289 rethrow; | 290 rethrow; |
290 } | 291 } |
291 } | 292 } |
292 | 293 |
293 /// Returns the set of dependencies that need to be precompiled. | 294 /// Returns the set of dependencies that need to be precompiled. |
294 /// | 295 /// |
295 /// If [changed] is passed, only dependencies whose contents might be changed | 296 /// If [changed] is passed, only dependencies whose contents might be changed |
296 /// if one of the given packages changes will be returned. | 297 /// if one of the given packages changes will be returned. |
297 Set<String> _dependenciesToPrecompile({Iterable<String> changed}) { | 298 Set<String> _dependenciesToPrecompile({Set<String> changed}) { |
298 return packageGraph.packages.values.where((package) { | 299 return packageGraph.packages.values.where((package) { |
299 if (package.pubspec.transformers.isEmpty) return false; | 300 if (package.pubspec.transformers.isEmpty) return false; |
300 if (packageGraph.isPackageMutable(package.name)) return false; | 301 if (packageGraph.isPackageMutable(package.name)) return false; |
301 if (!dirExists(p.join(_precompiledDepsPath, package.name))) return true; | 302 if (!dirExists(p.join(_precompiledDepsPath, package.name))) return true; |
302 if (changed == null) return true; | 303 if (changed == null) return true; |
303 | 304 |
304 /// Only recompile [package] if any of its transitive dependencies have | 305 /// Only recompile [package] if any of its transitive dependencies have |
305 /// changed. We check all transitive dependencies because it's possible | 306 /// changed. We check all transitive dependencies because it's possible |
306 /// that a transformer makes decisions based on their contents. | 307 /// that a transformer makes decisions based on their contents. |
307 return overlaps( | 308 return overlaps( |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 _linkOrDeleteSecondaryPackageDir(dir); | 689 _linkOrDeleteSecondaryPackageDir(dir); |
689 _listDirWithoutPackages(dir) | 690 _listDirWithoutPackages(dir) |
690 .where(dirExists) | 691 .where(dirExists) |
691 .forEach(_linkOrDeleteSecondaryPackageDir); | 692 .forEach(_linkOrDeleteSecondaryPackageDir); |
692 } | 693 } |
693 | 694 |
694 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed. | 695 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed. |
695 /// Recursively lists the contents of [dir], excluding hidden `.DS_Store` | 696 /// Recursively lists the contents of [dir], excluding hidden `.DS_Store` |
696 /// files and `package` files. | 697 /// files and `package` files. |
697 List<String> _listDirWithoutPackages(dir) { | 698 List<String> _listDirWithoutPackages(dir) { |
698 return flatten(listDir(dir).map((file) { | 699 return listDir(dir).expand/*<String>*/((file) { |
699 if (p.basename(file) == 'packages') return []; | 700 if (p.basename(file) == 'packages') return []; |
700 if (!dirExists(file)) return []; | 701 if (!dirExists(file)) return []; |
701 var fileAndSubfiles = [file]; | 702 var fileAndSubfiles = [file]; |
702 fileAndSubfiles.addAll(_listDirWithoutPackages(file)); | 703 fileAndSubfiles.addAll(_listDirWithoutPackages(file)); |
703 return fileAndSubfiles; | 704 return fileAndSubfiles; |
704 })); | 705 }); |
705 } | 706 } |
706 | 707 |
707 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 708 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
708 /// directory in [dir]. | 709 /// directory in [dir]. |
709 /// | 710 /// |
710 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 711 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
711 void _linkOrDeleteSecondaryPackageDir(String dir) { | 712 void _linkOrDeleteSecondaryPackageDir(String dir) { |
712 var symlink = p.join(dir, 'packages'); | 713 var symlink = p.join(dir, 'packages'); |
713 if (entryExists(symlink)) deleteEntry(symlink); | 714 if (entryExists(symlink)) deleteEntry(symlink); |
714 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 715 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
715 } | 716 } |
716 } | 717 } |
OLD | NEW |