From 77c15eabc55d15f473f8c74a236c428f1875c0c2 Mon Sep 17 00:00:00 2001
From: "nweiz@google.com" <nweiz@google.com>
Date: Mon, 13 Oct 2014 23:10:29 +0000
Subject: [PATCH] "pub get" doesn't choke on previously-cached unknown
 transformers.

BUG=https://code.google.com/p/dart/issues/detail?id=21298
R=alanknight@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@41087 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/barback/transformer_cache.dart |  4 ++
 test/transformer/cache_test.dart       | 57 ++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/lib/src/barback/transformer_cache.dart b/lib/src/barback/transformer_cache.dart
index 5433ce15..e6c9a538 100644
--- a/lib/src/barback/transformer_cache.dart
+++ b/lib/src/barback/transformer_cache.dart
@@ -56,6 +56,10 @@ class TransformerCache {
   /// Clear the cache if it depends on any package in [changedPackages].
   void clearIfOutdated(Set<String> changedPackages) {
     var snapshotDependencies = unionAll(_oldTransformers.map((id) {
+      // If the transformer cache contains transformers we don't know about,
+      // that's fine; we just won't load them.
+      if (!_graph.packages.containsKey(id.package)) return new Set();
+
       return _graph.transitiveDependencies(id.package)
           .map((package) => package.name).toSet();
     }));
diff --git a/test/transformer/cache_test.dart b/test/transformer/cache_test.dart
index 270d307c..d4a51a0f 100644
--- a/test/transformer/cache_test.dart
+++ b/test/transformer/cache_test.dart
@@ -4,6 +4,7 @@
 
 library pub_tests;
 
+import 'package:scheduled_test/scheduled_stream.dart';
 import 'package:scheduled_test/scheduled_test.dart';
 
 import '../descriptor.dart' as d;
@@ -53,6 +54,8 @@ void setUp() {
         d.file("transformer.dart", replaceTransformer("Goodbye", "See ya"))
       ])
     ]);
+
+    builder.serve("baz", "1.2.3");
   });
 
   d.dir(appPath, [
@@ -266,6 +269,60 @@ main() {
     process.stdout.expect("See ya!");
     process.shouldExit();
   });
+
+  // Issue 21298.
+  integration("doesn't recache when a transformer is removed", () {
+    setUp();
+
+    d.dir(appPath, [
+      d.pubspec({
+        "name": "myapp",
+        "dependencies": {
+          "foo": "1.2.3",
+          "bar": "1.2.3"
+        },
+        "transformers": ["foo", "bar"]
+      }),
+      d.dir("bin", [
+        d.file("myapp.dart", "main() => print('Hello!');")
+      ])
+    ]).create();
+
+    var process = pubRun(args: ['myapp']);
+    process.stdout.expect("See ya!");
+    process.shouldExit();
+
+    d.dir(appPath, [
+      d.pubspec({
+        "name": "myapp",
+        "dependencies": {
+          "foo": "1.2.3",
+          // Add a new dependency to trigger another "pub get". This works
+          // around issue 20498.
+          "baz": "1.2.3"
+        },
+        "transformers": ["foo"]
+      }),
+      d.dir("bin", [
+        d.file("myapp.dart", "main() => print('Hello!');")
+      ])
+    ]).create();
+
+    process = pubRun(args: ['myapp']);
+    process.stdout.expect(
+        "Your pubspec has changed, so we need to update your lockfile:");
+    process.stdout.expect(consumeThrough("Goodbye!"));
+    process.shouldExit();
+
+    // "bar" should still be in the manifest, since there's no reason to
+    // recompile the cache.
+    d.dir(appPath, [
+      d.dir(".pub/transformers", [
+        d.file("manifest.txt", "0.1.2+3\nbar,foo"),
+        d.matcherFile("transformers.snapshot", isNot(isEmpty))
+      ])
+    ]).validate();
+  });
 }
 
 String replaceTransformer(String input, String output) {
-- 
GitLab