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 barback.graph.package_graph; | 5 library barback.graph.package_graph; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import '../asset/asset_id.dart'; | 10 import '../asset/asset_id.dart'; |
11 import '../asset/asset_node.dart'; | 11 import '../asset/asset_node.dart'; |
12 import '../asset/asset_set.dart'; | 12 import '../asset/asset_set.dart'; |
13 import '../build_result.dart'; | 13 import '../build_result.dart'; |
14 import '../errors.dart'; | 14 import '../errors.dart'; |
15 import '../log.dart'; | 15 import '../log.dart'; |
16 import '../package_provider.dart'; | 16 import '../package_provider.dart'; |
17 import '../utils.dart'; | 17 import '../utils.dart'; |
18 import 'asset_cascade.dart'; | 18 import 'asset_cascade.dart'; |
19 import 'node_status.dart'; | 19 import 'node_status.dart'; |
| 20 import 'static_asset_cascade.dart'; |
20 | 21 |
21 /// The collection of [AssetCascade]s for an entire application. | 22 /// The collection of [AssetCascade]s for an entire application. |
22 /// | 23 /// |
23 /// This tracks each package's [AssetCascade] and routes asset requests between | 24 /// This tracks each package's [AssetCascade] and routes asset requests between |
24 /// them. | 25 /// them. |
25 class PackageGraph { | 26 class PackageGraph { |
26 /// The provider that exposes asset and package information. | 27 /// The provider that exposes asset and package information. |
27 final PackageProvider provider; | 28 final PackageProvider provider; |
28 | 29 |
29 /// The [AssetCascade] for each package. | 30 /// The [AssetCascade] for each package. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 _inErrorZone(() { | 89 _inErrorZone(() { |
89 for (var package in provider.packages) { | 90 for (var package in provider.packages) { |
90 var cascade = new AssetCascade(this, package); | 91 var cascade = new AssetCascade(this, package); |
91 _cascades[package] = cascade; | 92 _cascades[package] = cascade; |
92 cascade.onLog.listen(_onLog); | 93 cascade.onLog.listen(_onLog); |
93 cascade.onStatusChange.listen((status) { | 94 cascade.onStatusChange.listen((status) { |
94 if (status == NodeStatus.IDLE) _tryScheduleResult(); | 95 if (status == NodeStatus.IDLE) _tryScheduleResult(); |
95 }); | 96 }); |
96 } | 97 } |
97 | 98 |
| 99 if (provider is StaticPackageProvider) { |
| 100 StaticPackageProvider staticProvider = provider; |
| 101 for (var package in staticProvider.staticPackages) { |
| 102 if (_cascades.containsKey(package)) { |
| 103 throw new StateError('Package "$package" is in both ' |
| 104 'PackageProvider.packages and PackageProvider.staticPackages.'); |
| 105 } |
| 106 |
| 107 var cascade = new StaticAssetCascade(this, package); |
| 108 _cascades[package] = cascade; |
| 109 } |
| 110 } |
| 111 |
98 _errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors), | 112 _errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors), |
99 broadcast: true); | 113 broadcast: true); |
100 _errors.listen(_accumulatedErrors.add); | 114 _errors.listen(_accumulatedErrors.add); |
| 115 |
| 116 // Make sure a result gets scheduled even if there are no cascades or all |
| 117 // of them are static. |
| 118 if (provider.packages.isEmpty) _tryScheduleResult(); |
101 }); | 119 }); |
102 } | 120 } |
103 | 121 |
104 /// Gets the asset node identified by [id]. | 122 /// Gets the asset node identified by [id]. |
105 /// | 123 /// |
106 /// If [id] is for a generated or transformed asset, this will wait until it | 124 /// If [id] is for a generated or transformed asset, this will wait until it |
107 /// has been created and return it. This means that the returned asset will | 125 /// has been created and return it. This means that the returned asset will |
108 /// always be [AssetState.AVAILABLE]. | 126 /// always be [AssetState.AVAILABLE]. |
109 /// | 127 /// |
110 /// If the asset cannot be found, returns null. | 128 /// If the asset cannot be found, returns null. |
(...skipping 29 matching lines...) Expand all Loading... |
140 _lastUnexpectedError = null; | 158 _lastUnexpectedError = null; |
141 return new Future.error(error, _lastUnexpectedErrorTrace); | 159 return new Future.error(error, _lastUnexpectedErrorTrace); |
142 } | 160 } |
143 | 161 |
144 // If the last build completed with an error, complete the future with it. | 162 // If the last build completed with an error, complete the future with it. |
145 if (!_lastResult.succeeded) { | 163 if (!_lastResult.succeeded) { |
146 return new Future.error(BarbackException.aggregate(_lastResult.errors)); | 164 return new Future.error(BarbackException.aggregate(_lastResult.errors)); |
147 } | 165 } |
148 | 166 |
149 // Otherwise, return all of the final output assets. | 167 // Otherwise, return all of the final output assets. |
150 var assets = unionAll(_cascades.values.map( | 168 return Future.wait(_cascades.values.map( |
151 (cascade) => cascade.availableOutputs.toSet())); | 169 (cascade) => cascade.availableOutputs)) |
152 | 170 .then((assetSets) { |
153 return new Future.value(new AssetSet.from(assets)); | 171 var assets = unionAll(assetSets.map((assetSet) => assetSet.toSet())); |
| 172 return new Future.value(new AssetSet.from(assets)); |
| 173 }); |
154 } | 174 } |
155 | 175 |
156 /// Adds [sources] to the graph's known set of source assets. | 176 /// Adds [sources] to the graph's known set of source assets. |
157 /// | 177 /// |
158 /// Begins applying any transforms that can consume any of the sources. If a | 178 /// Begins applying any transforms that can consume any of the sources. If a |
159 /// given source is already known, it is considered modified and all | 179 /// given source is already known, it is considered modified and all |
160 /// transforms that use it will be re-applied. | 180 /// transforms that use it will be re-applied. |
161 void updateSources(Iterable<AssetId> sources) { | 181 void updateSources(Iterable<AssetId> sources) { |
162 groupBy(sources, (id) => id.package).forEach((package, ids) { | 182 groupBy(sources, (id) => id.package).forEach((package, ids) { |
163 var cascade = _cascades[package]; | 183 var cascade = _cascades[package]; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 completer.completeError(error, stackTrace); | 273 completer.completeError(error, stackTrace); |
254 }); | 274 }); |
255 }, onError: (error, stackTrace) { | 275 }, onError: (error, stackTrace) { |
256 _lastUnexpectedError = error; | 276 _lastUnexpectedError = error; |
257 _lastUnexpectedErrorTrace = stackTrace; | 277 _lastUnexpectedErrorTrace = stackTrace; |
258 _resultsController.addError(error, stackTrace); | 278 _resultsController.addError(error, stackTrace); |
259 }); | 279 }); |
260 return completer.future; | 280 return completer.future; |
261 } | 281 } |
262 } | 282 } |
OLD | NEW |