Add a bunch of toString methods to internal Barback classes.

These will make it easier to debug barback by making it easier to
inspect the current state.

R=alanknight@google.com
BUG=

Review URL: https://codereview.chromium.org//155213002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32304 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
nweiz@google.com
2014-02-05 00:47:00 +00:00
parent 8b14fbced0
commit 23c2fcd648
9 changed files with 62 additions and 15 deletions
+3 -1
View File
@@ -117,7 +117,7 @@ class AssetCascade {
/// It loads source assets within [package] using [provider].
AssetCascade(this.graph, this.package) {
_onDirtyPool.add(_onDirtyController.stream);
_addPhase(new Phase(this, []));
_addPhase(new Phase(this, [], package));
// Keep track of logged errors so we can know that the build failed.
onLog.listen((entry) {
@@ -308,4 +308,6 @@ class AssetCascade {
return future.then((_) => _process());
});
}
String toString() => "cascade for $package";
}
+4
View File
@@ -137,6 +137,8 @@ class AssetNode {
: id = asset.id,
_asset = asset,
_state = AssetState.AVAILABLE;
String toString() => "$state asset $id";
}
/// The controller for an [AssetNode].
@@ -199,6 +201,8 @@ class AssetNodeController {
node._asset = asset;
node._stateChangeController.add(AssetState.AVAILABLE);
}
String toString() => "controller for $node";
}
// TODO(nweiz): add an error state.
+2
View File
@@ -68,4 +68,6 @@ class AssetSet extends IterableBase<Asset> {
void clear() {
_assets.clear();
}
String toString() => _assets.toString();
}
+12 -4
View File
@@ -13,10 +13,16 @@ import 'phase.dart';
import 'stream_pool.dart';
import 'transformer_group.dart';
/// A class that process all of the phases in a single transformer group.
/// A class that processes all of the phases in a single transformer group.
///
/// A group takes many inputs, processes them, and emits many outputs.
class GroupRunner {
/// The group this runner runs.
final TransformerGroup _group;
/// A string describing the location of [this] in the transformer graph.
final String _location;
/// The phases defined by this group.
final _phases = new List<Phase>();
@@ -46,10 +52,10 @@ class GroupRunner {
/// ensure that it does so.
final _alreadyEmittedOutputs = new Set<AssetNode>();
GroupRunner(AssetCascade cascade, TransformerGroup group) {
var lastPhase = new Phase(cascade, group.phases.first);
GroupRunner(AssetCascade cascade, this._group, this._location) {
var lastPhase = new Phase(cascade, _group.phases.first, _location);
_phases.add(lastPhase);
for (var phase in group.phases.skip(1)) {
for (var phase in _group.phases.skip(1)) {
lastPhase = lastPhase.addPhase(phase);
_phases.add(lastPhase);
}
@@ -91,4 +97,6 @@ class GroupRunner {
return new Future.value(newOutputs);
}
String toString() => "group in phase $_location for $_group";
}
+17 -6
View File
@@ -36,6 +36,12 @@ class Phase {
/// The cascade that owns this phase.
final AssetCascade cascade;
/// A string describing the location of [this] in the transformer graph.
final String _location;
/// The index of [this] in its parent cascade or group.
final int _index;
/// The transformers that can access [inputs].
///
/// Their outputs will be available to the next phase.
@@ -111,12 +117,15 @@ class Phase {
// TODO(nweiz): Rather than passing the cascade and the phase everywhere,
// create an interface that just exposes [getInput]. Emit errors via
// [AssetNode]s.
Phase(this.cascade, Iterable transformers)
Phase(AssetCascade cascade, Iterable transformers, String location)
: this._(cascade, transformers, location, 0);
Phase._(this.cascade, Iterable transformers, this._location, this._index)
: _transformers = transformers.where((op) => op is Transformer).toSet() {
_onDirtyPool.add(_onDirtyController.stream);
for (var group in transformers.where((op) => op is TransformerGroup)) {
var runner = new GroupRunner(cascade, group);
var runner = new GroupRunner(cascade, group, "$_location.$_index");
_groups[group] = runner;
_onDirtyPool.add(runner.onDirty);
_onLogPool.add(runner.onLog);
@@ -148,7 +157,7 @@ class Phase {
});
_inputOrigins.add(node.origin);
var input = new PhaseInput(this, node, _transformers);
var input = new PhaseInput(this, node, _transformers, "$_location.$_index");
_inputs[node.id] = input;
input.input.whenRemoved(() {
_inputOrigins.remove(node.origin);
@@ -205,7 +214,7 @@ class Phase {
}
for (var added in newGroups.difference(oldGroups)) {
var runner = new GroupRunner(cascade, added);
var runner = new GroupRunner(cascade, added, "$_location.$_index");
_groups[added] = runner;
_onDirtyPool.add(runner.onDirty);
_onLogPool.add(runner.onLog);
@@ -224,7 +233,7 @@ class Phase {
/// This may only be called on a phase with no phase following it.
Phase addPhase(Iterable transformers) {
assert(_next == null);
_next = new Phase(cascade, transformers);
_next = new Phase._(cascade, transformers, _location, _index + 1);
for (var output in _outputs.values.toList()) {
// Remove [output]'s listeners because now they should get the asset from
// [_next], rather than this phase. Any transforms consuming [output] will
@@ -305,11 +314,13 @@ class Phase {
if (_outputs.containsKey(asset.id)) {
_outputs[asset.id].add(asset);
} else {
_outputs[asset.id] = new PhaseOutput(this, asset);
_outputs[asset.id] = new PhaseOutput(this, asset, "$_location.$_index");
_outputs[asset.id].onAsset.listen((output) {
if (_next != null) _next.addInput(output);
}, onDone: () => _outputs.remove(asset.id));
if (_next != null) _next.addInput(_outputs[asset.id].output);
}
}
String toString() => "phase $_location.$_index";
}
+9 -2
View File
@@ -24,6 +24,9 @@ class PhaseInput {
/// The phase for which this is an input.
final Phase _phase;
/// A string describing the location of [this] in the transformer graph.
final String _location;
/// The transformers to (potentially) run against [input].
final Set<Transformer> _transformers;
@@ -84,7 +87,8 @@ class PhaseInput {
Stream<LogEntry> get onLog => _onLogPool.stream;
final _onLogPool = new StreamPool<LogEntry>.broadcast();
PhaseInput(this._phase, AssetNode input, Iterable<Transformer> transformers)
PhaseInput(this._phase, AssetNode input, Iterable<Transformer> transformers,
this._location)
: _transformers = transformers.toSet(),
_inputForwarder = new AssetForwarder(input) {
_onDirtyPool.add(_onDirtyController.stream);
@@ -228,7 +232,8 @@ class PhaseInput {
// results.
return transformer.isPrimary(input.asset).then((isPrimary) {
if (!isPrimary) return;
var transform = new TransformNode(_phase, transformer, input);
var transform = new TransformNode(
_phase, transformer, input, _location);
_transforms.add(transform);
_onDirtyPool.add(transform.onDirty);
_onLogPool.add(transform.onLog);
@@ -312,4 +317,6 @@ class PhaseInput {
return transform.apply();
})).then((outputs) => unionAll(outputs));
}
String toString() => "phase input in $_location for $input";
}
+6 -1
View File
@@ -28,6 +28,9 @@ class PhaseOutput {
/// The phase for which this is an output.
final Phase _phase;
/// A string describing the location of [this] in the transformer graph.
final String _location;
/// The asset node for this output.
AssetNode get output => _outputForwarder.node;
AssetForwarder _outputForwarder;
@@ -53,7 +56,7 @@ class PhaseOutput {
output.id);
}
PhaseOutput(this._phase, AssetNode output)
PhaseOutput(this._phase, AssetNode output, this._location)
: _outputForwarder = new AssetForwarder(output) {
assert(!output.state.isRemoved);
add(output);
@@ -109,4 +112,6 @@ class PhaseOutput {
}
});
}
String toString() => "phase output in $_location for $output";
}
+7 -1
View File
@@ -33,6 +33,9 @@ class TransformNode {
/// The node for the primary asset this transform depends on.
final AssetNode primary;
/// A string describing the location of [this] in the transformer graph.
final String _location;
/// The subscription to [primary]'s [AssetNode.onStateChange] stream.
StreamSubscription _primarySubscription;
@@ -64,7 +67,7 @@ class TransformNode {
Stream<LogEntry> get onLog => _onLogController.stream;
final _onLogController = new StreamController<LogEntry>.broadcast(sync: true);
TransformNode(this.phase, this.transformer, this.primary) {
TransformNode(this.phase, this.transformer, this.primary, this._location) {
_primarySubscription = primary.onStateChange.listen((state) {
if (state.isRemoved) {
remove();
@@ -219,4 +222,7 @@ class TransformNode {
var entry = new LogEntry(info, asset, level, message, span);
_onLogController.add(entry);
}
String toString() =>
"transform node in $_location for $transformer on $primary";
}
@@ -25,4 +25,6 @@ class TransformerGroup {
TransformerGroup(Iterable<Iterable> phases)
: this.phases = phases.map((phase) => phase.toList()).toList();
String toString() => "group of $phases";
}