| 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; | 5 library barback.phase; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'asset_cascade.dart'; | 10 import 'asset_cascade.dart'; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 if (_inputOrigins.contains(asset.origin)) { | 266 if (_inputOrigins.contains(asset.origin)) { |
| 267 _forwarders[asset.id].addIntermediateAsset(asset); | 267 _forwarders[asset.id].addIntermediateAsset(asset); |
| 268 continue; | 268 continue; |
| 269 } | 269 } |
| 270 | 270 |
| 271 outputIds.add(asset.id); | 271 outputIds.add(asset.id); |
| 272 _addOutput(asset); | 272 _addOutput(asset); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 var outputFutures = []; | 276 var outputs = new List.from(_inputs.values); |
| 277 outputFutures.addAll(_inputs.values.map((input) { | 277 outputs.addAll(_groups.values); |
| 278 if (!input.isDirty) return new Future.value(new Set()); | |
| 279 return input.process().then(_handleOutputs); | |
| 280 })); | |
| 281 outputFutures.addAll(_groups.values.map((input) { | |
| 282 if (!input.isDirty) return new Future.value(new Set()); | |
| 283 return input.process().then(_handleOutputs); | |
| 284 })); | |
| 285 | 278 |
| 286 // TODO(nweiz): handle pass-through. | 279 // TODO(nweiz): handle pass-through. |
| 287 | 280 |
| 288 return Future.wait(outputFutures).then((_) { | 281 return forEachPooledFuture(outputs, (input) { |
| 282 if (!input.isDirty) return null; |
| 283 return input.process().then(_handleOutputs); |
| 284 }).then((_) { |
| 289 // Report collisions in a deterministic order. | 285 // Report collisions in a deterministic order. |
| 290 outputIds = outputIds.toList(); | 286 outputIds = outputIds.toList(); |
| 291 outputIds.sort((a, b) => a.compareTo(b)); | 287 outputIds.sort((a, b) => a.compareTo(b)); |
| 292 for (var id in outputIds) { | 288 for (var id in outputIds) { |
| 293 // It's possible the output was removed before other transforms in this | 289 // It's possible the output was removed before other transforms in this |
| 294 // phase finished. | 290 // phase finished. |
| 295 if (!_outputs.containsKey(id)) continue; | 291 if (!_outputs.containsKey(id)) continue; |
| 296 var exception = _outputs[id].collisionException; | 292 var exception = _outputs[id].collisionException; |
| 297 if (exception != null) cascade.reportError(exception); | 293 if (exception != null) cascade.reportError(exception); |
| 298 } | 294 } |
| 299 }); | 295 }); |
| 300 } | 296 } |
| 301 | 297 |
| 302 /// Add [asset] as an output of this phase. | 298 /// Add [asset] as an output of this phase. |
| 303 void _addOutput(AssetNode asset) { | 299 void _addOutput(AssetNode asset) { |
| 304 if (_outputs.containsKey(asset.id)) { | 300 if (_outputs.containsKey(asset.id)) { |
| 305 _outputs[asset.id].add(asset); | 301 _outputs[asset.id].add(asset); |
| 306 } else { | 302 } else { |
| 307 _outputs[asset.id] = new PhaseOutput(this, asset); | 303 _outputs[asset.id] = new PhaseOutput(this, asset); |
| 308 _outputs[asset.id].output.whenRemoved.then((_) { | 304 _outputs[asset.id].output.whenRemoved.then((_) { |
| 309 _outputs.remove(asset.id); | 305 _outputs.remove(asset.id); |
| 310 }); | 306 }); |
| 311 if (_next != null) _next.addInput(_outputs[asset.id].output); | 307 if (_next != null) _next.addInput(_outputs[asset.id].output); |
| 312 } | 308 } |
| 313 } | 309 } |
| 314 } | 310 } |
| OLD | NEW |