Search in sources :

Example 1 with DelegatingWalkableGraph

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();
        }
    }));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Function(com.google.common.base.Function) DelegatingWalkableGraph(com.google.devtools.build.skyframe.DelegatingWalkableGraph) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) DelegatingWalkableGraph(com.google.devtools.build.skyframe.DelegatingWalkableGraph) HashSet(java.util.HashSet) Predicate(com.google.common.base.Predicate)

Aggregations

Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 Label (com.google.devtools.build.lib.cmdline.Label)1 DelegatingWalkableGraph (com.google.devtools.build.skyframe.DelegatingWalkableGraph)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 WalkableGraph (com.google.devtools.build.skyframe.WalkableGraph)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1