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'; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 /// Defaults to `false`. This is not meaningful unless [_state] is | 107 /// Defaults to `false`. This is not meaningful unless [_state] is |
| 108 /// [_State.APPLIED]. | 108 /// [_State.APPLIED]. |
| 109 bool _consumePrimary = false; | 109 bool _consumePrimary = false; |
| 110 | 110 |
| 111 /// The set of output ids that [transformer] declared it would emit. | 111 /// The set of output ids that [transformer] declared it would emit. |
| 112 /// | 112 /// |
| 113 /// This is only non-null if [transformer] is a [DeclaringTransformer] and its | 113 /// This is only non-null if [transformer] is a [DeclaringTransformer] and its |
| 114 /// [declareOutputs] has been run successfully. | 114 /// [declareOutputs] has been run successfully. |
| 115 Set<AssetId> _declaredOutputs; | 115 Set<AssetId> _declaredOutputs; |
| 116 | 116 |
| 117 TransformNode(this.phase, Transformer transformer, this.primary, | 117 TransformNode(this.phase, Transformer transformer, AssetNode primary, |
| 118 this._location) | 118 this._location) |
| 119 : transformer = transformer, | 119 : transformer = transformer, |
| 120 _isLazy = transformer is LazyTransformer { | 120 primary = primary, |
| 121 _isLazy = transformer is LazyTransformer || | |
| 122 (transformer is DeclaringTransformer && primary.isLazy) { | |
|
Bob Nystrom
2014/04/10 20:45:34
Laziness propagates downwards from previous lazy t
nweiz
2014/04/10 20:54:53
Done.
| |
| 121 _onLogPool.add(_onLogController.stream); | 123 _onLogPool.add(_onLogController.stream); |
| 122 | 124 |
| 125 if (!_isLazy) primary.force(); | |
| 126 | |
| 123 _primarySubscription = primary.onStateChange.listen((state) { | 127 _primarySubscription = primary.onStateChange.listen((state) { |
| 124 if (state.isRemoved) { | 128 if (state.isRemoved) { |
| 125 remove(); | 129 remove(); |
| 126 } else { | 130 } else { |
| 127 _dirty(); | 131 _dirty(); |
| 128 } | 132 } |
| 129 }); | 133 }); |
| 130 | 134 |
| 131 _phaseSubscription = phase.previous.onAsset.listen((node) { | 135 _phaseSubscription = phase.previous.onAsset.listen((node) { |
| 132 if (_missingInputs.contains(node.id)) _dirty(); | 136 if (_missingInputs.contains(node.id)) _dirty(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 160 _passThroughController = null; | 164 _passThroughController = null; |
| 161 } | 165 } |
| 162 } | 166 } |
| 163 | 167 |
| 164 /// If [transformer] is lazy, ensures that its concrete outputs will be | 168 /// If [transformer] is lazy, ensures that its concrete outputs will be |
| 165 /// generated. | 169 /// generated. |
| 166 void force() { | 170 void force() { |
| 167 // TODO(nweiz): we might want to have a timeout after which, if the | 171 // 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. | 172 // transform's outputs have gone unused, we switch it back to lazy mode. |
| 169 if (!_isLazy) return; | 173 if (!_isLazy) return; |
| 174 primary.force(); | |
| 170 _isLazy = false; | 175 _isLazy = false; |
| 171 _dirty(); | 176 _dirty(); |
| 172 } | 177 } |
| 173 | 178 |
| 174 /// Marks this transform as dirty. | 179 /// Marks this transform as dirty. |
| 175 /// | 180 /// |
| 176 /// This causes all of the transform's outputs to be marked as dirty as well. | 181 /// This causes all of the transform's outputs to be marked as dirty as well. |
| 177 void _dirty() { | 182 void _dirty() { |
| 178 if (_state == _State.NOT_PRIMARY) { | 183 if (_state == _State.NOT_PRIMARY) { |
| 179 _emitPassThrough(); | 184 _emitPassThrough(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 .where((id) => id.package != phase.cascade.package).toSet(); | 251 .where((id) => id.package != phase.cascade.package).toSet(); |
| 247 for (var id in invalidIds) { | 252 for (var id in invalidIds) { |
| 248 _declaredOutputs.remove(id); | 253 _declaredOutputs.remove(id); |
| 249 // TODO(nweiz): report this as a warning rather than a failing error. | 254 // TODO(nweiz): report this as a warning rather than a failing error. |
| 250 phase.cascade.reportError(new InvalidOutputException(info, id)); | 255 phase.cascade.reportError(new InvalidOutputException(info, id)); |
| 251 } | 256 } |
| 252 | 257 |
| 253 if (!_declaredOutputs.contains(primary.id)) _emitPassThrough(); | 258 if (!_declaredOutputs.contains(primary.id)) _emitPassThrough(); |
| 254 | 259 |
| 255 for (var id in _declaredOutputs) { | 260 for (var id in _declaredOutputs) { |
| 256 var controller = transformer is LazyTransformer | 261 var controller = _isLazy |
| 257 ? new AssetNodeController.lazy(id, force, this) | 262 ? new AssetNodeController.lazy(id, force, this) |
| 258 : new AssetNodeController(id, this); | 263 : new AssetNodeController(id, this); |
| 259 _outputControllers[id] = controller; | 264 _outputControllers[id] = controller; |
| 260 _onAssetController.add(controller.node); | 265 _onAssetController.add(controller.node); |
| 261 } | 266 } |
| 262 }).catchError((error, stackTrace) { | 267 }).catchError((error, stackTrace) { |
| 263 if (_isRemoved) return; | 268 if (_isRemoved) return; |
| 264 phase.cascade.reportError(_wrapException(error, stackTrace)); | 269 phase.cascade.reportError(_wrapException(error, stackTrace)); |
| 265 }); | 270 }); |
| 266 } | 271 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 /// | 507 /// |
| 503 /// This will never transition to another state. | 508 /// This will never transition to another state. |
| 504 static final NOT_PRIMARY = const _State._("not primary"); | 509 static final NOT_PRIMARY = const _State._("not primary"); |
| 505 | 510 |
| 506 final String name; | 511 final String name; |
| 507 | 512 |
| 508 const _State._(this.name); | 513 const _State._(this.name); |
| 509 | 514 |
| 510 String toString() => name; | 515 String toString() => name; |
| 511 } | 516 } |
| OLD | NEW |