| 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.package_graph; | 5 library barback.package_graph; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset_cascade.dart'; | 9 import 'asset_cascade.dart'; |
| 10 import 'asset_id.dart'; | 10 import 'asset_id.dart'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 /// The stream of [LogEntry] objects used to report transformer log entries. | 59 /// The stream of [LogEntry] objects used to report transformer log entries. |
| 60 Stream<LogEntry> get log => _logController.stream; | 60 Stream<LogEntry> get log => _logController.stream; |
| 61 final _logController = new StreamController<LogEntry>.broadcast(); | 61 final _logController = new StreamController<LogEntry>.broadcast(); |
| 62 | 62 |
| 63 /// The most recent error emitted from a cascade's result stream. | 63 /// The most recent error emitted from a cascade's result stream. |
| 64 /// | 64 /// |
| 65 /// This is used to pipe an unexpected error from a build to the resulting | 65 /// This is used to pipe an unexpected error from a build to the resulting |
| 66 /// [Future] returned by [getAllAssets]. | 66 /// [Future] returned by [getAllAssets]. |
| 67 var _lastUnexpectedError; | 67 var _lastUnexpectedError; |
| 68 | 68 |
| 69 /// The stack trace for [_lastUnexpectedError]. |
| 70 StackTrace _lastUnexpectedErrorTrace; |
| 71 |
| 69 // TODO(nweiz): Allow transformers to declare themselves as "lightweight" or | 72 // TODO(nweiz): Allow transformers to declare themselves as "lightweight" or |
| 70 // "heavyweight" and adjust their restrictions appropriately. Simple | 73 // "heavyweight" and adjust their restrictions appropriately. Simple |
| 71 // transformers may be very efficient to run in parallel, whereas dart2js uses | 74 // transformers may be very efficient to run in parallel, whereas dart2js uses |
| 72 // a lot of memory and should be run more sequentially. | 75 // a lot of memory and should be run more sequentially. |
| 73 /// A pool that controls how many transformers may be applied at once. | 76 /// A pool that controls how many transformers may be applied at once. |
| 74 final Pool transformPool = new Pool(10); | 77 final Pool transformPool = new Pool(10); |
| 75 | 78 |
| 76 /// Creates a new [PackageGraph] that will transform assets in all packages | 79 /// Creates a new [PackageGraph] that will transform assets in all packages |
| 77 /// made available by [provider]. | 80 /// made available by [provider]. |
| 78 PackageGraph(this.provider) { | 81 PackageGraph(this.provider) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 107 cascade.results.listen((result) { | 110 cascade.results.listen((result) { |
| 108 _cascadeResults[cascade.package] = result; | 111 _cascadeResults[cascade.package] = result; |
| 109 // If any cascade hasn't yet finished, the overall build isn't finished | 112 // If any cascade hasn't yet finished, the overall build isn't finished |
| 110 // either. | 113 // either. |
| 111 if (_cascadeResults.values.any((result) => result == null)) return; | 114 if (_cascadeResults.values.any((result) => result == null)) return; |
| 112 | 115 |
| 113 // Include all build errors for all cascades. If no cascades have | 116 // Include all build errors for all cascades. If no cascades have |
| 114 // errors, the result will automatically be considered a success. | 117 // errors, the result will automatically be considered a success. |
| 115 _resultsController.add( | 118 _resultsController.add( |
| 116 new BuildResult.aggregate(_cascadeResults.values)); | 119 new BuildResult.aggregate(_cascadeResults.values)); |
| 117 }, onError: (error, [stackTrace]) { | 120 }, onError: (error, stackTrace) { |
| 118 _lastUnexpectedError = error; | 121 _lastUnexpectedError = error; |
| 122 _lastUnexpectedErrorTrace = stackTrace; |
| 119 _resultsController.addError(error, stackTrace); | 123 _resultsController.addError(error, stackTrace); |
| 120 }); | 124 }); |
| 121 } | 125 } |
| 122 | 126 |
| 123 _errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors), | 127 _errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors), |
| 124 broadcast: true); | 128 broadcast: true); |
| 125 } | 129 } |
| 126 | 130 |
| 127 /// Gets the asset node identified by [id]. | 131 /// Gets the asset node identified by [id]. |
| 128 /// | 132 /// |
| (...skipping 16 matching lines...) Expand all Loading... |
| 145 Future<AssetSet> getAllAssets() { | 149 Future<AssetSet> getAllAssets() { |
| 146 if (_cascadeResults.values.contains(null)) { | 150 if (_cascadeResults.values.contains(null)) { |
| 147 // A build is still ongoing, so wait for it to complete and try again. | 151 // A build is still ongoing, so wait for it to complete and try again. |
| 148 return results.first.then((_) => getAllAssets()); | 152 return results.first.then((_) => getAllAssets()); |
| 149 } | 153 } |
| 150 | 154 |
| 151 // If an unexpected error occurred, complete with that. | 155 // If an unexpected error occurred, complete with that. |
| 152 if (_lastUnexpectedError != null) { | 156 if (_lastUnexpectedError != null) { |
| 153 var error = _lastUnexpectedError; | 157 var error = _lastUnexpectedError; |
| 154 _lastUnexpectedError = null; | 158 _lastUnexpectedError = null; |
| 155 return new Future.error(error); | 159 return new Future.error(error, _lastUnexpectedErrorTrace); |
| 156 } | 160 } |
| 157 | 161 |
| 158 // If the build completed with an error, complete the future with it. | 162 // If the build completed with an error, complete the future with it. |
| 159 var result = new BuildResult.aggregate(_cascadeResults.values); | 163 var result = new BuildResult.aggregate(_cascadeResults.values); |
| 160 if (!result.succeeded) { | 164 if (!result.succeeded) { |
| 161 return new Future.error(BarbackException.aggregate(result.errors)); | 165 return new Future.error(BarbackException.aggregate(result.errors)); |
| 162 } | 166 } |
| 163 | 167 |
| 164 // Otherwise, return all of the final output assets. | 168 // Otherwise, return all of the final output assets. |
| 165 var assets = unionAll(_cascades.values.map( | 169 var assets = unionAll(_cascades.values.map( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 188 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 192 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 189 cascade.removeSources(ids); | 193 cascade.removeSources(ids); |
| 190 }); | 194 }); |
| 191 } | 195 } |
| 192 | 196 |
| 193 void updateTransformers(String package, | 197 void updateTransformers(String package, |
| 194 Iterable<Iterable<Transformer>> transformers) { | 198 Iterable<Iterable<Transformer>> transformers) { |
| 195 _cascades[package].updateTransformers(transformers); | 199 _cascades[package].updateTransformers(transformers); |
| 196 } | 200 } |
| 197 } | 201 } |
| OLD | NEW |