From 5589f499faa87ea62e9a8a329ee698493710cc63 Mon Sep 17 00:00:00 2001 From: "nweiz@google.com" Date: Wed, 23 Oct 2013 21:19:15 +0000 Subject: [PATCH] Don't return outputs from a removed PhaseInput. Also clean up a few things in Phase. R=alanknight@google.com Review URL: https://codereview.chromium.org//37813002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29127 260f80e4-7a28-3924-810f-c04153c831b5 --- pkg/barback/lib/src/phase.dart | 8 +++---- pkg/barback/lib/src/phase_input.dart | 10 ++++++-- .../test/package_graph/transform_test.dart | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/pkg/barback/lib/src/phase.dart b/pkg/barback/lib/src/phase.dart index ab39f7170ba..8680e6017b0 100644 --- a/pkg/barback/lib/src/phase.dart +++ b/pkg/barback/lib/src/phase.dart @@ -281,13 +281,11 @@ class Phase { if (!input.isDirty) return new Future.value(new Set()); return input.process().then(_handleOutputs); })); - outputFutures.addAll(_groups.values.map((input) { - if (!input.isDirty) return new Future.value(new Set()); - return input.process().then(_handleOutputs); + outputFutures.addAll(_groups.values.map((group) { + if (!group.isDirty) return new Future.value(new Set()); + return group.process().then(_handleOutputs); })); - // TODO(nweiz): handle pass-through. - return Future.wait(outputFutures).then((_) { // Report collisions in a deterministic order. outputIds = outputIds.toList(); diff --git a/pkg/barback/lib/src/phase_input.dart b/pkg/barback/lib/src/phase_input.dart index 552fa5daf9f..1b96ee0de49 100644 --- a/pkg/barback/lib/src/phase_input.dart +++ b/pkg/barback/lib/src/phase_input.dart @@ -273,9 +273,15 @@ class PhaseInput { } /// Processes the transforms for this input. + /// + /// Returns the set of newly-created asset nodes that transforms have emitted + /// for this input. The assets returned this way are guaranteed not to be + /// [AssetState.REMOVED]. Future> process() { - if (_adjustTransformersFuture == null) return _processTransforms(); - return _waitForTransformers(() => _processTransforms()); + return _waitForTransformers(() => _processTransforms()).then((outputs) { + if (input.state.isRemoved) return new Set(); + return outputs; + }); } /// Runs [callback] once all the transformers are adjusted correctly and the diff --git a/pkg/barback/test/package_graph/transform_test.dart b/pkg/barback/test/package_graph/transform_test.dart index 14aff9fabcf..ae097a6f4f6 100644 --- a/pkg/barback/test/package_graph/transform_test.dart +++ b/pkg/barback/test/package_graph/transform_test.dart @@ -806,6 +806,30 @@ main() { buildShouldSucceed(); }); + test("one transformer takes a long time while the other finishes, then " + "the input is removed", () { + var rewrite1 = new RewriteTransformer("txt", "out1"); + var rewrite2 = new RewriteTransformer("txt", "out2"); + initGraph(["app|foo.txt"], {"app": [[rewrite1, rewrite2]]}); + + rewrite1.pauseApply(); + + updateSources(["app|foo.txt"]); + + // Wait for rewrite1 to pause and rewrite2 to finish. + schedule(pumpEventQueue); + + removeSources(["app|foo.txt"]); + + // Make sure the removal is processed completely before we restart rewrite2. + schedule(pumpEventQueue); + rewrite1.resumeApply(); + + buildShouldSucceed(); + expectNoAsset("app|foo.out1"); + expectNoAsset("app|foo.out2"); + }); + group("pass-through", () { test("passes an asset through a phase in which no transforms apply", () { initGraph([