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

Side by Side Diff: pkg/barback/lib/src/graph/transform_node.dart

Issue 262173009: Add aggregate transformer types to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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) 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.graph.transform_node; 5 library barback.graph.transform_node;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import '../asset/asset.dart'; 9 import '../asset/asset.dart';
10 import '../asset/asset_id.dart'; 10 import '../asset/asset_id.dart';
11 import '../asset/asset_node.dart'; 11 import '../asset/asset_node.dart';
12 import '../errors.dart'; 12 import '../errors.dart';
13 import '../log.dart'; 13 import '../log.dart';
14 import '../transformer/aggregate_transform.dart';
15 import '../transformer/declaring_aggregate_transform.dart';
14 import '../transformer/declaring_transform.dart'; 16 import '../transformer/declaring_transform.dart';
15 import '../transformer/declaring_transformer.dart'; 17 import '../transformer/declaring_transformer.dart';
16 import '../transformer/lazy_transformer.dart'; 18 import '../transformer/lazy_transformer.dart';
17 import '../transformer/transform.dart'; 19 import '../transformer/transform.dart';
18 import '../transformer/transformer.dart'; 20 import '../transformer/transformer.dart';
19 import '../utils.dart';
20 import 'node_status.dart'; 21 import 'node_status.dart';
21 import 'node_streams.dart'; 22 import 'node_streams.dart';
22 import 'phase.dart'; 23 import 'phase.dart';
23 24
24 /// Describes a transform on a set of assets and its relationship to the build 25 /// Describes a transform on a set of assets and its relationship to the build
25 /// dependency graph. 26 /// dependency graph.
26 /// 27 ///
27 /// Keeps track of whether it's dirty and needs to be run and which assets it 28 /// Keeps track of whether it's dirty and needs to be run and which assets it
28 /// depends on. 29 /// depends on.
29 class TransformNode { 30 class TransformNode {
31 /// The aggregate key for this node.
32 final key = true;
33
30 /// The [Phase] that this transform runs in. 34 /// The [Phase] that this transform runs in.
31 final Phase phase; 35 final Phase phase;
32 36
33 /// The [Transformer] to apply to this node's inputs. 37 /// The [Transformer] to apply to this node's inputs.
34 final Transformer transformer; 38 final Transformer transformer;
35 39
36 /// The node for the primary asset this transform depends on. 40 /// The node for the primary asset this transform depends on.
37 final AssetNode primary; 41 final AssetNode primary;
38 42
39 /// A string describing the location of [this] in the transformer graph. 43 /// A string describing the location of [this] in the transformer graph.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } else { 230 } else {
227 _state = _State.NEEDS_APPLY; 231 _state = _State.NEEDS_APPLY;
228 } 232 }
229 } 233 }
230 234
231 /// Runs [transform.declareOutputs] and emits the resulting assets as dirty 235 /// Runs [transform.declareOutputs] and emits the resulting assets as dirty
232 /// assets. 236 /// assets.
233 Future _declareOutputs() { 237 Future _declareOutputs() {
234 if (transformer is! DeclaringTransformer) return new Future.value(); 238 if (transformer is! DeclaringTransformer) return new Future.value();
235 239
236 var controller = new DeclaringTransformController(this); 240 var controller = new DeclaringAggregateTransformController(this);
237 return syncFuture(() { 241 _streams.onLogPool.add(controller.onLog);
238 return (transformer as DeclaringTransformer) 242 controller.idController.add(primary.id);
239 .declareOutputs(controller.transform); 243 return newDeclaringTransform(controller.transform).then((transform) {
244 return (transformer as DeclaringTransformer).declareOutputs(transform);
240 }).then((_) { 245 }).then((_) {
241 if (_isRemoved) return; 246 if (_isRemoved) return;
242 if (controller.loggedError) return; 247 if (controller.loggedError) return;
243 248
244 _consumePrimary = controller.consumePrimary; 249 _consumePrimary = controller.consumedPrimaries.contains(primary.id);
245 _declaredOutputs = controller.outputIds; 250 _declaredOutputs = controller.outputIds;
246 var invalidIds = _declaredOutputs 251 var invalidIds = _declaredOutputs
247 .where((id) => id.package != phase.cascade.package).toSet(); 252 .where((id) => id.package != phase.cascade.package).toSet();
248 for (var id in invalidIds) { 253 for (var id in invalidIds) {
249 _declaredOutputs.remove(id); 254 _declaredOutputs.remove(id);
250 // TODO(nweiz): report this as a warning rather than a failing error. 255 // TODO(nweiz): report this as a warning rather than a failing error.
251 phase.cascade.reportError(new InvalidOutputException(info, id)); 256 phase.cascade.reportError(new InvalidOutputException(info, id));
252 } 257 }
253 258
254 if (!_declaredOutputs.contains(primary.id)) _emitPassThrough(); 259 if (!_declaredOutputs.contains(primary.id)) _emitPassThrough();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 }); 342 });
338 343
339 return node.asset; 344 return node.asset;
340 }); 345 });
341 } 346 }
342 347
343 /// Run [Transformer.apply] as soon as [primary] is available. 348 /// Run [Transformer.apply] as soon as [primary] is available.
344 /// 349 ///
345 /// Returns whether or not an error occurred while running the transformer. 350 /// Returns whether or not an error occurred while running the transformer.
346 Future<bool> _runApply() { 351 Future<bool> _runApply() {
347 var transformController = new TransformController(this); 352 var controller = new AggregateTransformController(this);
348 _streams.onLogPool.add(transformController.onLog); 353 _streams.onLogPool.add(controller.onLog);
349 354
350 return primary.whenAvailable((_) { 355 return primary.whenAvailable((_) {
351 if (_isRemoved) return null; 356 if (_isRemoved) return null;
352 _state = _State.APPLYING; 357 _state = _State.APPLYING;
353 return syncFuture(() => transformer.apply(transformController.transform)); 358 controller.inputController.add(primary.asset);
359 return newTransform(controller.transform).then((transform) {
360 return transformer.apply(transform);
361 });
354 }).then((_) { 362 }).then((_) {
355 if (!_forced && !primary.state.isAvailable) { 363 if (!_forced && !primary.state.isAvailable) {
356 _state = _State.DECLARED; 364 _state = _State.DECLARED;
357 _streams.changeStatus(NodeStatus.IDLE); 365 _streams.changeStatus(NodeStatus.IDLE);
358 return false; 366 return false;
359 } 367 }
360 368
361 if (_isRemoved) return false; 369 if (_isRemoved) return false;
362 if (_state == _State.NEEDS_APPLY) return false; 370 if (_state == _State.NEEDS_APPLY) return false;
363 if (_state == _State.DECLARING) return false; 371 if (_state == _State.DECLARING) return false;
364 if (transformController.loggedError) return true; 372 if (controller.loggedError) return true;
365 _handleApplyResults(transformController); 373 _handleApplyResults(controller);
366 return false; 374 return false;
367 }).catchError((error, stackTrace) { 375 }).catchError((error, stackTrace) {
368 // If the transform became dirty while processing, ignore any errors from 376 // If the transform became dirty while processing, ignore any errors from
369 // it. 377 // it.
370 if (_state == _State.NEEDS_APPLY || _isRemoved) return false; 378 if (_state == _State.NEEDS_APPLY || _isRemoved) return false;
371 379
372 // Catch all transformer errors and pipe them to the results stream. This 380 // Catch all transformer errors and pipe them to the results stream. This
373 // is so a broken transformer doesn't take down the whole graph. 381 // is so a broken transformer doesn't take down the whole graph.
374 phase.cascade.reportError(_wrapException(error, stackTrace)); 382 phase.cascade.reportError(_wrapException(error, stackTrace));
375 return true; 383 return true;
376 }); 384 });
377 } 385 }
378 386
379 /// Handle the results of running [Transformer.apply]. 387 /// Handle the results of running [Transformer.apply].
380 /// 388 ///
381 /// [transformController] should be the controller for the [Transform] passed 389 /// [controller] should be the controller for the [AggegateTransform] passed
382 /// to [Transformer.apply]. 390 /// to [AggregateTransformer.apply].
383 void _handleApplyResults(TransformController transformController) { 391 void _handleApplyResults(AggregateTransformController controller) {
384 _consumePrimary = transformController.consumePrimary; 392 _consumePrimary = controller.consumedPrimaries.contains(primary.id);
385 393
386 var newOutputs = transformController.outputs; 394 var newOutputs = controller.outputs;
387 // Any ids that are for a different package are invalid. 395 // Any ids that are for a different package are invalid.
388 var invalidIds = newOutputs 396 var invalidIds = newOutputs
389 .map((asset) => asset.id) 397 .map((asset) => asset.id)
390 .where((id) => id.package != phase.cascade.package) 398 .where((id) => id.package != phase.cascade.package)
391 .toSet(); 399 .toSet();
392 for (var id in invalidIds) { 400 for (var id in invalidIds) {
393 newOutputs.removeId(id); 401 newOutputs.removeId(id);
394 // TODO(nweiz): report this as a warning rather than a failing error. 402 // TODO(nweiz): report this as a warning rather than a failing error.
395 phase.cascade.reportError(new InvalidOutputException(info, id)); 403 phase.cascade.reportError(new InvalidOutputException(info, id));
396 } 404 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 /// If an input changes, this will transition to [DECLARED] if the transform 534 /// If an input changes, this will transition to [DECLARED] if the transform
527 /// is deferred and [APPLYING] otherwise. 535 /// is deferred and [APPLYING] otherwise.
528 static final APPLIED = const _State._("applied"); 536 static final APPLIED = const _State._("applied");
529 537
530 final String name; 538 final String name;
531 539
532 const _State._(this.name); 540 const _State._(this.name);
533 541
534 String toString() => name; 542 String toString() => name;
535 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698