Fix SkyQuery bug where we weren't respecting the package blacklist. We do this by changing both the relevant Skyframe and the SkyQuery code to propagate (minimal!) blacklist information in the SkyKeys themselves.

There are other approaches to solving this problem, but I like how this solution doesn't involve duplication of logic. Also, it has the following nice benefit: previously, RecursiveDirectoryTraversalFunction would declare a dep on the blacklist for every directory traversed which adds an edge for each directory traversed.

--
MOS_MIGRATED_REVID=120049635
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index a984edf..c7b9ba8 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -56,6 +56,7 @@
 import com.google.devtools.build.lib.query2.engine.RdepsFunction;
 import com.google.devtools.build.lib.query2.engine.TargetLiteral;
 import com.google.devtools.build.lib.query2.engine.Uniquifier;
+import com.google.devtools.build.lib.skyframe.BlacklistedPackagePrefixesValue;
 import com.google.devtools.build.lib.skyframe.FileValue;
 import com.google.devtools.build.lib.skyframe.GraphBackedRecursivePackageProvider;
 import com.google.devtools.build.lib.skyframe.PackageLookupValue;
@@ -108,6 +109,7 @@
   protected WalkableGraph graph;
 
   private ImmutableList<TargetPatternKey> universeTargetPatternKeys;
+  private ImmutableSet<PathFragment> blacklistPatterns;
 
   private final Map<String, Set<Label>> precomputedPatterns = new HashMap<>();
   private final BlazeTargetAccessor accessor = new BlazeTargetAccessor(this);
@@ -156,6 +158,11 @@
     }
     graph = result.getWalkableGraph();
 
+    blacklistPatterns = 
+        Preconditions.checkNotNull(
+            (BlacklistedPackagePrefixesValue) graph.getValue(BlacklistedPackagePrefixesValue.key()))
+        .getPatterns();
+
     SkyKey universeKey = graphFactory.getUniverseKey(universeScope, parserPrefix);
     universeTargetPatternKeys =
         PrepareDepsOfPatternsFunction.getTargetPatternKeys(
@@ -457,9 +464,8 @@
                 TargetPatternValue.key(
                         pattern, TargetPatternEvaluator.DEFAULT_FILTERING_POLICY, parserPrefix)
                     .argument());
-        GraphBackedRecursivePackageProvider provider =
-            new GraphBackedRecursivePackageProvider(graph, universeTargetPatternKeys, pkgPath);
-
+        GraphBackedRecursivePackageProvider provider = new GraphBackedRecursivePackageProvider(
+            graph, universeTargetPatternKeys, pkgPath);
         ExecutorService threadPool = Executors.newFixedThreadPool(
             Runtime.getRuntime().availableProcessors(),
             new ThreadFactoryBuilder().setNameFormat("GetPackages-%d").build());
@@ -467,9 +473,11 @@
             new RecursivePackageProviderBackedTargetPatternResolver(
                 provider, eventHandler, targetPatternKey.getPolicy(), threadPool);
         TargetPattern parsedPattern = targetPatternKey.getParsedPattern();
+        ImmutableSet<PathFragment> subdirectoriesToExclude =
+            targetPatternKey.getAllSubdirectoriesToExclude(blacklistPatterns);
         FilteringBatchingUniquifyingCallback wrapper =
             new FilteringBatchingUniquifyingCallback(callback);
-        parsedPattern.eval(resolver, wrapper, QueryException.class);
+        parsedPattern.eval(resolver, subdirectoriesToExclude, wrapper, QueryException.class);
         wrapper.processLastPending();
       } catch (TargetParsingException e) {
         reportBuildFileError(owner, e.getMessage());