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 library pub.package_graph; | 5 library pub.package_graph; |
6 | 6 |
7 import 'barback/transformer_cache.dart'; | 7 import 'barback/transformer_cache.dart'; |
8 import 'entrypoint.dart'; | 8 import 'entrypoint.dart'; |
9 import 'lock_file.dart'; | 9 import 'lock_file.dart'; |
10 import 'package.dart'; | 10 import 'package.dart'; |
| 11 import 'solver/version_solver.dart'; |
11 import 'source/cached.dart'; | 12 import 'source/cached.dart'; |
12 import 'utils.dart'; | 13 import 'utils.dart'; |
13 | 14 |
14 /// A holistic view of the entire transitive dependency graph for an entrypoint. | 15 /// A holistic view of the entire transitive dependency graph for an entrypoint. |
15 /// | |
16 /// A package graph can be loaded using [Entrypoint.loadPackageGraph]. | |
17 class PackageGraph { | 16 class PackageGraph { |
18 /// The entrypoint. | 17 /// The entrypoint. |
19 final Entrypoint entrypoint; | 18 final Entrypoint entrypoint; |
20 | 19 |
21 /// The entrypoint's lockfile. | 20 /// The entrypoint's lockfile. |
22 /// | 21 /// |
23 /// This describes the sources and resolved descriptions of everything in | 22 /// This describes the sources and resolved descriptions of everything in |
24 /// [packages]. | 23 /// [packages]. |
25 final LockFile lockFile; | 24 final LockFile lockFile; |
26 | 25 |
27 /// The transitive dependencies of the entrypoint (including itself). | 26 /// The transitive dependencies of the entrypoint (including itself). |
28 /// | 27 /// |
29 /// This may not include all transitive dependencies of the entrypoint if the | 28 /// This may not include all transitive dependencies of the entrypoint if the |
30 /// creator of the package graph knows only a subset of the packages are | 29 /// creator of the package graph knows only a subset of the packages are |
31 /// relevant in the current context. | 30 /// relevant in the current context. |
32 final Map<String, Package> packages; | 31 final Map<String, Package> packages; |
33 | 32 |
34 /// A map of transitive dependencies for each package. | 33 /// A map of transitive dependencies for each package. |
35 Map<String, Set<Package>> _transitiveDependencies; | 34 Map<String, Set<Package>> _transitiveDependencies; |
36 | 35 |
37 /// The transformer cache, if it's been loaded. | 36 /// The transformer cache, if it's been loaded. |
38 TransformerCache _transformerCache; | 37 TransformerCache _transformerCache; |
39 | 38 |
40 PackageGraph(this.entrypoint, this.lockFile, this.packages); | 39 PackageGraph(this.entrypoint, this.lockFile, this.packages); |
41 | 40 |
| 41 /// Creates a package graph using the data from [result]. |
| 42 /// |
| 43 /// This is generally faster than loading a package graph from scratch, since |
| 44 /// the packages' pubspecs are already fully-parsed. |
| 45 factory PackageGraph.fromSolveResult(Entrypoint entrypoint, |
| 46 SolveResult result) { |
| 47 var packages = new Map.fromIterable(result.packages, |
| 48 key: (id) => id.name, |
| 49 value: (id) { |
| 50 if (id.name == entrypoint.root.name) return entrypoint.root; |
| 51 |
| 52 return new Package(result.pubspecs[id.name], |
| 53 entrypoint.cache.sources[id.source].getDirectory(id)); |
| 54 }); |
| 55 |
| 56 return new PackageGraph( |
| 57 entrypoint, |
| 58 new LockFile(result.packages, entrypoint.cache.sources), |
| 59 packages); |
| 60 } |
| 61 |
42 /// Loads the transformer cache for this graph. | 62 /// Loads the transformer cache for this graph. |
43 /// | 63 /// |
44 /// This may only be called if [entrypoint] represents a physical package. | 64 /// This may only be called if [entrypoint] represents a physical package. |
45 /// This may modify the cache. | 65 /// This may modify the cache. |
46 TransformerCache loadTransformerCache() { | 66 TransformerCache loadTransformerCache() { |
47 if (_transformerCache == null) { | 67 if (_transformerCache == null) { |
48 if (entrypoint.root.dir == null) { | 68 if (entrypoint.root.dir == null) { |
49 throw new StateError("Can't load the transformer cache for virtual " | 69 throw new StateError("Can't load the transformer cache for virtual " |
50 "entrypoint ${entrypoint.root.name}."); | 70 "entrypoint ${entrypoint.root.name}."); |
51 } | 71 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool isPackageStatic(String package) { | 155 bool isPackageStatic(String package) { |
136 var id = lockFile.packages[package]; | 156 var id = lockFile.packages[package]; |
137 if (id == null) return false; | 157 if (id == null) return false; |
138 | 158 |
139 var source = entrypoint.cache.sources[id.source]; | 159 var source = entrypoint.cache.sources[id.source]; |
140 if (source is! CachedSource) return false; | 160 if (source is! CachedSource) return false; |
141 | 161 |
142 return packages[package].pubspec.transformers.isEmpty; | 162 return packages[package].pubspec.transformers.isEmpty; |
143 } | 163 } |
144 } | 164 } |
OLD | NEW |