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

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

Issue 26572010: Improve barback/pub logging. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing file. Created 7 years, 2 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
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.transform; 5 library barback.transform;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'asset.dart'; 10 import 'asset.dart';
11 import 'asset_id.dart'; 11 import 'asset_id.dart';
12 import 'asset_node.dart'; 12 import 'asset_node.dart';
13 import 'asset_set.dart'; 13 import 'asset_set.dart';
14 import 'errors.dart'; 14 import 'errors.dart';
15 import 'transform_logger.dart'; 15 import 'transform_logger.dart';
16 import 'transform_node.dart'; 16 import 'transform_node.dart';
17 import 'utils.dart'; 17 import 'utils.dart';
18 18
19 typedef void LogFunction(AssetId asset, LogLevel level, String message,
20 Span span);
21
19 /// Creates a [Transform] by forwarding to the private constructor. 22 /// Creates a [Transform] by forwarding to the private constructor.
20 /// 23 ///
21 /// Lets [TransformNode] create [Transforms] without giving a [Transform] 24 /// Lets [TransformNode] create [Transforms] without giving a [Transform]
22 /// itself a public constructor, which would be visible to external users. 25 /// itself a public constructor, which would be visible to external users.
23 /// Unlike the [Transform] class, this function is not exported by barback.dart. 26 /// Unlike the [Transform] class, this function is not exported by barback.dart.
24 Transform createTransform(TransformNode node, AssetSet outputs) => 27 Transform createTransform(TransformNode node, AssetSet outputs,
25 new Transform._(node, outputs); 28 LogFunction logFunction) =>
29 new Transform._(node, outputs, logFunction);
26 30
27 /// While a [Transformer] represents a *kind* of transformation, this defines 31 /// While a [Transformer] represents a *kind* of transformation, this defines
28 /// one specific usage of it on a set of files. 32 /// one specific usage of it on a set of files.
29 /// 33 ///
30 /// This ephemeral object exists only during an actual transform application to 34 /// This ephemeral object exists only during an actual transform application to
31 /// facilitate communication between the [Transformer] and the code hosting 35 /// facilitate communication between the [Transformer] and the code hosting
32 /// the transformation. It lets the [Transformer] access inputs and generate 36 /// the transformation. It lets the [Transformer] access inputs and generate
33 /// outputs. 37 /// outputs.
34 class Transform { 38 class Transform {
35 final TransformNode _node; 39 final TransformNode _node;
36 40 final TransformLogger _logger;
37 final AssetSet _outputs; 41 final AssetSet _outputs;
38 42
39 /// A logger so that the [Transformer] can report build details. 43 /// A logger so that the [Transformer] can report build details.
40 TransformLogger get logger => _logger; 44 TransformLogger get logger => _logger;
41 45
42 /// Gets the primary input asset. 46 /// Gets the primary input asset.
43 /// 47 ///
44 /// While a transformation can use multiple input assets, one must be a 48 /// While a transformation can use multiple input assets, one must be a
45 /// special "primary" asset. This will be the "entrypoint" or "main" input 49 /// special "primary" asset. This will be the "entrypoint" or "main" input
46 /// file for a transformation. 50 /// file for a transformation.
47 /// 51 ///
48 /// For example, with a dart2js transform, the primary input would be the 52 /// For example, with a dart2js transform, the primary input would be the
49 /// entrypoint Dart file. All of the other Dart files that that imports 53 /// entrypoint Dart file. All of the other Dart files that that imports
50 /// would be secondary inputs. 54 /// would be secondary inputs.
51 /// 55 ///
52 /// This method may fail at runtime if called asynchronously after the 56 /// This method may fail at runtime if called asynchronously after the
53 /// transform begins running. The primary input may become unavailable while 57 /// transform begins running. The primary input may become unavailable while
54 /// this transformer is running due to asset changes earlier in the graph. 58 /// this transformer is running due to asset changes earlier in the graph.
55 /// You can ignore the error if this happens: the transformer will be re-run 59 /// You can ignore the error if this happens: the transformer will be re-run
56 /// automatically for you. 60 /// automatically for you.
57 Asset get primaryInput { 61 Asset get primaryInput {
58 if (_node.primary.state != AssetState.AVAILABLE) { 62 if (_node.primary.state != AssetState.AVAILABLE) {
59 throw new AssetNotFoundException(_node.primary.id); 63 throw new AssetNotFoundException(_node.primary.id);
60 } 64 }
61 65
62 return _node.primary.asset; 66 return _node.primary.asset;
63 } 67 }
64 68
65 Transform._(this._node, this._outputs); 69 Transform._(this._node, this._outputs, LogFunction logFunction)
70 : _logger = new TransformLogger(logFunction);
66 71
67 /// Gets the asset for an input [id]. 72 /// Gets the asset for an input [id].
68 /// 73 ///
69 /// If an input with that ID cannot be found, throws an 74 /// If an input with that ID cannot be found, throws an
70 /// [AssetNotFoundException]. 75 /// [AssetNotFoundException].
71 Future<Asset> getInput(AssetId id) => _node.getInput(id); 76 Future<Asset> getInput(AssetId id) => _node.getInput(id);
72 77
73 /// A convenience method to the contents of the input with [id] as a string. 78 /// A convenience method to the contents of the input with [id] as a string.
74 /// 79 ///
75 /// This is equivalent to calling `getInput()` followed by `readAsString()`. 80 /// This is equivalent to calling `getInput()` followed by `readAsString()`.
(...skipping 16 matching lines...) Expand all
92 97
93 /// Stores [output] as the output created by this transformation. 98 /// Stores [output] as the output created by this transformation.
94 /// 99 ///
95 /// A transformation can output as many assets as it wants. 100 /// A transformation can output as many assets as it wants.
96 void addOutput(Asset output) { 101 void addOutput(Asset output) {
97 // TODO(rnystrom): This should immediately throw if an output with that ID 102 // TODO(rnystrom): This should immediately throw if an output with that ID
98 // has already been created by this transformer. 103 // has already been created by this transformer.
99 _outputs.add(output); 104 _outputs.add(output);
100 } 105 }
101 } 106 }
102
103 // TODO(sigmund,rnystrom): create a separate logger for each Transfom.
104 final TransformLogger _logger = new TransformLogger(true);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698