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

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

Issue 22265002: Support cross-package transforms in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove a duplicated test. Created 7 years, 4 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; 5 library barback.phase;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.dart';
10 import 'asset_cascade.dart'; 10 import 'asset_cascade.dart';
(...skipping 27 matching lines...) Expand all
38 38
39 /// The transformers that can access [inputs]. 39 /// The transformers that can access [inputs].
40 /// 40 ///
41 /// Their outputs will be available to the next phase. 41 /// Their outputs will be available to the next phase.
42 final List<Transformer> _transformers; 42 final List<Transformer> _transformers;
43 43
44 /// The inputs that are available for transforms in this phase to consume. 44 /// The inputs that are available for transforms in this phase to consume.
45 /// 45 ///
46 /// For the first phase, these will be the source assets. For all other 46 /// For the first phase, these will be the source assets. For all other
47 /// phases, they will be the outputs from the previous phase. 47 /// phases, they will be the outputs from the previous phase.
48 final inputs = new Map<AssetId, AssetNode>(); 48 final _inputs = new Map<AssetId, AssetNode>();
49 49
50 /// The transforms currently applicable to assets in [inputs], indexed by 50 /// The transforms currently applicable to assets in [inputs], indexed by
51 /// the ids of their primary inputs. 51 /// the ids of their primary inputs.
52 /// 52 ///
53 /// These are the transforms that have been "wired up": they represent a 53 /// These are the transforms that have been "wired up": they represent a
54 /// repeatable transformation of a single concrete set of inputs. "dart2js" 54 /// repeatable transformation of a single concrete set of inputs. "dart2js"
55 /// is a transformer. "dart2js on web/main.dart" is a transform. 55 /// is a transformer. "dart2js on web/main.dart" is a transform.
56 final _transforms = new Map<AssetId, Set<TransformNode>>(); 56 final _transforms = new Map<AssetId, Set<TransformNode>>();
57 57
58 /// Futures that will complete once the transformers that can consume a given 58 /// Futures that will complete once the transformers that can consume a given
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 /// 109 ///
110 /// This should only be used for brand-new assets or assets that have been 110 /// This should only be used for brand-new assets or assets that have been
111 /// removed and re-created. The phase will automatically handle updated assets 111 /// removed and re-created. The phase will automatically handle updated assets
112 /// using the [AssetNode.onStateChange] stream. 112 /// using the [AssetNode.onStateChange] stream.
113 void addInput(AssetNode node) { 113 void addInput(AssetNode node) {
114 // We remove [node.id] from [inputs] as soon as the node is removed rather 114 // We remove [node.id] from [inputs] as soon as the node is removed rather
115 // than at the same time [node.id] is removed from [_transforms] so we don't 115 // than at the same time [node.id] is removed from [_transforms] so we don't
116 // have to wait on [_adjustTransformers]. It's important that [inputs] is 116 // have to wait on [_adjustTransformers]. It's important that [inputs] is
117 // always up-to-date so that the [AssetCascade] can look there for available 117 // always up-to-date so that the [AssetCascade] can look there for available
118 // assets. 118 // assets.
119 inputs[node.id] = node; 119 _inputs[node.id] = node;
120 node.whenRemoved.then((_) => inputs.remove(node.id)); 120 node.whenRemoved.then((_) => _inputs.remove(node.id));
121 121
122 if (!_adjustTransformersFutures.containsKey(node.id)) { 122 if (!_adjustTransformersFutures.containsKey(node.id)) {
123 _transforms[node.id] = new Set<TransformNode>(); 123 _transforms[node.id] = new Set<TransformNode>();
124 _adjustTransformers(node); 124 _adjustTransformers(node);
125 return; 125 return;
126 } 126 }
127 127
128 // If an input is added while the same input is still being processed, 128 // If an input is added while the same input is still being processed,
129 // that means that the asset was removed and recreated while 129 // that means that the asset was removed and recreated while
130 // [_adjustTransformers] was being run on the old value. We have to wait 130 // [_adjustTransformers] was being run on the old value. We have to wait
(...skipping 28 matching lines...) Expand all
159 } 159 }
160 160
161 /// Returns the input for this phase with the given [id], but only if that 161 /// Returns the input for this phase with the given [id], but only if that
162 /// input is known not to be consumed as a transformer's primary input. 162 /// input is known not to be consumed as a transformer's primary input.
163 /// 163 ///
164 /// If the input is unavailable, or if the phase hasn't determined whether or 164 /// If the input is unavailable, or if the phase hasn't determined whether or
165 /// not any transformers will consume it as a primary input, null will be 165 /// not any transformers will consume it as a primary input, null will be
166 /// returned instead. This means that the return value is guaranteed to always 166 /// returned instead. This means that the return value is guaranteed to always
167 /// be [AssetState.AVAILABLE]. 167 /// be [AssetState.AVAILABLE].
168 AssetNode getUnconsumedInput(AssetId id) { 168 AssetNode getUnconsumedInput(AssetId id) {
169 if (!inputs.containsKey(id)) return null; 169 if (!_inputs.containsKey(id)) return null;
170 170
171 // If the asset has transforms, it's not unconsumed. 171 // If the asset has transforms, it's not unconsumed.
172 if (!_transforms[id].isEmpty) return null; 172 if (!_transforms[id].isEmpty) return null;
173 173
174 // If we're working on figuring out if the asset has transforms, we can't 174 // If we're working on figuring out if the asset has transforms, we can't
175 // prove that it's unconsumed. 175 // prove that it's unconsumed.
176 if (_adjustTransformersFutures.containsKey(id)) return null; 176 if (_adjustTransformersFutures.containsKey(id)) return null;
177 177
178 // The asset should be available. If it were removed, it wouldn't be in 178 // The asset should be available. If it were removed, it wouldn't be in
179 // _inputs, and if it were dirty, it'd be in _adjustTransformersFutures. 179 // _inputs, and if it were dirty, it'd be in _adjustTransformersFutures.
180 assert(inputs[id].state.isAvailable); 180 assert(_inputs[id].state.isAvailable);
181 return inputs[id]; 181 return _inputs[id];
182 }
183
184 /// Gets the asset node for an input [id].
185 ///
186 /// If an input with that ID cannot be found, throws an
187 /// [AssetNotFoundException].
188 Future<AssetNode> getInput(AssetId id) {
189 return newFuture(() {
190 // TODO(rnystrom): Need to handle passthrough where an asset from a
191 // previous phase can be found.
192 if (id.package == cascade.package) return _inputs[id];
Bob Nystrom 2013/08/07 22:00:08 Can this ever return null? If not, why not? Maybe
nweiz 2013/08/07 22:59:15 It can. The doc comment is inaccurate. I'll fix it
193 return cascade.graph.getAssetNode(id);
194 });
182 } 195 }
183 196
184 /// Asynchronously determines which transformers can consume [node] as a 197 /// Asynchronously determines which transformers can consume [node] as a
185 /// primary input and creates transforms for them. 198 /// primary input and creates transforms for them.
186 /// 199 ///
187 /// This ensures that if [node] is modified or removed during or after the 200 /// This ensures that if [node] is modified or removed during or after the
188 /// time it takes to adjust its transformers, they're appropriately 201 /// time it takes to adjust its transformers, they're appropriately
189 /// re-adjusted. Its progress can be tracked in [_adjustTransformersFutures]. 202 /// re-adjusted. Its progress can be tracked in [_adjustTransformersFutures].
190 void _adjustTransformers(AssetNode node) { 203 void _adjustTransformers(AssetNode node) {
191 // Mark the phase as dirty. This may not actually end up creating any new 204 // Mark the phase as dirty. This may not actually end up creating any new
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Report collisions in a deterministic order. 329 // Report collisions in a deterministic order.
317 collisions = collisions.toList(); 330 collisions = collisions.toList();
318 collisions.sort((a, b) => a.toString().compareTo(b.toString())); 331 collisions.sort((a, b) => a.toString().compareTo(b.toString()));
319 for (var collision in collisions) { 332 for (var collision in collisions) {
320 cascade.reportError(new AssetCollisionException(collision)); 333 cascade.reportError(new AssetCollisionException(collision));
321 // TODO(rnystrom): Define what happens after a collision occurs. 334 // TODO(rnystrom): Define what happens after a collision occurs.
322 } 335 }
323 }); 336 });
324 } 337 }
325 } 338 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698