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

Side by Side Diff: pkg/barback/lib/src/transformer/declaring_transform.dart

Issue 262173009: Add aggregate transformer types to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.transformer.declaring_transform; 5 library barback.transformer.declaring_transform;
6 6
7 import 'dart:async';
8
7 import '../asset/asset_id.dart'; 9 import '../asset/asset_id.dart';
8 import '../graph/transform_node.dart'; 10 import 'declaring_aggregate_transform.dart';
9 import 'base_transform.dart'; 11 import 'transform_logger.dart';
10 12
11 /// A transform for [DeclaringTransform]ers that allows them to declare the ids 13 /// Creates a new [DeclaringTransform] wrapping an
14 /// [AggregateDeclaringTransform].
15 ///
16 /// Although barback internally works in terms of
17 /// [DeclaringAggregateTransformer]s, most transformers only work on individual
18 /// primary inputs in isolation. We want to allow those transformers to
19 /// implement the more user-friendly [DeclaringTransformer] interface which
20 /// takes the more user-friendly [DeclaringTransform] object. This method wraps
21 /// the more general [DeclaringAggregateTransform] to return a
22 /// [DeclaringTransform] instead.
23 Future<DeclaringTransform> newDeclaringTransform(
24 DeclaringAggregateTransform aggregate) {
25 // A wrapped [Transformer] will assign each primary input a unique transform
26 // key, so we can safely get the first asset emitted. We don't want to wait
27 // for the stream to close, since that requires barback to prove that no more
28 // new assets will be generated.
29 return aggregate.primaryIds.first.then((primaryId) =>
30 new DeclaringTransform._(aggregate, primaryId));
31 }
32
33 /// A transform for [DeclaringTransformer]s that allows them to declare the ids
12 /// of the outputs they'll generate without generating the concrete bodies of 34 /// of the outputs they'll generate without generating the concrete bodies of
13 /// those outputs. 35 /// those outputs.
14 class DeclaringTransform extends BaseTransform { 36 class DeclaringTransform {
15 final _outputIds = new Set<AssetId>(); 37 /// The underlying aggregate transform.
38 final DeclaringAggregateTransform _aggregate;
16 39
17 final AssetId primaryId; 40 final AssetId primaryId;
18 41
19 DeclaringTransform._(TransformNode node) 42 /// A logger so that the [Transformer] can report build details.
20 : primaryId = node.primary.id, 43 TransformLogger get logger => _aggregate.logger;
21 super(node); 44
45 DeclaringTransform._(this._aggregate, this.primaryId);
22 46
23 /// Stores [id] as the id of an output that will be created by this 47 /// Stores [id] as the id of an output that will be created by this
24 /// transformation when it's run. 48 /// transformation when it's run.
25 /// 49 ///
26 /// A transformation can declare as many assets as it wants. If 50 /// A transformation can declare as many assets as it wants. If
27 /// [DeclaringTransformer.declareOutputs] declareds a given asset id for a 51 /// [DeclaringTransformer.declareOutputs] declareds a given asset id for a
28 /// given input, [Transformer.apply] should emit the corresponding asset as 52 /// given input, [Transformer.apply] should emit the corresponding asset as
29 /// well. 53 /// well.
30 void declareOutput(AssetId id) { 54 void declareOutput(AssetId id) => _aggregate.declareOutput(id);
31 // TODO(nweiz): This should immediately throw if an output with that ID 55
32 // has already been declared by this transformer. 56 /// Consume the primary input so that it doesn't get processed by future
33 _outputIds.add(id); 57 /// phases or emitted once processing has finished.
34 } 58 ///
59 /// Normally the primary input will automatically be forwarded unless the
60 /// transformer overwrites it by emitting an input with the same id. This
61 /// allows the transformer to tell barback not to forward the primary input
62 /// even if it's not overwritten.
63 void consumePrimary() => _aggregate.consumePrimary(primaryId);
35 } 64 }
36
37 /// The controller for [DeclaringTransform].
38 class DeclaringTransformController extends BaseTransformController {
39 DeclaringTransform get transform => super.transform;
40
41 /// The set of ids that the transformer declares it will emit for the given
42 /// primary input.
43 Set<AssetId> get outputIds => transform._outputIds;
44
45 DeclaringTransformController(TransformNode node)
46 : super(new DeclaringTransform._(node));
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698