Convert SkyQueryEnvironment#buildTransitiveClosure to use batch operations.
--
MOS_MIGRATED_REVID=96433497
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 473c69d..9f4aa40 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
@@ -17,7 +17,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-import com.google.common.base.Supplier;
+import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -25,7 +25,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.cmdline.TargetPattern;
@@ -57,7 +56,6 @@
import com.google.devtools.build.skyframe.WalkableGraph.WalkableGraphFactory;
import java.util.ArrayDeque;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
@@ -327,13 +325,12 @@
throws QueryException {
// Everything has already been loaded, so here we just check for errors so that we can
// pre-emptively throw/report if needed.
- for (Target target : targets) {
- SkyKey targetKey = TransitiveTargetValue.key(target.getLabel());
- checkExistence(targetKey);
- Exception exception = graph.getException(targetKey);
- if (exception != null) {
- reportBuildFileError(caller, exception.getMessage());
+ for (Map.Entry<SkyKey, Exception> entry :
+ graph.getMissingAndExceptions(makeKeys(targets)).entrySet()) {
+ if (entry.getValue() == null) {
+ throw new QueryException(entry.getKey().argument() + " does not exist in graph");
}
+ reportBuildFileError(caller, entry.getValue().getMessage());
}
}
@@ -416,14 +413,7 @@
}
private Map<SkyKey, Target> makeTargetsWithAssociations(Iterable<SkyKey> keys) {
- Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = Multimaps.newListMultimap(
- new HashMap<SkyKey, Collection<SkyKey>>(),
- new Supplier<List<SkyKey>>() {
- @Override
- public List<SkyKey> get() {
- return new ArrayList<>();
- }
- });
+ Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = ArrayListMultimap.create();
for (SkyKey key : keys) {
SkyFunctionName functionName = key.functionName();
if (!functionName.equals(SkyFunctions.TRANSITIVE_TARGET)) {
@@ -437,7 +427,7 @@
}
}
ImmutableMap.Builder<SkyKey, Target> result = ImmutableMap.builder();
- Map<SkyKey, SkyValue> packageMap = graph.getValuesMaybe(packageKeyToTargetKeyMap.keySet());
+ Map<SkyKey, SkyValue> packageMap = graph.getDoneValues(packageKeyToTargetKeyMap.keySet());
for (Map.Entry<SkyKey, SkyValue> entry : packageMap.entrySet()) {
for (SkyKey targetKey : packageKeyToTargetKeyMap.get(entry.getKey())) {
try {