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

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

Issue 48993007: Revise barback logging patch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 1 month 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 | « pkg/barback/lib/src/log.dart ('k') | pkg/barback/lib/src/phase.dart » ('j') | no next file with comments »
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.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';
11 import 'asset_node.dart'; 11 import 'asset_node.dart';
12 import 'asset_set.dart'; 12 import 'asset_set.dart';
13 import 'barback_logger.dart';
14 import 'build_result.dart'; 13 import 'build_result.dart';
15 import 'errors.dart'; 14 import 'errors.dart';
15 import 'log.dart';
16 import 'package_provider.dart'; 16 import 'package_provider.dart';
17 import 'pool.dart'; 17 import 'pool.dart';
18 import 'transformer.dart'; 18 import 'transformer.dart';
19 import 'utils.dart'; 19 import 'utils.dart';
20 20
21 /// The collection of [AssetCascade]s for an entire application. 21 /// The collection of [AssetCascade]s for an entire application.
22 /// 22 ///
23 /// This tracks each package's [AssetCascade] and routes asset requests between 23 /// This tracks each package's [AssetCascade] and routes asset requests between
24 /// them. 24 /// them.
25 class PackageGraph { 25 class PackageGraph {
26 /// The provider that exposes asset and package information. 26 /// The provider that exposes asset and package information.
27 final PackageProvider provider; 27 final PackageProvider provider;
28 28
29 /// The logger used to report transformer log entries. If this is null, then
30 /// [_defaultLogger] will be used instead.
31 final BarbackLogger _logger;
32
33 /// The [AssetCascade] for each package. 29 /// The [AssetCascade] for each package.
34 final _cascades = <String, AssetCascade>{}; 30 final _cascades = <String, AssetCascade>{};
35 31
36 /// The current [BuildResult] for each package's [AssetCascade]. 32 /// The current [BuildResult] for each package's [AssetCascade].
37 /// 33 ///
38 /// The result for a given package will be `null` if that [AssetCascade] is 34 /// The result for a given package will be `null` if that [AssetCascade] is
39 /// actively building. 35 /// actively building.
40 final _cascadeResults = <String, BuildResult>{}; 36 final _cascadeResults = <String, BuildResult>{};
41 37
42 /// A stream that emits a [BuildResult] each time the build is completed, 38 /// A stream that emits a [BuildResult] each time the build is completed,
(...skipping 10 matching lines...) Expand all
53 /// A stream that emits any errors from the graph or the transformers. 49 /// A stream that emits any errors from the graph or the transformers.
54 /// 50 ///
55 /// This emits errors as they're detected. If an error occurs in one part of 51 /// This emits errors as they're detected. If an error occurs in one part of
56 /// the graph, unrelated parts will continue building. 52 /// the graph, unrelated parts will continue building.
57 /// 53 ///
58 /// This will not emit programming errors from barback itself. Those will be 54 /// This will not emit programming errors from barback itself. Those will be
59 /// emitted through the [results] stream's error channel. 55 /// emitted through the [results] stream's error channel.
60 Stream<BarbackException> get errors => _errors; 56 Stream<BarbackException> get errors => _errors;
61 Stream<BarbackException> _errors; 57 Stream<BarbackException> _errors;
62 58
59 /// The stream of [LogEntry] objects used to report transformer log entries.
60 Stream<LogEntry> get log => _logController.stream;
61 final _logController = new StreamController<LogEntry>.broadcast();
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 // TODO(nweiz): Allow transformers to declare themselves as "lightweight" or 69 // TODO(nweiz): Allow transformers to declare themselves as "lightweight" or
70 // "heavyweight" and adjust their restrictions appropriately. Simple 70 // "heavyweight" and adjust their restrictions appropriately. Simple
71 // transformers may be very efficient to run in parallel, whereas dart2js uses 71 // transformers may be very efficient to run in parallel, whereas dart2js uses
72 // a lot of memory and should be run more sequentially. 72 // a lot of memory and should be run more sequentially.
73 /// A pool that controls how many transformers may be applied at once. 73 /// A pool that controls how many transformers may be applied at once.
74 final Pool transformPool = new Pool(10); 74 final Pool transformPool = new Pool(10);
75 75
76 /// Creates a new [PackageGraph] that will transform assets in all packages 76 /// Creates a new [PackageGraph] that will transform assets in all packages
77 /// made available by [provider]. 77 /// made available by [provider].
78 PackageGraph(this.provider, {BarbackLogger logger}) 78 PackageGraph(this.provider) {
79 : _logger = logger != null ? logger : new BarbackLogger() {
80 for (var package in provider.packages) { 79 for (var package in provider.packages) {
81 var cascade = new AssetCascade(this, package); 80 var cascade = new AssetCascade(this, package);
82 // The initial result for each cascade is "success" since the cascade 81 // The initial result for each cascade is "success" since the cascade
83 // doesn't start building until some source in that graph is updated. 82 // doesn't start building until some source in that graph is updated.
84 _cascadeResults[package] = new BuildResult.success(); 83 _cascadeResults[package] = new BuildResult.success();
85 _cascades[package] = cascade; 84 _cascades[package] = cascade;
86 cascade.onDirty.listen((_) { 85 cascade.onDirty.listen((_) {
87 _cascadeResults[package] = null; 86 _cascadeResults[package] = null;
88 }); 87 });
89 88
90 cascade.onLog.listen(_logger.logEntry); 89 cascade.onLog.listen((entry) {
90 if (_logController.hasListener) {
91 _logController.add(entry);
92 } else {
93 // No listeners, so just print entry.
94 var buffer = new StringBuffer();
95 buffer.write("[${entry.level} ${entry.transform}] ");
96
97 if (entry.span != null) {
98 buffer.write(entry.span.getLocationMessage(entry.message));
99 } else {
100 buffer.write(entry.message);
101 }
102
103 print(buffer);
104 }
105 });
91 106
92 cascade.results.listen((result) { 107 cascade.results.listen((result) {
93 _cascadeResults[cascade.package] = result; 108 _cascadeResults[cascade.package] = result;
94 // If any cascade hasn't yet finished, the overall build isn't finished 109 // If any cascade hasn't yet finished, the overall build isn't finished
95 // either. 110 // either.
96 if (_cascadeResults.values.any((result) => result == null)) return; 111 if (_cascadeResults.values.any((result) => result == null)) return;
97 112
98 // Include all build errors for all cascades. If no cascades have 113 // Include all build errors for all cascades. If no cascades have
99 // errors, the result will automatically be considered a success. 114 // errors, the result will automatically be considered a success.
100 _resultsController.add( 115 _resultsController.add(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (cascade == null) throw new ArgumentError("Unknown package $package."); 188 if (cascade == null) throw new ArgumentError("Unknown package $package.");
174 cascade.removeSources(ids); 189 cascade.removeSources(ids);
175 }); 190 });
176 } 191 }
177 192
178 void updateTransformers(String package, 193 void updateTransformers(String package,
179 Iterable<Iterable<Transformer>> transformers) { 194 Iterable<Iterable<Transformer>> transformers) {
180 _cascades[package].updateTransformers(transformers); 195 _cascades[package].updateTransformers(transformers);
181 } 196 }
182 } 197 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/log.dart ('k') | pkg/barback/lib/src/phase.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698