diff options
author | 2015-08-20 20:06:16 +0000 | |
---|---|---|
committer | 2015-08-21 09:43:37 +0000 | |
commit | a40e7b7b1f8c94f4613f40a5ca4cc55ec9d5d1dd (patch) | |
tree | 1a8005421a2450053d2342e1abf088768a760518 /src/main/java/com/google/devtools | |
parent | 7d90353076470a51fe2abe4815e9b78df3faf208 (diff) |
Filter out targets not in the universe (as defined by the lack of transitive traversal values) from queries.
--
MOS_MIGRATED_REVID=101151407
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java | 27 |
1 files changed, 20 insertions, 7 deletions
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 4e79439088..17ecb747da 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 @@ -366,6 +366,16 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> { } } + private Set<Target> filterTargetsNotInGraph(Set<Target> targets) { + Map<Target, SkyKey> map = Maps.toMap(targets, TARGET_TO_SKY_KEY); + Set<SkyKey> present = graph.getDoneValues(map.values()).keySet(); + if (present.size() == targets.size()) { + // Optimize for case of all targets being in graph. + return targets; + } + return Maps.filterValues(map, Predicates.in(present)).keySet(); + } + @Override protected Map<String, Set<Target>> preloadOrThrow( QueryExpression caller, Collection<String> patterns) @@ -406,7 +416,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> { targetPatternKey.getPolicy(), pkgPath); TargetPattern parsedPattern = targetPatternKey.getParsedPattern(); try { - result.put(pattern, parsedPattern.eval(resolver).getTargets()); + result.put(pattern, filterTargetsNotInGraph(parsedPattern.eval(resolver).getTargets())); } catch (TargetParsingException e) { targetParsingException = e; } catch (InterruptedException e) { @@ -481,13 +491,16 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> { return result.build(); } + private static final Function<Target, SkyKey> TARGET_TO_SKY_KEY = + new Function<Target, SkyKey>() { + @Override + public SkyKey apply(Target target) { + return TransitiveTraversalValue.key(target.getLabel()); + } + }; + private Iterable<SkyKey> makeKeys(Iterable<Target> targets) { - return Iterables.transform(targets, new Function<Target, SkyKey>() { - @Override - public SkyKey apply(Target target) { - return TransitiveTraversalValue.key(target.getLabel()); - } - }); + return Iterables.transform(targets, TARGET_TO_SKY_KEY); } @Override |