Skip to content

Commit

Permalink
BuildViewForTesting should directly call into ConfiguredTargetFunction.
Browse files Browse the repository at this point in the history
Previously it was trying to replicate the code, but wasn't exact.

PiperOrigin-RevId: 372343711
  • Loading branch information
katre authored and copybara-github committed May 6, 2021
1 parent 9b18d95 commit 762b5d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public SkyValue compute(SkyKey key, Environment env) throws ConfiguredTargetFunc
*/
@VisibleForTesting
@Nullable
static ToolchainCollection<UnloadedToolchainContext> computeUnloadedToolchainContexts(
public static ToolchainCollection<UnloadedToolchainContext> computeUnloadedToolchainContexts(
Environment env,
RuleClassProvider ruleClassProvider,
TargetAndConfiguration targetAndConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.ExecGroup;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
import com.google.devtools.build.lib.packages.PackageSpecification;
Expand All @@ -99,6 +98,7 @@
import com.google.devtools.build.lib.skyframe.AspectValueKey.AspectKey;
import com.google.devtools.build.lib.skyframe.BuildConfigurationValue;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
import com.google.devtools.build.lib.skyframe.PackageValue;
import com.google.devtools.build.lib.skyframe.SkyFunctionEnvironmentForTesting;
Expand All @@ -107,17 +107,14 @@
import com.google.devtools.build.lib.skyframe.SkyframeExecutorWrappingWalkableGraph;
import com.google.devtools.build.lib.skyframe.StarlarkBuiltinsValue;
import com.google.devtools.build.lib.skyframe.TargetPatternPhaseValue;
import com.google.devtools.build.lib.skyframe.ToolchainContextKey;
import com.google.devtools.build.lib.skyframe.ToolchainException;
import com.google.devtools.build.lib.skyframe.UnloadedToolchainContext;
import com.google.devtools.build.lib.util.OrderedSetMultimap;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.ValueOrException;
import com.google.devtools.build.skyframe.Version;
import com.google.devtools.build.skyframe.WalkableGraph;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -621,51 +618,16 @@ public RuleContext getRuleContextForTesting(
Event.error("Failed to get target when trying to get rule context for testing"));
throw new IllegalStateException(e);
}
ImmutableSet<Label> requiredToolchains =
target.getAssociatedRule().getRuleClassObject().getRequiredToolchains();
ImmutableMap<String, ExecGroup> execGroups =
target.getAssociatedRule().getRuleClassObject().getExecGroups();

SkyFunctionEnvironmentForTesting skyfunctionEnvironment =
skyframeExecutor.getSkyFunctionEnvironmentForTesting(eventHandler);

Map<String, ToolchainContextKey> toolchainContextKeys = new HashMap<>();
BuildConfigurationValue.Key configurationKey = BuildConfigurationValue.key(targetConfig);
for (Map.Entry<String, ExecGroup> execGroup : execGroups.entrySet()) {
toolchainContextKeys.put(
execGroup.getKey(),
ToolchainContextKey.key()
.configurationKey(configurationKey)
.requiredToolchainTypeLabels(execGroup.getValue().requiredToolchains())
.build());
}
String targetUnloadedToolchainContextKey = "target-unloaded-toolchain-context";
toolchainContextKeys.put(
targetUnloadedToolchainContextKey,
ToolchainContextKey.key()
.configurationKey(configurationKey)
.requiredToolchainTypeLabels(requiredToolchains)
.build());

Map<SkyKey, ValueOrException<ToolchainException>> values =
skyfunctionEnvironment.getValuesOrThrow(
toolchainContextKeys.values(), ToolchainException.class);

ToolchainCollection.Builder<UnloadedToolchainContext> unloadedToolchainContexts =
ToolchainCollection.builder();
for (Map.Entry<String, ToolchainContextKey> unloadedToolchainContextKey :
toolchainContextKeys.entrySet()) {
UnloadedToolchainContext unloadedToolchainContext =
(UnloadedToolchainContext) values.get(unloadedToolchainContextKey.getValue()).get();
String execGroup = unloadedToolchainContextKey.getKey();
if (execGroup.equals(targetUnloadedToolchainContextKey)) {
unloadedToolchainContexts.addDefaultContext(unloadedToolchainContext);
} else {
unloadedToolchainContexts.addContext(execGroup, unloadedToolchainContext);
}
}

ToolchainCollection<UnloadedToolchainContext> unloadedToolchainCollection =
unloadedToolchainContexts.build();
ConfiguredTargetFunction.computeUnloadedToolchainContexts(
skyfunctionEnvironment,
ruleClassProvider,
new TargetAndConfiguration(target.getAssociatedRule(), targetConfig),
null);

OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> prerequisiteMap =
getPrerequisiteMapForTesting(
Expand Down

0 comments on commit 762b5d8

Please sign in to comment.