Skip to content

Commit

Permalink
Simplify SkyFunctionEnvironmentForTesting
Browse files Browse the repository at this point in the history
Its getValueOrUntypedExceptions method makes a redundant call to
buildDriver, given its call to skyframeExecutor.

RELNOTES: None.
PiperOrigin-RevId: 232888986
  • Loading branch information
anakanemison authored and Copybara-Service committed Feb 7, 2019
1 parent f02a20c commit da75b71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,37 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.util.ResourceUsage;
import com.google.devtools.build.skyframe.AbstractSkyFunctionEnvironment;
import com.google.devtools.build.skyframe.BuildDriver;
import com.google.devtools.build.skyframe.EvaluationContext;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.build.skyframe.ValueOrUntypedException;
import java.util.Map;

/** A skyframe environment that can be used to evaluate arbitrary skykeys for testing. */
/**
* A {@link SkyFunction.Environment} backed by a {@link SkyframeExecutor} that can be used to
* evaluate arbitrary {@link SkyKey}s for testing.
*/
public class SkyFunctionEnvironmentForTesting extends AbstractSkyFunctionEnvironment
implements SkyFunction.Environment {

private final BuildDriver buildDriver;
private final ExtendedEventHandler eventHandler;
private final SkyframeExecutor skyframeExecutor;

/** Creates a SkyFunctionEnvironmentForTesting that uses a BuildDriver to evaluate skykeys. */
public SkyFunctionEnvironmentForTesting(
BuildDriver buildDriver,
ExtendedEventHandler eventHandler,
SkyframeExecutor skyframeExecutor) {
this.buildDriver = buildDriver;
SkyFunctionEnvironmentForTesting(
ExtendedEventHandler eventHandler, SkyframeExecutor skyframeExecutor) {
this.eventHandler = eventHandler;
this.skyframeExecutor = skyframeExecutor;
}

@Override
protected Map<SkyKey, ValueOrUntypedException> getValueOrUntypedExceptions(
Iterable<? extends SkyKey> depKeys) throws InterruptedException {
Iterable<? extends SkyKey> depKeys) {
ImmutableMap.Builder<SkyKey, ValueOrUntypedException> resultMap = ImmutableMap.builder();
Iterable<SkyKey> keysToEvaluate = ImmutableList.copyOf(depKeys);
EvaluationContext evaluationContext =
EvaluationContext.newBuilder()
.setKeepGoing(true)
.setNumThreads(ResourceUsage.getAvailableProcessors())
.setEventHander(eventHandler)
.build();
EvaluationResult<SkyValue> evaluationResult =
skyframeExecutor.evaluateSkyKeys(eventHandler, keysToEvaluate, true);
buildDriver.evaluate(depKeys, evaluationContext);
for (SkyKey depKey : ImmutableSet.copyOf(depKeys)) {
resultMap.put(depKey, ValueOrUntypedException.ofValueUntyped(evaluationResult.get(depKey)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ static Root maybeTransformRootForRepository(Root packageRoot, RepositoryName rep
@VisibleForTesting
public SkyFunctionEnvironmentForTesting getSkyFunctionEnvironmentForTesting(
ExtendedEventHandler eventHandler) {
return new SkyFunctionEnvironmentForTesting(buildDriver, eventHandler, this);
return new SkyFunctionEnvironmentForTesting(eventHandler, this);
}

/**
Expand Down

0 comments on commit da75b71

Please sign in to comment.