Skip to content

Commit

Permalink
Update code for NestedSet not implementing Iterable
Browse files Browse the repository at this point in the history
This is the last significant code change before making NestedSet not
implement Iterable.

PiperOrigin-RevId: 289824349
  • Loading branch information
ulfjack authored and Copybara-Service committed Jan 15, 2020
1 parent 8cb336a commit a928a5f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.ArrayList;
Expand Down Expand Up @@ -200,12 +201,11 @@ public static Set<TreeFileArtifact> asTreeFileArtifacts(
*
* <p>Non-middleman artifacts are returned untouched.
*/
public static List<ActionInput> expandArtifacts(Iterable<? extends ActionInput> inputs,
ArtifactExpander artifactExpander) {

public static List<ActionInput> expandArtifacts(
NestedSet<? extends ActionInput> inputs, ArtifactExpander artifactExpander) {
List<ActionInput> result = new ArrayList<>();
List<Artifact> containedArtifacts = new ArrayList<>();
for (ActionInput input : inputs) {
for (ActionInput input : inputs.toList()) {
if (!(input instanceof Artifact)) {
result.add(input);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
import com.google.devtools.build.lib.actions.RunfilesSupplier;
import com.google.devtools.build.lib.actions.Spawn;
import com.google.devtools.build.lib.actions.cache.VirtualActionInput.EmptyActionInput;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -126,7 +127,7 @@ void addRunfilesToInputs(
if (expandTreeArtifactsInRunfiles && localArtifact.isTreeArtifact()) {
List<ActionInput> expandedInputs =
ActionInputHelper.expandArtifacts(
Collections.singletonList(localArtifact), artifactExpander);
NestedSetBuilder.create(Order.STABLE_ORDER, localArtifact), artifactExpander);
for (ActionInput input : expandedInputs) {
addMapping(
inputMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public TestRunnerSpawn createTestRunnerSpawn(
ImmutableMap.of(),
/*inputs=*/ action.getInputs(),
action.getConfiguration().getFragment(TestConfiguration.class).isPersistentTestRunner()
? NestedSetBuilder.wrap(Order.STABLE_ORDER, action.getTools())
? action.getTools()
: NestedSetBuilder.emptySet(Order.STABLE_ORDER),
ImmutableSet.copyOf(action.getSpawnOutputs()),
localResourceUsage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,23 @@ public void testOrderIndependenceOfTreeArtifactContents() throws Exception {
public void testActionExpansion() throws Exception {
WriteInputToFilesAction action = new WriteInputToFilesAction(in, outOneFileOne, outOneFileTwo);

CopyTreeAction actionTwo = new CopyTreeAction(
ImmutableList.of(outOneFileOne, outOneFileTwo),
ImmutableList.of(outTwoFileOne, outTwoFileTwo)) {
@Override
public void executeTestBehavior(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException {
super.executeTestBehavior(actionExecutionContext);

Collection<ActionInput> expanded =
ActionInputHelper.expandArtifacts(ImmutableList.of(outOne),
actionExecutionContext.getArtifactExpander());
// Only files registered should show up here.
assertThat(expanded).containsExactly(outOneFileOne, outOneFileTwo);
}
};
CopyTreeAction actionTwo =
new CopyTreeAction(
ImmutableList.of(outOneFileOne, outOneFileTwo),
ImmutableList.of(outTwoFileOne, outTwoFileTwo)) {
@Override
public void executeTestBehavior(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException {
super.executeTestBehavior(actionExecutionContext);

Collection<ActionInput> expanded =
ActionInputHelper.expandArtifacts(
NestedSetBuilder.create(Order.STABLE_ORDER, outOne),
actionExecutionContext.getArtifactExpander());
// Only files registered should show up here.
assertThat(expanded).containsExactly(outOneFileOne, outOneFileTwo);
}
};

registerAction(action);
registerAction(actionTwo);
Expand Down

0 comments on commit a928a5f

Please sign in to comment.