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

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

Issue 16854005: First pass at build dependency graph for barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Handle unprovided sources and errors a bit better. Created 7 years, 6 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
« no previous file with comments | « pkg/barback/lib/src/transform.dart ('k') | pkg/barback/lib/src/transformer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.transform_node;
6
7 import 'dart:async';
8
9 import 'asset.dart';
10 import 'asset_graph.dart';
11 import 'asset_id.dart';
12 import 'asset_node.dart';
13 import 'errors.dart';
14 import 'phase.dart';
15 import 'transform.dart';
16 import 'transformer.dart';
17
18 /// Describes a transform on a set of assets and its relationship to the build
19 /// dependency graph.
20 ///
21 /// Keeps track of whether it's dirty and needs to be run and which assets it
22 /// depends on.
23 class TransformNode {
24 /// The [Phase] that this transform runs in.
25 final Phase phase;
26
27 /// The [Transformer] to apply to this node's inputs.
28 final Transformer _transformer;
29
30 /// The node for the primary asset this transform depends on.
31 final AssetNode primary;
32
33 /// True if an input has been modified since the last time this transform
34 /// was run.
35 bool get isDirty => _isDirty;
36 var _isDirty = true;
37
38 /// The inputs read by this transform the last time it was run.
39 ///
40 /// Used to tell if an input was removed in a later run.
41 var _inputs = new Set<AssetNode>();
42
43 /// The outputs created by this transform the last time it was run.
44 ///
45 /// Used to tell if an output was removed in a later run.
46 var _outputs = new Set<AssetId>();
47
48 TransformNode(this.phase, this._transformer, this.primary);
49
50 /// Marks this transform as needing to be run.
51 void dirty() {
52 _isDirty = true;
53 }
54
55 /// Applies this transform.
56 ///
57 /// Returns a [TransformOutputs] describing the resulting outputs compared to
58 /// previous runs.
59 Future<TransformOutputs> apply() {
60 var newInputs = new Set<AssetNode>();
61 var newOutputs = new Map<AssetId, Asset>();
62 var transform = createTransform(this, newInputs, newOutputs);
63 return _transformer.apply(transform).catchError((error) {
64 // Catch all transformer errors and pipe them to the results stream.
65 // This is so a broken transformer doesn't take down the whole graph.
66 phase.graph.reportError(error);
67
68 // Don't allow partial results from a failed transform.
69 newOutputs.clear();
70 }).then((_) {
71 _isDirty = false;
72
73 // Stop watching any inputs that were removed.
74 for (var oldInput in _inputs) {
75 oldInput.consumers.remove(this);
76 }
77
78 // Watch any new inputs so this transform will be re-processed when an
79 // input is modified.
80 for (var newInput in newInputs) {
81 newInput.consumers.add(this);
82 }
83
84 _inputs = newInputs;
85
86 // See which outputs are missing from the last run.
87 var outputIds = newOutputs.keys.toSet();
88 var removed = _outputs.difference(outputIds);
89 _outputs = outputIds;
90
91 return new TransformOutputs(newOutputs, removed);
92 });
93 }
94 }
95
96 /// The result of running a [Transform], compared to the previous time it was
97 /// applied.
98 class TransformOutputs {
99 /// The outputs that are new or were modified since the last run.
100 final Map<AssetId, Asset> updated;
101
102 /// The outputs that were created by the previous run but were not generated
103 /// by the most recent run.
104 final Set<AssetId> removed;
105
106 TransformOutputs(this.updated, this.removed);
107 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/transform.dart ('k') | pkg/barback/lib/src/transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698