use of com.google.devtools.build.skyframe.DelegatingWalkableGraph in project bazel by bazelbuild.
the class SkyframeLabelVisitorTestCase method getVisitedLabels.
/**
* Returns the set of labels that were visited in the loading of the given starting labels.
* Semantics are somewhat subtle in case of errors. The returned set always contains the starting
* labels, even if they were not successfully loaded, but does not contain other unsuccessfully
* loaded targets.
*/
public static Set<Label> getVisitedLabels(Iterable<Label> startingLabels, SkyframeExecutor skyframeExecutor) throws InterruptedException {
final WalkableGraph graph = new DelegatingWalkableGraph(((InMemoryMemoizingEvaluator) skyframeExecutor.getEvaluatorForTesting()).getGraphForTesting());
List<SkyKey> startingKeys = new ArrayList<>();
for (Label label : startingLabels) {
startingKeys.add(TransitiveTargetValue.key(label));
}
Iterable<SkyKey> nodesToVisit = new ArrayList<>(startingKeys);
Set<SkyKey> visitedNodes = new HashSet<>();
while (!Iterables.isEmpty(nodesToVisit)) {
List<SkyKey> existingNodes = new ArrayList<>();
for (SkyKey key : nodesToVisit) {
if (exists(key, graph) && graph.getValue(key) != null && visitedNodes.add(key)) {
existingNodes.add(key);
}
}
nodesToVisit = Iterables.filter(Iterables.concat(graph.getDirectDeps(existingNodes).values()), new Predicate<SkyKey>() {
@Override
public boolean apply(SkyKey skyKey) {
return skyKey.functionName().equals(SkyFunctions.TRANSITIVE_TARGET);
}
});
}
visitedNodes.addAll(startingKeys);
return ImmutableSet.copyOf(Collections2.transform(visitedNodes, new Function<SkyKey, Label>() {
@Override
public Label apply(SkyKey skyKey) {
return (Label) skyKey.argument();
}
}));
}
Aggregations