Chromium Code Reviews| 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.transform_node; | 5 library barback.transform_node; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset.dart'; | 9 import 'asset.dart'; |
| 10 import 'asset_id.dart'; | 10 import 'asset_id.dart'; |
| 11 import 'asset_node.dart'; | 11 import 'asset_node.dart'; |
| 12 import 'asset_set.dart'; | 12 import 'asset_set.dart'; |
| 13 import 'barback_logger.dart'; | |
| 13 import 'errors.dart'; | 14 import 'errors.dart'; |
| 14 import 'phase.dart'; | 15 import 'phase.dart'; |
| 15 import 'transform.dart'; | 16 import 'transform.dart'; |
| 16 import 'transformer.dart'; | 17 import 'transformer.dart'; |
| 17 | 18 |
| 18 /// Describes a transform on a set of assets and its relationship to the build | 19 /// Describes a transform on a set of assets and its relationship to the build |
| 19 /// dependency graph. | 20 /// dependency graph. |
| 20 /// | 21 /// |
| 21 /// Keeps track of whether it's dirty and needs to be run and which assets it | 22 /// Keeps track of whether it's dirty and needs to be run and which assets it |
| 22 /// depends on. | 23 /// depends on. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 46 | 47 |
| 47 /// A stream that emits an event whenever this transform becomes dirty and | 48 /// A stream that emits an event whenever this transform becomes dirty and |
| 48 /// needs to be re-run. | 49 /// needs to be re-run. |
| 49 /// | 50 /// |
| 50 /// This may emit events when the transform was already dirty or while | 51 /// This may emit events when the transform was already dirty or while |
| 51 /// processing transforms. Events are emitted synchronously to ensure that the | 52 /// processing transforms. Events are emitted synchronously to ensure that the |
| 52 /// dirty state is thoroughly propagated as soon as any assets are changed. | 53 /// dirty state is thoroughly propagated as soon as any assets are changed. |
| 53 Stream get onDirty => _onDirtyController.stream; | 54 Stream get onDirty => _onDirtyController.stream; |
| 54 final _onDirtyController = new StreamController.broadcast(sync: true); | 55 final _onDirtyController = new StreamController.broadcast(sync: true); |
| 55 | 56 |
| 57 /// A stream that emits an event whenever this transform logs an entry. | |
| 58 Stream<LogEntry> get onLog => _onLogController.stream; | |
| 59 final _onLogController = new StreamController<LogEntry>.broadcast(); | |
| 60 | |
| 56 TransformNode(this.phase, this.transformer, this.primary) { | 61 TransformNode(this.phase, this.transformer, this.primary) { |
| 57 _primarySubscription = primary.onStateChange.listen((state) { | 62 _primarySubscription = primary.onStateChange.listen((state) { |
| 58 if (state.isRemoved) { | 63 if (state.isRemoved) { |
| 59 remove(); | 64 remove(); |
| 60 } else { | 65 } else { |
| 61 _dirty(); | 66 _dirty(); |
| 62 } | 67 } |
| 63 }); | 68 }); |
| 64 } | 69 } |
| 65 | 70 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 } | 104 } |
| 100 | 105 |
| 101 /// Applies this transform. | 106 /// Applies this transform. |
| 102 /// | 107 /// |
| 103 /// Returns a set of asset nodes representing the outputs from this transform | 108 /// Returns a set of asset nodes representing the outputs from this transform |
| 104 /// that weren't emitted last time it was run. | 109 /// that weren't emitted last time it was run. |
| 105 Future<Set<AssetNode>> apply() { | 110 Future<Set<AssetNode>> apply() { |
| 106 assert(!_onDirtyController.isClosed); | 111 assert(!_onDirtyController.isClosed); |
| 107 | 112 |
| 108 var newOutputs = new AssetSet(); | 113 var newOutputs = new AssetSet(); |
| 109 var transform = createTransform(this, newOutputs); | 114 var transform = createTransform(this, newOutputs, _log); |
| 110 | 115 |
| 111 // Clear all the old input subscriptions. If an input is re-used, we'll | 116 // Clear all the old input subscriptions. If an input is re-used, we'll |
| 112 // re-subscribe. | 117 // re-subscribe. |
| 113 for (var subscription in _inputSubscriptions.values) { | 118 for (var subscription in _inputSubscriptions.values) { |
| 114 subscription.cancel(); | 119 subscription.cancel(); |
| 115 } | 120 } |
| 116 _inputSubscriptions.clear(); | 121 _inputSubscriptions.clear(); |
| 117 | 122 |
| 118 _isDirty = false; | 123 _isDirty = false; |
| 119 return transformer.apply(transform).catchError((error) { | 124 return transformer.apply(transform).catchError((error) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 controller.setAvailable(asset); | 198 controller.setAvailable(asset); |
| 194 } else { | 199 } else { |
| 195 var controller = new AssetNodeController.available(asset, this); | 200 var controller = new AssetNodeController.available(asset, this); |
| 196 _outputControllers[asset.id] = controller; | 201 _outputControllers[asset.id] = controller; |
| 197 brandNewOutputs.add(controller.node); | 202 brandNewOutputs.add(controller.node); |
| 198 } | 203 } |
| 199 } | 204 } |
| 200 | 205 |
| 201 return brandNewOutputs; | 206 return brandNewOutputs; |
| 202 } | 207 } |
| 208 | |
| 209 void _log(AssetId asset, LogLevel level, String message, Span span) { | |
| 210 // If the log isn't already associated with an asset, use the primary. | |
| 211 if (asset == null) asset = primary.id; | |
| 212 var info = new TransformInfo(transformer, primary.id); | |
|
nweiz
2013/10/16 19:41:27
There's already an info getter that does this.
Bob Nystrom
2013/10/28 23:45:56
Done.
| |
| 213 var entry = new LogEntry(info, asset, level, message, span); | |
| 214 _onLogController.add(entry); | |
| 215 } | |
| 203 } | 216 } |
| OLD | NEW |