Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: pkg/barback/lib/src/phase_input.dart

Issue 26572010: Improve barback/pub logging. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing file. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'barback_logger.dart';
13 import 'errors.dart'; 14 import 'errors.dart';
14 import 'phase.dart'; 15 import 'phase.dart';
15 import 'stream_pool.dart'; 16 import 'stream_pool.dart';
16 import 'transform_node.dart'; 17 import 'transform_node.dart';
17 import 'transformer.dart'; 18 import 'transformer.dart';
18 import 'utils.dart'; 19 import 'utils.dart';
19 20
20 /// 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
21 /// take that node as a primary input. 22 /// take that node as a primary input.
22 class PhaseInput { 23 class PhaseInput {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 /// This is used whenever the input is changed or removed. It's sometimes 72 /// This is used whenever the input is changed or removed. It's sometimes
72 /// redundant with the events collected from [_transforms], but this stream is 73 /// redundant with the events collected from [_transforms], but this stream is
73 /// necessary for removed inputs, and the transform stream is necessary for 74 /// necessary for removed inputs, and the transform stream is necessary for
74 /// modified secondary inputs. 75 /// modified secondary inputs.
75 final _onDirtyController = new StreamController.broadcast(sync: true); 76 final _onDirtyController = new StreamController.broadcast(sync: true);
76 77
77 /// Whether this input is dirty and needs [process] to be called. 78 /// Whether this input is dirty and needs [process] to be called.
78 bool get isDirty => _adjustTransformersFuture != null || 79 bool get isDirty => _adjustTransformersFuture != null ||
79 _newPassThrough || _transforms.any((transform) => transform.isDirty); 80 _newPassThrough || _transforms.any((transform) => transform.isDirty);
80 81
82 /// A stream that emits an event whenever any transforms that use [input] as
83 /// their primary input log an entry.
nweiz 2013/10/16 19:41:27 "log" -> "logs"
Bob Nystrom 2013/10/28 23:45:56 This one's actually correct. :)
84 Stream<LogEntry> get onLog => _onLogPool.stream;
85 final _onLogPool = new StreamPool<LogEntry>.broadcast();
86
81 PhaseInput(this._phase, AssetNode input, Iterable<Transformer> transformers) 87 PhaseInput(this._phase, AssetNode input, Iterable<Transformer> transformers)
82 : _transformers = transformers.toSet(), 88 : _transformers = transformers.toSet(),
83 _inputForwarder = new AssetForwarder(input) { 89 _inputForwarder = new AssetForwarder(input) {
84 _onDirtyPool.add(_onDirtyController.stream); 90 _onDirtyPool.add(_onDirtyController.stream);
85 91
86 input.onStateChange.listen((state) { 92 input.onStateChange.listen((state) {
87 if (state.isRemoved) { 93 if (state.isRemoved) {
88 remove(); 94 remove();
89 } else if (_adjustTransformersFuture == null) { 95 } else if (_adjustTransformersFuture == null) {
90 _adjustTransformers(); 96 _adjustTransformers();
91 } 97 }
92 }); 98 });
93 99
94 _adjustTransformers(); 100 _adjustTransformers();
95 } 101 }
96 102
97 /// Removes this input. 103 /// Removes this input.
98 /// 104 ///
99 /// This marks all outputs of the input as removed. 105 /// This marks all outputs of the input as removed.
100 void remove() { 106 void remove() {
101 _onDirtyController.add(null); 107 _onDirtyController.add(null);
102 _onDirtyPool.close(); 108 _onDirtyPool.close();
109 _onLogPool.close();
103 _inputForwarder.close(); 110 _inputForwarder.close();
104 if (_passThroughController != null) { 111 if (_passThroughController != null) {
105 _passThroughController.setRemoved(); 112 _passThroughController.setRemoved();
106 _passThroughController = null; 113 _passThroughController = null;
107 } 114 }
108 } 115 }
109 116
110 /// Set this input's transformers to [transformers]. 117 /// Set this input's transformers to [transformers].
111 void updateTransformers(Iterable<Transformer> newTransformers) { 118 void updateTransformers(Iterable<Transformer> newTransformers) {
112 newTransformers = newTransformers.toSet(); 119 newTransformers = newTransformers.toSet();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // We can safely access [input.asset] here even though it might have 224 // We can safely access [input.asset] here even though it might have
218 // changed since (as above) if it has, [_adjustTransformers] will just be 225 // changed since (as above) if it has, [_adjustTransformers] will just be
219 // re-run. 226 // re-run.
220 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to 227 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to
221 // results. 228 // results.
222 return transformer.isPrimary(input.asset).then((isPrimary) { 229 return transformer.isPrimary(input.asset).then((isPrimary) {
223 if (!isPrimary) return; 230 if (!isPrimary) return;
224 var transform = new TransformNode(_phase, transformer, input); 231 var transform = new TransformNode(_phase, transformer, input);
225 _transforms.add(transform); 232 _transforms.add(transform);
226 _onDirtyPool.add(transform.onDirty); 233 _onDirtyPool.add(transform.onDirty);
234 _onLogPool.add(transform.onLog);
227 }); 235 });
228 })); 236 }));
229 } 237 }
230 238
231 /// Adjust whether [input] is passed through the phase unmodified, based on 239 /// Adjust whether [input] is passed through the phase unmodified, based on
232 /// whether it's consumed by other transforms in this phase. 240 /// whether it's consumed by other transforms in this phase.
233 /// 241 ///
234 /// If [input] was already passed-through, this will update the passed-through 242 /// If [input] was already passed-through, this will update the passed-through
235 /// value. 243 /// value.
236 void _adjustPassThrough() { 244 void _adjustPassThrough() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return new Future.value( 295 return new Future.value(
288 new Set<AssetNode>.from([_passThroughController.node])); 296 new Set<AssetNode>.from([_passThroughController.node]));
289 } 297 }
290 298
291 return Future.wait(_transforms.map((transform) { 299 return Future.wait(_transforms.map((transform) {
292 if (!transform.isDirty) return new Future.value(new Set()); 300 if (!transform.isDirty) return new Future.value(new Set());
293 return transform.apply(); 301 return transform.apply();
294 })).then((outputs) => unionAll(outputs)); 302 })).then((outputs) => unionAll(outputs));
295 } 303 }
296 } 304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698