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

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

Issue 24460004: Fix a barback bug where a result could be emitted incorrectly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | pkg/barback/lib/src/package_graph.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.asset_cascade; 5 library barback.asset_cascade;
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_id.dart'; 11 import 'asset_id.dart';
12 import 'asset_node.dart'; 12 import 'asset_node.dart';
13 import 'asset_set.dart'; 13 import 'asset_set.dart';
14 import 'build_result.dart'; 14 import 'build_result.dart';
15 import 'cancelable_future.dart'; 15 import 'cancelable_future.dart';
16 import 'errors.dart'; 16 import 'errors.dart';
17 import 'package_graph.dart'; 17 import 'package_graph.dart';
18 import 'phase.dart'; 18 import 'phase.dart';
19 import 'stream_pool.dart';
19 import 'transformer.dart'; 20 import 'transformer.dart';
20 import 'utils.dart'; 21 import 'utils.dart';
21 22
22 /// The asset cascade for an individual package. 23 /// The asset cascade for an individual package.
23 /// 24 ///
24 /// This keeps track of which [Transformer]s are applied to which assets, and 25 /// This keeps track of which [Transformer]s are applied to which assets, and
25 /// re-runs those transformers when their dependencies change. The transformed 26 /// re-runs those transformers when their dependencies change. The transformed
26 /// asset nodes are accessible via [getAssetNode]. 27 /// asset nodes are accessible via [getAssetNode].
27 /// 28 ///
28 /// A cascade consists of one or more [Phases], each of which has one or more 29 /// A cascade consists of one or more [Phases], each of which has one or more
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 /// A stream that emits any errors from the cascade or the transformers. 63 /// A stream that emits any errors from the cascade or the transformers.
63 /// 64 ///
64 /// This emits errors as they're detected. If an error occurs in one part of 65 /// This emits errors as they're detected. If an error occurs in one part of
65 /// the cascade, unrelated parts will continue building. 66 /// the cascade, unrelated parts will continue building.
66 /// 67 ///
67 /// This will not emit programming errors from barback itself. Those will be 68 /// This will not emit programming errors from barback itself. Those will be
68 /// emitted through the [results] stream's error channel. 69 /// emitted through the [results] stream's error channel.
69 Stream<BarbackException> get errors => _errorsController.stream; 70 Stream<BarbackException> get errors => _errorsController.stream;
70 final _errorsController = new StreamController<BarbackException>.broadcast(); 71 final _errorsController = new StreamController<BarbackException>.broadcast();
71 72
73 /// A stream that emits an event whenever this cascade becomes dirty.
74 ///
75 /// After this stream emits an event, [results] will emit an event once the
76 /// cascade is no longer dirty.
77 ///
78 /// This may emit events when the cascade was already dirty. Events are
79 /// emitted synchronously to ensure that the dirty state is thoroughly
80 /// propagated as soon as any assets are changed.
81 Stream get onDirty => _onDirtyPool.stream;
82 final _onDirtyPool = new StreamPool.broadcast();
83
84 /// A controller whose stream feeds into [_onDirtyPool].
85 final _onDirtyController = new StreamController.broadcast(sync: true);
86
72 /// The errors that have occurred since the current build started. 87 /// The errors that have occurred since the current build started.
73 /// 88 ///
74 /// This will be empty if no build is occurring. 89 /// This will be empty if no build is occurring.
75 Queue<BarbackException> _accumulatedErrors; 90 Queue<BarbackException> _accumulatedErrors;
76 91
77 /// A future that completes when the currently running build process finishes. 92 /// A future that completes when the currently running build process finishes.
78 /// 93 ///
79 /// If no build it in progress, is `null`. 94 /// If no build it in progress, is `null`.
80 Future _processDone; 95 Future _processDone;
81 96
82 /// Whether any source assets have been updated or removed since processing 97 /// Whether any source assets have been updated or removed since processing
83 /// last began. 98 /// last began.
84 var _newChanges = false; 99 var _newChanges = false;
85 100
86 /// Returns all currently-available output assets from this cascade. 101 /// Returns all currently-available output assets from this cascade.
87 AssetSet get availableOutputs => _phases.last.availableOutputs; 102 AssetSet get availableOutputs => _phases.last.availableOutputs;
88 103
89 /// Creates a new [AssetCascade]. 104 /// Creates a new [AssetCascade].
90 /// 105 ///
91 /// It loads source assets within [package] using [provider]. 106 /// It loads source assets within [package] using [provider].
92 AssetCascade(this.graph, this.package) { 107 AssetCascade(this.graph, this.package) {
108 _onDirtyPool.add(_onDirtyController.stream);
93 _addPhase(new Phase(this, [])); 109 _addPhase(new Phase(this, []));
94 } 110 }
95 111
96 /// Gets the asset identified by [id]. 112 /// Gets the asset identified by [id].
97 /// 113 ///
98 /// If [id] is for a generated or transformed asset, this will wait until it 114 /// If [id] is for a generated or transformed asset, this will wait until it
99 /// has been created and return it. This means that the returned asset will 115 /// has been created and return it. This means that the returned asset will
100 /// always be [AssetState.AVAILABLE]. 116 /// always be [AssetState.AVAILABLE].
101 /// 117 ///
102 /// If the asset cannot be found, returns null. 118 /// If the asset cannot be found, returns null.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 210 }
195 } 211 }
196 212
197 void reportError(BarbackException error) { 213 void reportError(BarbackException error) {
198 _accumulatedErrors.add(error); 214 _accumulatedErrors.add(error);
199 _errorsController.add(error); 215 _errorsController.add(error);
200 } 216 }
201 217
202 /// Add [phase] to the end of [_phases] and watch its [onDirty] stream. 218 /// Add [phase] to the end of [_phases] and watch its [onDirty] stream.
203 void _addPhase(Phase phase) { 219 void _addPhase(Phase phase) {
220 _onDirtyPool.add(phase.onDirty);
204 phase.onDirty.listen((_) { 221 phase.onDirty.listen((_) {
205 _newChanges = true; 222 _newChanges = true;
206 _waitForProcess(); 223 _waitForProcess();
207 }); 224 });
208 _phases.add(phase); 225 _phases.add(phase);
209 } 226 }
210 227
211 /// Starts the build process asynchronously if there is work to be done. 228 /// Starts the build process asynchronously if there is work to be done.
212 /// 229 ///
213 /// Returns a future that completes with the background processing is done. 230 /// Returns a future that completes with the background processing is done.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 276
260 // Otherwise, everything is done. 277 // Otherwise, everything is done.
261 return; 278 return;
262 } 279 }
263 280
264 // Process that phase and then loop onto the next. 281 // Process that phase and then loop onto the next.
265 return future.then((_) => _process()); 282 return future.then((_) => _process());
266 }); 283 });
267 } 284 }
268 } 285 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/package_graph.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698