| 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.phase; | 5 library barback.graph.phase; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../asset/asset_id.dart'; | 9 import '../asset/asset_id.dart'; |
| 10 import '../asset/asset_node.dart'; | 10 import '../asset/asset_node.dart'; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if (state.isRemoved) { | 178 if (state.isRemoved) { |
| 179 _inputOrigins.remove(node.origin); | 179 _inputOrigins.remove(node.origin); |
| 180 _forwarders.remove(node.id).remove(); | 180 _forwarders.remove(node.id).remove(); |
| 181 } | 181 } |
| 182 _streams.changeStatus(status); | 182 _streams.changeStatus(status); |
| 183 }); | 183 }); |
| 184 | 184 |
| 185 for (var classifier in _classifiers.values) { | 185 for (var classifier in _classifiers.values) { |
| 186 classifier.addInput(node); | 186 classifier.addInput(node); |
| 187 } | 187 } |
| 188 for (var group in _groups.values) { | |
| 189 group.addInput(node); | |
| 190 } | |
| 191 } | 188 } |
| 192 | 189 |
| 193 // TODO(nweiz): If the output is available when this is called, it's | 190 // TODO(nweiz): If the output is available when this is called, it's |
| 194 // theoretically possible for it to become unavailable between the call and | 191 // theoretically possible for it to become unavailable between the call and |
| 195 // the return. If it does so, it won't trigger the rebuilding process. To | 192 // the return. If it does so, it won't trigger the rebuilding process. To |
| 196 // avoid this, we should have this and the methods it calls take explicit | 193 // avoid this, we should have this and the methods it calls take explicit |
| 197 // callbacks, as in [AssetNode.whenAvailable]. | 194 // callbacks, as in [AssetNode.whenAvailable]. |
| 198 /// Gets the asset node for an output [id]. | 195 /// Gets the asset node for an output [id]. |
| 199 /// | 196 /// |
| 200 /// If [id] is for a generated or transformed asset, this will wait until it | 197 /// If [id] is for a generated or transformed asset, this will wait until it |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 253 } |
| 257 | 254 |
| 258 var newGroups = transformers.where((op) => op is TransformerGroup) | 255 var newGroups = transformers.where((op) => op is TransformerGroup) |
| 259 .toSet(); | 256 .toSet(); |
| 260 var oldGroups = _groups.keys.toSet(); | 257 var oldGroups = _groups.keys.toSet(); |
| 261 for (var removed in oldGroups.difference(newGroups)) { | 258 for (var removed in oldGroups.difference(newGroups)) { |
| 262 _groups.remove(removed).remove(); | 259 _groups.remove(removed).remove(); |
| 263 } | 260 } |
| 264 | 261 |
| 265 for (var added in newGroups.difference(oldGroups)) { | 262 for (var added in newGroups.difference(oldGroups)) { |
| 266 var runner = new GroupRunner(cascade, added, "$_location.$_index"); | 263 var runner = new GroupRunner(previous, added, "$_location.$_index"); |
| 267 _groups[added] = runner; | 264 _groups[added] = runner; |
| 268 runner.onAsset.listen(_handleOutput); | 265 runner.onAsset.listen(_handleOutput); |
| 269 _streams.onLogPool.add(runner.onLog); | 266 _streams.onLogPool.add(runner.onLog); |
| 270 runner.onStatusChange.listen((_) => _streams.changeStatus(status)); | 267 runner.onStatusChange.listen((_) => _streams.changeStatus(status)); |
| 271 for (var input in _inputs) { | |
| 272 runner.addInput(input); | |
| 273 } | |
| 274 } | 268 } |
| 275 | 269 |
| 276 for (var forwarder in _forwarders.values) { | 270 for (var forwarder in _forwarders.values) { |
| 277 forwarder.updateTransformers(_classifiers.length, _groups.length); | 271 forwarder.updateTransformers(_classifiers.length, _groups.length); |
| 278 } | 272 } |
| 279 | 273 |
| 280 _streams.changeStatus(status); | 274 _streams.changeStatus(status); |
| 281 } | 275 } |
| 282 | 276 |
| 283 /// Force all [LazyTransformer]s' transforms in this phase to begin producing | 277 /// Force all [LazyTransformer]s' transforms in this phase to begin producing |
| 284 /// concrete assets. | 278 /// concrete assets. |
| 285 void forceAllTransforms() { | 279 void forceAllTransforms() { |
| 286 for (var classifier in _classifiers.values) { | 280 for (var classifier in _classifiers.values) { |
| 287 classifier.forceAllTransforms(); | 281 classifier.forceAllTransforms(); |
| 288 } | 282 } |
| 289 | 283 |
| 290 for (var group in _groups.values) { | 284 for (var group in _groups.values) { |
| 291 group.forceAllTransforms(); | 285 group.forceAllTransforms(); |
| 292 } | 286 } |
| 293 } | 287 } |
| 294 | 288 |
| 295 /// Add a new phase after this one. | 289 /// Add a new phase after this one. |
| 296 /// | 290 /// |
| 297 /// This may only be called on a phase with no phase following it. | 291 /// The new phase will have a location annotation describing its place in the |
| 298 Phase addPhase() { | 292 /// package graph. By default, this annotation will describe it as being |
| 299 var next = new Phase._(cascade, _location, _index + 1, this); | 293 /// directly after [this]. If [location] is passed, though, it's described as |
| 294 /// being the first phase in that location. |
| 295 Phase addPhase([String location]) { |
| 296 var index = 0; |
| 297 if (location == null) { |
| 298 location = _location; |
| 299 index = _index + 1; |
| 300 } |
| 301 |
| 302 var next = new Phase._(cascade, location, index, this); |
| 300 for (var output in _outputs.values.toList()) { | 303 for (var output in _outputs.values.toList()) { |
| 301 // Remove [output]'s listeners because now they should get the asset from | 304 // Remove [output]'s listeners because now they should get the asset from |
| 302 // [next], rather than this phase. Any transforms consuming [output] will | 305 // [next], rather than this phase. Any transforms consuming [output] will |
| 303 // be re-run and will consume the output from the new final phase. | 306 // be re-run and will consume the output from the new final phase. |
| 304 output.removeListeners(); | 307 output.removeListeners(); |
| 305 } | 308 } |
| 306 return next; | 309 return next; |
| 307 } | 310 } |
| 308 | 311 |
| 309 /// Mark this phase as removed. | 312 /// Mark this phase as removed. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 assert(asset.state.isDirty); | 378 assert(asset.state.isDirty); |
| 376 asset.force(); | 379 asset.force(); |
| 377 asset.whenStateChanges().then((state) { | 380 asset.whenStateChanges().then((state) { |
| 378 if (state.isRemoved) return getOutput(asset.id); | 381 if (state.isRemoved) return getOutput(asset.id); |
| 379 return asset; | 382 return asset; |
| 380 }).then(request.complete).catchError(request.completeError); | 383 }).then(request.complete).catchError(request.completeError); |
| 381 } | 384 } |
| 382 | 385 |
| 383 String toString() => "phase $_location.$_index"; | 386 String toString() => "phase $_location.$_index"; |
| 384 } | 387 } |
| OLD | NEW |