Skip to content

Commit

Permalink
Reimplement getInputMapping() using walkInputs()
Browse files Browse the repository at this point in the history
Keep a single way of retreiving the inputs, instead of keeping two
implementations in sync. Using walkInputs() will be slightly slower,
but as getInputMapping() is only called on cache miss, I think the
maintenance problem is more important to solve.
  • Loading branch information
moroten committed Aug 19, 2021
1 parent 452144d commit 9de8564
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.ActionInputHelper;
import com.google.devtools.build.lib.actions.Artifact;
Expand Down Expand Up @@ -44,6 +45,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

Expand Down Expand Up @@ -245,18 +247,32 @@ public SortedMap<PathFragment, ActionInput> getInputMapping(
PathFragment baseDirectory,
MetadataProvider actionInputFileCache)
throws IOException, ForbiddenActionInputException {
Set<Object> visitedNodes = Sets.newConcurrentHashSet();
TreeMap<PathFragment, ActionInput> inputMap = new TreeMap<>();
addInputs(inputMap, spawn.getInputFiles(), artifactExpander, baseDirectory);
addRunfilesToInputs(
inputMap,
spawn.getRunfilesSupplier(),
actionInputFileCache,
artifactExpander,
baseDirectory);
addFilesetManifests(spawn.getFilesetMappings(), inputMap, baseDirectory);
walkInputs(
spawn, artifactExpander, baseDirectory, actionInputFileCache,
(Object nodeKey, SpawnExecutionContext.InputWalker walker) -> {
getInputMappingVisitor(visitedNodes, inputMap, walker);
}
);
return inputMap;
}

private void getInputMappingVisitor(
Set<Object> visitedNodes,
TreeMap<PathFragment, ActionInput> inputMap,
SpawnExecutionContext.InputWalker walker)
throws IOException, ForbiddenActionInputException {
inputMap.putAll(walker.getLeavesInputMapping());
walker.visitNonLeaves(
(Object nodeKey, SpawnExecutionContext.InputWalker subWalker) -> {
if (visitedNodes.add(nodeKey)) {
getInputMappingVisitor(visitedNodes, inputMap, subWalker);
}
}
);
}

public void walkInputs(
Spawn spawn,
ArtifactExpander artifactExpander,
Expand Down

0 comments on commit 9de8564

Please sign in to comment.