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

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

Issue 23199004: Support passing barback assets through phases in which they're unused. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | pkg/barback/lib/src/barback.dart » ('j') | pkg/barback/lib/src/errors.dart » ('J')
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';
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 _newChanges = true; 106 _newChanges = true;
107 _waitForProcess(); 107 _waitForProcess();
108 }); 108 });
109 _phases.insert(0, nextPhase); 109 _phases.insert(0, nextPhase);
110 } 110 }
111 } 111 }
112 112
113 /// Gets the asset identified by [id]. 113 /// Gets the asset identified by [id].
114 /// 114 ///
115 /// If [id] is for a generated or transformed asset, this will wait until it 115 /// If [id] is for a generated or transformed asset, this will wait until it
116 /// has been created and return it. If the asset cannot be found, returns 116 /// has been created and return it. This means that the returned asset will
117 /// null. 117 /// always be [AssetState.AVAILABLE].
118 ///
119 /// If the asset cannot be found, returns null.
118 Future<AssetNode> getAssetNode(AssetId id) { 120 Future<AssetNode> getAssetNode(AssetId id) {
119 assert(id.package == package); 121 assert(id.package == package);
120 122
121 // TODO(rnystrom): Waiting for the entire build to complete is unnecessary 123 // TODO(rnystrom): Waiting for the entire build to complete is unnecessary
122 // in some cases. Should optimize: 124 // in some cases. Should optimize:
123 // * [id] may be generated before the compilation is finished. We should 125 // * [id] may be generated before the compilation is finished. We should
124 // be able to quickly check whether there are any more in-place 126 // be able to quickly check whether there are any more in-place
125 // transformations that can be run on it. If not, we can return it early. 127 // transformations that can be run on it. If not, we can return it early.
126 // * If [id] has never been generated and all active transformers provide 128 // * If [id] has never been generated and all active transformers provide
127 // metadata about the file names of assets it can emit, we can prove that 129 // metadata about the file names of assets it can emit, we can prove that
128 // none of them can emit [id] and fail early. 130 // none of them can emit [id] and fail early.
129 return newFuture(() { 131 return _phases.last.getInput(id).then((node) {
130 var node = _getAssetNode(id);
131
132 // If the requested asset is available, we can just return it. 132 // If the requested asset is available, we can just return it.
133 if (node != null) return node; 133 if (node != null && node.state.isAvailable) return node;
134 134
135 // If there's a build running, that build might generate the asset, so we 135 // If there's a build running, that build might generate the asset, so we
136 // wait for it to complete and then try again. 136 // wait for it to complete and then try again.
137 if (_processDone != null) { 137 if (_processDone != null) {
138 return _processDone.then((_) => getAssetNode(id)); 138 return _processDone.then((_) => getAssetNode(id));
139 } 139 }
140 140
141 // If the asset hasn't been built and nothing is building now, the asset 141 // If the asset hasn't been built and nothing is building now, the asset
142 // won't be generated, so we return null. 142 // won't be generated, so we return null.
143 return null; 143 return null;
144 }); 144 });
145 } 145 }
146 146
147 // Returns the post-transformation asset node for [id], if one is available.
148 //
149 // This will only return a node that has an asset available, and only if that
150 // node is guaranteed not to be consumed by any transforms. If the phase is
151 // still working to figure out if a node will be consumed by a transformer,
152 // that node won't be returned.
153 AssetNode _getAssetNode(AssetId id) {
154 // Each phase's inputs are the outputs of the previous phase. Find the last
155 // phase that contains the asset. Since the last phase has no transformers,
156 // this will find the latest output for that id.
157 for (var i = _phases.length - 1; i >= 0; i--) {
158 var node = _phases[i].getUnconsumedInput(id);
159 if (node != null) return node;
160 }
161
162 return null;
163 }
164
165 /// Adds [sources] to the graph's known set of source assets. 147 /// Adds [sources] to the graph's known set of source assets.
166 /// 148 ///
167 /// Begins applying any transforms that can consume any of the sources. If a 149 /// Begins applying any transforms that can consume any of the sources. If a
168 /// given source is already known, it is considered modified and all 150 /// given source is already known, it is considered modified and all
169 /// transforms that use it will be re-applied. 151 /// transforms that use it will be re-applied.
170 void updateSources(Iterable<AssetId> sources) { 152 void updateSources(Iterable<AssetId> sources) {
171 for (var id in sources) { 153 for (var id in sources) {
172 var controller = _sourceControllerMap[id]; 154 var controller = _sourceControllerMap[id];
173 if (controller != null) { 155 if (controller != null) {
174 controller.setDirty(); 156 controller.setDirty();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 246
265 // Otherwise, everything is done. 247 // Otherwise, everything is done.
266 return; 248 return;
267 } 249 }
268 250
269 // Process that phase and then loop onto the next. 251 // Process that phase and then loop onto the next.
270 return future.then((_) => _process()); 252 return future.then((_) => _process());
271 }); 253 });
272 } 254 }
273 } 255 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/barback.dart » ('j') | pkg/barback/lib/src/errors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698