| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 'package:collection/collection.dart'; |
| 6 |
| 5 import 'barback/transformer_cache.dart'; | 7 import 'barback/transformer_cache.dart'; |
| 6 import 'entrypoint.dart'; | 8 import 'entrypoint.dart'; |
| 7 import 'lock_file.dart'; | 9 import 'lock_file.dart'; |
| 8 import 'package.dart'; | 10 import 'package.dart'; |
| 9 import 'solver/version_solver.dart'; | 11 import 'solver/version_solver.dart'; |
| 10 import 'source/cached.dart'; | 12 import 'source/cached.dart'; |
| 11 import 'utils.dart'; | |
| 12 | 13 |
| 13 /// A holistic view of the entire transitive dependency graph for an entrypoint. | 14 /// A holistic view of the entire transitive dependency graph for an entrypoint. |
| 14 class PackageGraph { | 15 class PackageGraph { |
| 15 /// The entrypoint. | 16 /// The entrypoint. |
| 16 final Entrypoint entrypoint; | 17 final Entrypoint entrypoint; |
| 17 | 18 |
| 18 /// The entrypoint's lockfile. | 19 /// The entrypoint's lockfile. |
| 19 /// | 20 /// |
| 20 /// This describes the sources and resolved descriptions of everything in | 21 /// This describes the sources and resolved descriptions of everything in |
| 21 /// [packages]. | 22 /// [packages]. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 TransformerCache _transformerCache; | 36 TransformerCache _transformerCache; |
| 36 | 37 |
| 37 PackageGraph(this.entrypoint, this.lockFile, this.packages); | 38 PackageGraph(this.entrypoint, this.lockFile, this.packages); |
| 38 | 39 |
| 39 /// Creates a package graph using the data from [result]. | 40 /// Creates a package graph using the data from [result]. |
| 40 /// | 41 /// |
| 41 /// This is generally faster than loading a package graph from scratch, since | 42 /// This is generally faster than loading a package graph from scratch, since |
| 42 /// the packages' pubspecs are already fully-parsed. | 43 /// the packages' pubspecs are already fully-parsed. |
| 43 factory PackageGraph.fromSolveResult(Entrypoint entrypoint, | 44 factory PackageGraph.fromSolveResult(Entrypoint entrypoint, |
| 44 SolveResult result) { | 45 SolveResult result) { |
| 45 var packages = new Map.fromIterable(result.packages, | 46 var packages = new Map<String, Package>.fromIterable(result.packages, |
| 46 key: (id) => id.name, | 47 key: (id) => id.name, |
| 47 value: (id) { | 48 value: (id) { |
| 48 if (id.name == entrypoint.root.name) return entrypoint.root; | 49 if (id.name == entrypoint.root.name) return entrypoint.root; |
| 49 | 50 |
| 50 return new Package(result.pubspecs[id.name], | 51 return new Package(result.pubspecs[id.name], |
| 51 entrypoint.cache.source(id.source).getDirectory(id)); | 52 entrypoint.cache.source(id.source).getDirectory(id)); |
| 52 }); | 53 }); |
| 53 | 54 |
| 54 return new PackageGraph(entrypoint, result.lockFile, packages); | 55 return new PackageGraph(entrypoint, result.lockFile, packages); |
| 55 } | 56 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 | 72 |
| 72 /// Returns all transitive dependencies of [package]. | 73 /// Returns all transitive dependencies of [package]. |
| 73 /// | 74 /// |
| 74 /// For the entrypoint this returns all packages in [packages], which includes | 75 /// For the entrypoint this returns all packages in [packages], which includes |
| 75 /// dev and override. For any other package, it ignores dev and override | 76 /// dev and override. For any other package, it ignores dev and override |
| 76 /// dependencies. | 77 /// dependencies. |
| 77 Set<Package> transitiveDependencies(String package) { | 78 Set<Package> transitiveDependencies(String package) { |
| 78 if (package == entrypoint.root.name) return packages.values.toSet(); | 79 if (package == entrypoint.root.name) return packages.values.toSet(); |
| 79 | 80 |
| 80 if (_transitiveDependencies == null) { | 81 if (_transitiveDependencies == null) { |
| 81 var closure = transitiveClosure(mapMap(packages, | 82 var closure = transitiveClosure( |
| 82 value: (_, package) => package.dependencies.map((dep) => dep.name))); | 83 mapMap/*<String, Package, String, Iterable<String>>*/( |
| 83 _transitiveDependencies = mapMap(closure, | 84 packages, |
| 84 value: (_, names) => names.map((name) => packages[name]).toSet()); | 85 value: (_, package) => |
| 86 package.dependencies.map((dep) => dep.name))); |
| 87 _transitiveDependencies = |
| 88 mapMap/*<String, Set<String>, String, Set<Package>>*/( |
| 89 closure, |
| 90 value: (depender, names) { |
| 91 var set = names.map((name) => packages[name]).toSet(); |
| 92 set.add(packages[depender]); |
| 93 return set; |
| 94 }); |
| 85 } | 95 } |
| 86 | 96 |
| 87 return _transitiveDependencies[package]; | 97 return _transitiveDependencies[package]; |
| 88 } | 98 } |
| 89 | 99 |
| 90 /// Returns whether [package], or any of its transitive dependencies, have | 100 /// Returns whether [package], or any of its transitive dependencies, have |
| 91 /// transformers that run on any of their public assets. | 101 /// transformers that run on any of their public assets. |
| 92 /// | 102 /// |
| 93 /// This is pessimistic; if any package can't be determined to be transformed, | 103 /// This is pessimistic; if any package can't be determined to be transformed, |
| 94 /// this returns `true`. | 104 /// this returns `true`. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 /// | 156 /// |
| 147 /// Note that a static package isn't the same as an immutable package (see | 157 /// Note that a static package isn't the same as an immutable package (see |
| 148 /// [isPackageMutable]). | 158 /// [isPackageMutable]). |
| 149 bool isPackageStatic(String package) { | 159 bool isPackageStatic(String package) { |
| 150 var id = lockFile.packages[package]; | 160 var id = lockFile.packages[package]; |
| 151 if (id == null) return false; | 161 if (id == null) return false; |
| 152 if (entrypoint.cache.source(id.source) is! CachedSource) return false; | 162 if (entrypoint.cache.source(id.source) is! CachedSource) return false; |
| 153 return packages[package].pubspec.transformers.isEmpty; | 163 return packages[package].pubspec.transformers.isEmpty; |
| 154 } | 164 } |
| 155 } | 165 } |
| OLD | NEW |