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.phase_input; | 5 library barback.phase_input; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'asset.dart'; | 10 import 'asset.dart'; |
| 11 import 'asset_forwarder.dart'; | 11 import 'asset_forwarder.dart'; |
| 12 import 'asset_node.dart'; | 12 import 'asset_node.dart'; |
| 13 import 'errors.dart'; | 13 import 'errors.dart'; |
| 14 import 'log.dart'; | 14 import 'log.dart'; |
| 15 import 'phase.dart'; | 15 import 'phase.dart'; |
| 16 import 'stream_pool.dart'; | 16 import 'stream_pool.dart'; |
| 17 import 'transform_node.dart'; | 17 import 'transform_node.dart'; |
| 18 import 'transformer.dart'; | 18 import 'transformer.dart'; |
| 19 import 'utils.dart'; | 19 import 'utils.dart'; |
| 20 | 20 |
| 21 /// A class for watching a single [AssetNode] and running any transforms that | 21 /// A class for watching a single [AssetNode] and running any transforms that |
| 22 /// take that node as a primary input. | 22 /// take that node as a primary input. |
| 23 class PhaseInput { | 23 class PhaseInput { |
| 24 /// The phase for which this is an input. | 24 /// The phase for which this is an input. |
| 25 final Phase _phase; | 25 final Phase _phase; |
| 26 | 26 |
| 27 /// A string describing the location of [this] in the transformer graph. | |
| 28 final String _location; | |
| 29 | |
| 27 /// The transformers to (potentially) run against [input]. | 30 /// The transformers to (potentially) run against [input]. |
| 28 final Set<Transformer> _transformers; | 31 final Set<Transformer> _transformers; |
| 29 | 32 |
| 30 /// The transforms currently applicable to [input]. | 33 /// The transforms currently applicable to [input]. |
| 31 /// | 34 /// |
| 32 /// These are the transforms that have been "wired up": they represent a | 35 /// These are the transforms that have been "wired up": they represent a |
| 33 /// repeatable transformation of a single concrete set of inputs. "dart2js" is | 36 /// repeatable transformation of a single concrete set of inputs. "dart2js" is |
| 34 /// a transformer. "dart2js on web/main.dart" is a transform. | 37 /// a transformer. "dart2js on web/main.dart" is a transform. |
| 35 final _transforms = new Set<TransformNode>(); | 38 final _transforms = new Set<TransformNode>(); |
| 36 | 39 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 | 80 |
| 78 /// Whether this input is dirty and needs [process] to be called. | 81 /// Whether this input is dirty and needs [process] to be called. |
| 79 bool get isDirty => _adjustTransformersFuture != null || | 82 bool get isDirty => _adjustTransformersFuture != null || |
| 80 _newPassThrough || _transforms.any((transform) => transform.isDirty); | 83 _newPassThrough || _transforms.any((transform) => transform.isDirty); |
| 81 | 84 |
| 82 /// A stream that emits an event whenever any transforms that use [input] as | 85 /// A stream that emits an event whenever any transforms that use [input] as |
| 83 /// their primary input log an entry. | 86 /// their primary input log an entry. |
| 84 Stream<LogEntry> get onLog => _onLogPool.stream; | 87 Stream<LogEntry> get onLog => _onLogPool.stream; |
| 85 final _onLogPool = new StreamPool<LogEntry>.broadcast(); | 88 final _onLogPool = new StreamPool<LogEntry>.broadcast(); |
| 86 | 89 |
| 87 PhaseInput(this._phase, AssetNode input, Iterable<Transformer> transformers) | 90 PhaseInput(this._phase, AssetNode input, Iterable<Transformer> transformers, |
| 91 this._location) | |
|
Bob Nystrom
2014/02/05 20:51:14
Only indent +4.
nweiz
2014/02/05 21:23:24
Done.
| |
| 88 : _transformers = transformers.toSet(), | 92 : _transformers = transformers.toSet(), |
| 89 _inputForwarder = new AssetForwarder(input) { | 93 _inputForwarder = new AssetForwarder(input) { |
| 90 _onDirtyPool.add(_onDirtyController.stream); | 94 _onDirtyPool.add(_onDirtyController.stream); |
| 91 | 95 |
| 92 input.onStateChange.listen((state) { | 96 input.onStateChange.listen((state) { |
| 93 if (state.isRemoved) { | 97 if (state.isRemoved) { |
| 94 remove(); | 98 remove(); |
| 95 } else if (_adjustTransformersFuture == null) { | 99 } else if (_adjustTransformersFuture == null) { |
| 96 _adjustTransformers(); | 100 _adjustTransformers(); |
| 97 } | 101 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 // run will be discarded, so we can just short-circuit. | 225 // run will be discarded, so we can just short-circuit. |
| 222 if (input.asset == null) return new Future.value(); | 226 if (input.asset == null) return new Future.value(); |
| 223 | 227 |
| 224 // We can safely access [input.asset] here even though it might have | 228 // We can safely access [input.asset] here even though it might have |
| 225 // changed since (as above) if it has, [_adjustTransformers] will just be | 229 // changed since (as above) if it has, [_adjustTransformers] will just be |
| 226 // re-run. | 230 // re-run. |
| 227 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to | 231 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to |
| 228 // results. | 232 // results. |
| 229 return transformer.isPrimary(input.asset).then((isPrimary) { | 233 return transformer.isPrimary(input.asset).then((isPrimary) { |
| 230 if (!isPrimary) return; | 234 if (!isPrimary) return; |
| 231 var transform = new TransformNode(_phase, transformer, input); | 235 var transform = new TransformNode( |
| 236 _phase, transformer, input, _location); | |
| 232 _transforms.add(transform); | 237 _transforms.add(transform); |
| 233 _onDirtyPool.add(transform.onDirty); | 238 _onDirtyPool.add(transform.onDirty); |
| 234 _onLogPool.add(transform.onLog); | 239 _onLogPool.add(transform.onLog); |
| 235 }); | 240 }); |
| 236 })); | 241 })); |
| 237 } | 242 } |
| 238 | 243 |
| 239 /// Adjust whether [input] is passed through the phase unmodified, based on | 244 /// Adjust whether [input] is passed through the phase unmodified, based on |
| 240 /// whether it's consumed by other transforms in this phase. | 245 /// whether it's consumed by other transforms in this phase. |
| 241 /// | 246 /// |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 _newPassThrough = false; | 310 _newPassThrough = false; |
| 306 return new Future.value( | 311 return new Future.value( |
| 307 new Set<AssetNode>.from([_passThroughController.node])); | 312 new Set<AssetNode>.from([_passThroughController.node])); |
| 308 } | 313 } |
| 309 | 314 |
| 310 return Future.wait(_transforms.map((transform) { | 315 return Future.wait(_transforms.map((transform) { |
| 311 if (!transform.isDirty) return new Future.value(new Set()); | 316 if (!transform.isDirty) return new Future.value(new Set()); |
| 312 return transform.apply(); | 317 return transform.apply(); |
| 313 })).then((outputs) => unionAll(outputs)); | 318 })).then((outputs) => unionAll(outputs)); |
| 314 } | 319 } |
| 320 | |
| 321 String toString() => "phase input in $_location for $input"; | |
| 315 } | 322 } |
| OLD | NEW |