| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 /// Creates a new [PackageGraph] that will transform assets in all packages | 63 /// Creates a new [PackageGraph] that will transform assets in all packages |
| 64 /// made available by [provider]. | 64 /// made available by [provider]. |
| 65 PackageGraph(this.provider) { | 65 PackageGraph(this.provider) { |
| 66 for (var package in provider.packages) { | 66 for (var package in provider.packages) { |
| 67 var cascade = new AssetCascade(this, package); | 67 var cascade = new AssetCascade(this, package); |
| 68 // The initial result for each cascade is "success" since the cascade | 68 // The initial result for each cascade is "success" since the cascade |
| 69 // doesn't start building until some source in that graph is updated. | 69 // doesn't start building until some source in that graph is updated. |
| 70 _cascadeResults[package] = new BuildResult.success(); | 70 _cascadeResults[package] = new BuildResult.success(); |
| 71 _cascades[package] = cascade; | 71 _cascades[package] = cascade; |
| 72 cascade.onDirty.listen((_) { |
| 73 _cascadeResults[package] = null; |
| 74 }); |
| 72 | 75 |
| 73 cascade.results.listen((result) { | 76 cascade.results.listen((result) { |
| 74 _cascadeResults[cascade.package] = result; | 77 _cascadeResults[cascade.package] = result; |
| 75 // If any cascade hasn't yet finished, the overall build isn't finished | 78 // If any cascade hasn't yet finished, the overall build isn't finished |
| 76 // either. | 79 // either. |
| 77 if (_cascadeResults.values.any((result) => result == null)) return; | 80 if (_cascadeResults.values.any((result) => result == null)) return; |
| 78 | 81 |
| 79 // Include all build errors for all cascades. If no cascades have | 82 // Include all build errors for all cascades. If no cascades have |
| 80 // errors, the result will automatically be considered a success. | 83 // errors, the result will automatically be considered a success. |
| 81 _resultsController.add(new BuildResult(unionAll( | 84 _resultsController.add(new BuildResult(unionAll( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 140 |
| 138 /// Adds [sources] to the graph's known set of source assets. | 141 /// Adds [sources] to the graph's known set of source assets. |
| 139 /// | 142 /// |
| 140 /// Begins applying any transforms that can consume any of the sources. If a | 143 /// Begins applying any transforms that can consume any of the sources. If a |
| 141 /// given source is already known, it is considered modified and all | 144 /// given source is already known, it is considered modified and all |
| 142 /// transforms that use it will be re-applied. | 145 /// transforms that use it will be re-applied. |
| 143 void updateSources(Iterable<AssetId> sources) { | 146 void updateSources(Iterable<AssetId> sources) { |
| 144 groupBy(sources, (id) => id.package).forEach((package, ids) { | 147 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| 145 var cascade = _cascades[package]; | 148 var cascade = _cascades[package]; |
| 146 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 149 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 147 _cascadeResults[package] = null; | |
| 148 cascade.updateSources(ids); | 150 cascade.updateSources(ids); |
| 149 }); | 151 }); |
| 150 } | 152 } |
| 151 | 153 |
| 152 /// Removes [removed] from the graph's known set of source assets. | 154 /// Removes [removed] from the graph's known set of source assets. |
| 153 void removeSources(Iterable<AssetId> sources) { | 155 void removeSources(Iterable<AssetId> sources) { |
| 154 groupBy(sources, (id) => id.package).forEach((package, ids) { | 156 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| 155 var cascade = _cascades[package]; | 157 var cascade = _cascades[package]; |
| 156 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 158 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 157 _cascadeResults[package] = null; | |
| 158 cascade.removeSources(ids); | 159 cascade.removeSources(ids); |
| 159 }); | 160 }); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void updateTransformers(String package, | 163 void updateTransformers(String package, |
| 163 Iterable<Iterable<Transformer>> transformers) { | 164 Iterable<Iterable<Transformer>> transformers) { |
| 164 _cascadeResults[package] = null; | |
| 165 _cascades[package].updateTransformers(transformers); | 165 _cascades[package].updateTransformers(transformers); |
| 166 } | 166 } |
| 167 } | 167 } |
| OLD | NEW |