| 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'; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 /// The subscription to [primary]'s [AssetNode.onStateChange] stream. | 41 /// The subscription to [primary]'s [AssetNode.onStateChange] stream. |
| 42 StreamSubscription _primarySubscription; | 42 StreamSubscription _primarySubscription; |
| 43 | 43 |
| 44 /// The subscription to [phase]'s [Phase.onAsset] stream. | 44 /// The subscription to [phase]'s [Phase.onAsset] stream. |
| 45 StreamSubscription<AssetNode> _phaseSubscription; | 45 StreamSubscription<AssetNode> _phaseSubscription; |
| 46 | 46 |
| 47 /// Whether [this] is dirty and still has more processing to do. | 47 /// Whether [this] is dirty and still has more processing to do. |
| 48 bool get isDirty => _state != _State.NOT_PRIMARY && _state != _State.APPLIED; | 48 bool get isDirty => _state != _State.NOT_PRIMARY && _state != _State.APPLIED; |
| 49 | 49 |
| 50 /// Whether [transformer] is lazy and this transform has yet to be forced. | 50 /// Whether this transform is lazy and this transform has yet to be forced. |
| 51 /// |
| 52 /// A transform being lazy is distinct from a transformer being lazy. A |
| 53 /// transformer that's declaring but not lazy will have lazy transforms for |
| 54 /// primary inputs that are themselves lazy. |
| 51 bool _isLazy; | 55 bool _isLazy; |
| 52 | 56 |
| 53 /// The subscriptions to each input's [AssetNode.onStateChange] stream. | 57 /// The subscriptions to each input's [AssetNode.onStateChange] stream. |
| 54 final _inputSubscriptions = new Map<AssetId, StreamSubscription>(); | 58 final _inputSubscriptions = new Map<AssetId, StreamSubscription>(); |
| 55 | 59 |
| 56 /// The controllers for the asset nodes emitted by this node. | 60 /// The controllers for the asset nodes emitted by this node. |
| 57 final _outputControllers = new Map<AssetId, AssetNodeController>(); | 61 final _outputControllers = new Map<AssetId, AssetNodeController>(); |
| 58 | 62 |
| 59 /// The ids of inputs the transformer tried and failed to read last time it | 63 /// The ids of inputs the transformer tried and failed to read last time it |
| 60 /// ran. | 64 /// ran. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 /// Defaults to `false`. This is not meaningful unless [_state] is | 111 /// Defaults to `false`. This is not meaningful unless [_state] is |
| 108 /// [_State.APPLIED]. | 112 /// [_State.APPLIED]. |
| 109 bool _consumePrimary = false; | 113 bool _consumePrimary = false; |
| 110 | 114 |
| 111 /// The set of output ids that [transformer] declared it would emit. | 115 /// The set of output ids that [transformer] declared it would emit. |
| 112 /// | 116 /// |
| 113 /// This is only non-null if [transformer] is a [DeclaringTransformer] and its | 117 /// This is only non-null if [transformer] is a [DeclaringTransformer] and its |
| 114 /// [declareOutputs] has been run successfully. | 118 /// [declareOutputs] has been run successfully. |
| 115 Set<AssetId> _declaredOutputs; | 119 Set<AssetId> _declaredOutputs; |
| 116 | 120 |
| 117 TransformNode(this.phase, Transformer transformer, this.primary, | 121 TransformNode(this.phase, Transformer transformer, AssetNode primary, |
| 118 this._location) | 122 this._location) |
| 119 : transformer = transformer, | 123 : transformer = transformer, |
| 120 _isLazy = transformer is LazyTransformer { | 124 primary = primary, |
| 125 _isLazy = transformer is LazyTransformer || |
| 126 (transformer is DeclaringTransformer && primary.isLazy) { |
| 121 _onLogPool.add(_onLogController.stream); | 127 _onLogPool.add(_onLogController.stream); |
| 122 | 128 |
| 129 if (!_isLazy) primary.force(); |
| 130 |
| 123 _primarySubscription = primary.onStateChange.listen((state) { | 131 _primarySubscription = primary.onStateChange.listen((state) { |
| 124 if (state.isRemoved) { | 132 if (state.isRemoved) { |
| 125 remove(); | 133 remove(); |
| 126 } else { | 134 } else { |
| 127 _dirty(); | 135 _dirty(); |
| 128 } | 136 } |
| 129 }); | 137 }); |
| 130 | 138 |
| 131 _phaseSubscription = phase.previous.onAsset.listen((node) { | 139 _phaseSubscription = phase.previous.onAsset.listen((node) { |
| 132 if (_missingInputs.contains(node.id)) _dirty(); | 140 if (_missingInputs.contains(node.id)) _dirty(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 160 _passThroughController = null; | 168 _passThroughController = null; |
| 161 } | 169 } |
| 162 } | 170 } |
| 163 | 171 |
| 164 /// If [transformer] is lazy, ensures that its concrete outputs will be | 172 /// If [transformer] is lazy, ensures that its concrete outputs will be |
| 165 /// generated. | 173 /// generated. |
| 166 void force() { | 174 void force() { |
| 167 // TODO(nweiz): we might want to have a timeout after which, if the | 175 // TODO(nweiz): we might want to have a timeout after which, if the |
| 168 // transform's outputs have gone unused, we switch it back to lazy mode. | 176 // transform's outputs have gone unused, we switch it back to lazy mode. |
| 169 if (!_isLazy) return; | 177 if (!_isLazy) return; |
| 178 primary.force(); |
| 170 _isLazy = false; | 179 _isLazy = false; |
| 171 _dirty(); | 180 _dirty(); |
| 172 } | 181 } |
| 173 | 182 |
| 174 /// Marks this transform as dirty. | 183 /// Marks this transform as dirty. |
| 175 /// | 184 /// |
| 176 /// This causes all of the transform's outputs to be marked as dirty as well. | 185 /// This causes all of the transform's outputs to be marked as dirty as well. |
| 177 void _dirty() { | 186 void _dirty() { |
| 178 if (_state == _State.NOT_PRIMARY) { | 187 if (_state == _State.NOT_PRIMARY) { |
| 179 _emitPassThrough(); | 188 _emitPassThrough(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 .where((id) => id.package != phase.cascade.package).toSet(); | 255 .where((id) => id.package != phase.cascade.package).toSet(); |
| 247 for (var id in invalidIds) { | 256 for (var id in invalidIds) { |
| 248 _declaredOutputs.remove(id); | 257 _declaredOutputs.remove(id); |
| 249 // TODO(nweiz): report this as a warning rather than a failing error. | 258 // TODO(nweiz): report this as a warning rather than a failing error. |
| 250 phase.cascade.reportError(new InvalidOutputException(info, id)); | 259 phase.cascade.reportError(new InvalidOutputException(info, id)); |
| 251 } | 260 } |
| 252 | 261 |
| 253 if (!_declaredOutputs.contains(primary.id)) _emitPassThrough(); | 262 if (!_declaredOutputs.contains(primary.id)) _emitPassThrough(); |
| 254 | 263 |
| 255 for (var id in _declaredOutputs) { | 264 for (var id in _declaredOutputs) { |
| 256 var controller = transformer is LazyTransformer | 265 var controller = _isLazy |
| 257 ? new AssetNodeController.lazy(id, force, this) | 266 ? new AssetNodeController.lazy(id, force, this) |
| 258 : new AssetNodeController(id, this); | 267 : new AssetNodeController(id, this); |
| 259 _outputControllers[id] = controller; | 268 _outputControllers[id] = controller; |
| 260 _onAssetController.add(controller.node); | 269 _onAssetController.add(controller.node); |
| 261 } | 270 } |
| 262 }).catchError((error, stackTrace) { | 271 }).catchError((error, stackTrace) { |
| 263 if (_isRemoved) return; | 272 if (_isRemoved) return; |
| 264 phase.cascade.reportError(_wrapException(error, stackTrace)); | 273 phase.cascade.reportError(_wrapException(error, stackTrace)); |
| 265 }); | 274 }); |
| 266 } | 275 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 /// | 511 /// |
| 503 /// This will never transition to another state. | 512 /// This will never transition to another state. |
| 504 static final NOT_PRIMARY = const _State._("not primary"); | 513 static final NOT_PRIMARY = const _State._("not primary"); |
| 505 | 514 |
| 506 final String name; | 515 final String name; |
| 507 | 516 |
| 508 const _State._(this.name); | 517 const _State._(this.name); |
| 509 | 518 |
| 510 String toString() => name; | 519 String toString() => name; |
| 511 } | 520 } |
| OLD | NEW |