Skip to content

Commit

Permalink
Rename ToolchainResolutionFunction to SingleToolchainResolutionFunction.
Browse files Browse the repository at this point in the history
Part of work on execution transitions, bazelbuild#7935.
  • Loading branch information
katre committed Apr 16, 2019
1 parent 5074514 commit 778635e
Showing 7 changed files with 63 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -38,9 +38,10 @@
import com.google.devtools.build.lib.skyframe.PlatformLookupUtil.InvalidPlatformException;
import com.google.devtools.build.lib.skyframe.RegisteredExecutionPlatformsValue;
import com.google.devtools.build.lib.skyframe.RegisteredToolchainsFunction.InvalidToolchainLabelException;
import com.google.devtools.build.lib.skyframe.SingleToolchainResolutionFunction;
import com.google.devtools.build.lib.skyframe.SingleToolchainResolutionFunction.NoToolchainFoundException;
import com.google.devtools.build.lib.skyframe.SingleToolchainResolutionValue;
import com.google.devtools.build.lib.skyframe.ToolchainException;
import com.google.devtools.build.lib.skyframe.ToolchainResolutionFunction.NoToolchainFoundException;
import com.google.devtools.build.lib.skyframe.ToolchainResolutionValue;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.ValueOrException2;
@@ -114,8 +115,8 @@ public ToolchainResolver setExecConstraintLabels(Set<Label> execConstraintLabels
* com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction} (to load platforms and
* toolchains), to {@link
* com.google.devtools.build.lib.skyframe.RegisteredExecutionPlatformsFunction}, and to {@link
* com.google.devtools.build.lib.skyframe.ToolchainResolutionFunction}. This method return {@code
* null} to signal a SkyFrame restart is needed to resolve dependencies.
* SingleToolchainResolutionFunction}. This method returns {@code null} to signal a SkyFrame
* restart is needed to resolve dependencies.
*/
@Nullable
public UnloadedToolchainContext resolve() throws InterruptedException, ToolchainException {
@@ -286,10 +287,10 @@ private void determineToolchainImplementations(
throws InterruptedException, ToolchainException, ValueMissingException {

// Find the toolchains for the required toolchain types.
List<ToolchainResolutionValue.Key> registeredToolchainKeys = new ArrayList<>();
List<SingleToolchainResolutionValue.Key> registeredToolchainKeys = new ArrayList<>();
for (Label toolchainTypeLabel : requiredToolchainTypeLabels) {
registeredToolchainKeys.add(
ToolchainResolutionValue.key(
SingleToolchainResolutionValue.key(
configurationKey,
toolchainTypeLabel,
platformKeys.targetPlatformKey(),
@@ -315,17 +316,17 @@ private void determineToolchainImplementations(
try {
ValueOrException2<NoToolchainFoundException, InvalidToolchainLabelException>
valueOrException = entry.getValue();
ToolchainResolutionValue toolchainResolutionValue =
(ToolchainResolutionValue) valueOrException.get();
if (toolchainResolutionValue == null) {
SingleToolchainResolutionValue singleToolchainResolutionValue =
(SingleToolchainResolutionValue) valueOrException.get();
if (singleToolchainResolutionValue == null) {
valuesMissing = true;
continue;
}

ToolchainTypeInfo requiredToolchainType = toolchainResolutionValue.toolchainType();
ToolchainTypeInfo requiredToolchainType = singleToolchainResolutionValue.toolchainType();
requiredToolchainTypesBuilder.add(requiredToolchainType);
resolvedToolchains.putAll(
findPlatformsAndLabels(requiredToolchainType, toolchainResolutionValue));
findPlatformsAndLabels(requiredToolchainType, singleToolchainResolutionValue));
} catch (NoToolchainFoundException e) {
// Save the missing type and continue looping to check for more.
missingToolchains.add(e.missingToolchainTypeLabel());
@@ -386,12 +387,13 @@ private void determineToolchainImplementations(
* resolvedToolchains}.
*/
private static Table<ConfiguredTargetKey, ToolchainTypeInfo, Label> findPlatformsAndLabels(
ToolchainTypeInfo requiredToolchainType, ToolchainResolutionValue toolchainResolutionValue) {
ToolchainTypeInfo requiredToolchainType,
SingleToolchainResolutionValue singleToolchainResolutionValue) {

Table<ConfiguredTargetKey, ToolchainTypeInfo, Label> resolvedToolchains =
HashBasedTable.create();
for (Map.Entry<ConfiguredTargetKey, Label> entry :
toolchainResolutionValue.availableToolchainLabels().entrySet()) {
singleToolchainResolutionValue.availableToolchainLabels().entrySet()) {
resolvedToolchains.put(entry.getKey(), requiredToolchainType, entry.getValue());
}
return resolvedToolchains;
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
import java.util.Optional;

/**
* {@link CyclesReporter#SingleCycleReporter} implementation that can handle cycles involving
* {@link CyclesReporter.SingleCycleReporter} implementation that can handle cycles involving
* registered toolchains.
*/
public class RegisteredToolchainsCycleReporter implements CyclesReporter.SingleCycleReporter {
@@ -38,8 +38,8 @@ public class RegisteredToolchainsCycleReporter implements CyclesReporter.SingleC
private static final Predicate<SkyKey> IS_CONFIGURED_TARGET_SKY_KEY =
SkyFunctions.isSkyFunction(SkyFunctions.CONFIGURED_TARGET);

private static final Predicate<SkyKey> IS_TOOLCHAIN_RESOLUTION_SKY_KEY =
SkyFunctions.isSkyFunction(SkyFunctions.TOOLCHAIN_RESOLUTION);
private static final Predicate<SkyKey> IS_SINGLE_TOOLCHAIN_RESOLUTION_SKY_KEY =
SkyFunctions.isSkyFunction(SkyFunctions.SINGLE_TOOLCHAIN_RESOLUTION);

@Override
public boolean maybeReportCycle(
@@ -52,7 +52,7 @@ public boolean maybeReportCycle(
return true;
} else if (!Iterables.any(cycle, IS_REGISTERED_TOOLCHAINS_SKY_KEY)
|| !Iterables.any(cycle, IS_CONFIGURED_TARGET_SKY_KEY)
|| !Iterables.any(cycle, IS_TOOLCHAIN_RESOLUTION_SKY_KEY)) {
|| !Iterables.any(cycle, IS_SINGLE_TOOLCHAIN_RESOLUTION_SKY_KEY)) {
return false;
}

@@ -73,9 +73,9 @@ public String apply(SkyKey input) {
if (input.argument() instanceof RegisteredToolchainsValue.Key) {
return "RegisteredToolchains";
}
if (input.argument() instanceof ToolchainResolutionValue.Key) {
if (input.argument() instanceof SingleToolchainResolutionValue.Key) {
Label toolchainType =
((ToolchainResolutionValue.Key) input.argument()).toolchainTypeLabel();
((SingleToolchainResolutionValue.Key) input.argument()).toolchainTypeLabel();
return String.format("toolchain type %s", toolchainType.toString());
} else {
throw new UnsupportedOperationException();
Original file line number Diff line number Diff line change
@@ -42,14 +42,14 @@
import java.util.Set;
import javax.annotation.Nullable;

/** {@link SkyFunction} which performs toolchain resolution for a class of rules. */
public class ToolchainResolutionFunction implements SkyFunction {
/** {@link SkyFunction} which performs toolchain resolution for a single toolchain type. */
public class SingleToolchainResolutionFunction implements SkyFunction {

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env)
throws ToolchainResolutionFunctionException, InterruptedException {
ToolchainResolutionValue.Key key = (ToolchainResolutionValue.Key) skyKey.argument();
SingleToolchainResolutionValue.Key key = (SingleToolchainResolutionValue.Key) skyKey.argument();

// This call could be combined with the call below, but this SkyFunction is evaluated so rarely
// it's not worth optimizing.
@@ -91,7 +91,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
* platform.
*/
@Nullable
private static ToolchainResolutionValue resolveConstraints(
private static SingleToolchainResolutionValue resolveConstraints(
Label toolchainTypeLabel,
List<ConfiguredTargetKey> availableExecutionPlatformKeys,
ConfiguredTargetKey targetPlatformKey,
@@ -179,7 +179,7 @@ private static ToolchainResolutionValue resolveConstraints(
new NoToolchainFoundException(toolchainTypeLabel));
}

return ToolchainResolutionValue.create(toolchainType, resolvedToolchainLabels);
return SingleToolchainResolutionValue.create(toolchainType, resolvedToolchainLabels);
}

/**
@@ -246,7 +246,9 @@ public Label missingToolchainTypeLabel() {
}
}

/** Used to indicate errors during the computation of an {@link ToolchainResolutionValue}. */
/**
* Used to indicate errors during the computation of an {@link SingleToolchainResolutionValue}.
*/
private static final class ToolchainResolutionFunctionException extends SkyFunctionException {
public ToolchainResolutionFunctionException(NoToolchainFoundException e) {
super(e, Transience.PERSISTENT);
Original file line number Diff line number Diff line change
@@ -26,14 +26,12 @@
import java.util.List;

/**
* A value which represents the map of potential execution platforms and resolved toolchains. This
* value only considers a single toolchain type, which allows for a Skyframe cache per toolchain
* type. Callers will need to consider all toolchain types that are required and merge the results
* together appropriately.
* A value which represents the map of potential execution platforms and resolved toolchains for a
* single toolchain type.This allows for a Skyframe cache per toolchain type.
*/
@AutoCodec
@AutoValue
public abstract class ToolchainResolutionValue implements SkyValue {
public abstract class SingleToolchainResolutionValue implements SkyValue {

// A key representing the input data.
public static Key key(
@@ -45,15 +43,15 @@ public static Key key(
configurationKey, toolchainTypeLabel, targetPlatformKey, availableExecutionPlatformKeys);
}

/** {@link SkyKey} implementation used for {@link ToolchainResolutionFunction}. */
/** {@link SkyKey} implementation used for {@link SingleToolchainResolutionFunction}. */
@AutoCodec
@AutoCodec.VisibleForSerialization
@AutoValue
public abstract static class Key implements SkyKey {

@Override
public SkyFunctionName functionName() {
return SkyFunctions.TOOLCHAIN_RESOLUTION;
return SkyFunctions.SINGLE_TOOLCHAIN_RESOLUTION;
}

abstract BuildConfigurationValue.Key configurationKey();
@@ -70,7 +68,7 @@ static Key create(
Label toolchainTypeLabel,
ConfiguredTargetKey targetPlatformKey,
List<ConfiguredTargetKey> availableExecutionPlatformKeys) {
return new AutoValue_ToolchainResolutionValue_Key(
return new AutoValue_SingleToolchainResolutionValue_Key(
configurationKey,
toolchainTypeLabel,
targetPlatformKey,
@@ -79,10 +77,10 @@ static Key create(
}

@AutoCodec.Instantiator
public static ToolchainResolutionValue create(
public static SingleToolchainResolutionValue create(
ToolchainTypeInfo toolchainType,
ImmutableMap<ConfiguredTargetKey, Label> availableToolchainLabels) {
return new AutoValue_ToolchainResolutionValue(toolchainType, availableToolchainLabels);
return new AutoValue_SingleToolchainResolutionValue(toolchainType, availableToolchainLabels);
}

/** Returns the resolved details about the requested toolchain type. */
Original file line number Diff line number Diff line change
@@ -136,8 +136,8 @@ public final class SkyFunctions {
SkyFunctionName.createHermetic("REGISTERED_EXECUTION_PLATFORMS");
static final SkyFunctionName REGISTERED_TOOLCHAINS =
SkyFunctionName.createHermetic("REGISTERED_TOOLCHAINS");
static final SkyFunctionName TOOLCHAIN_RESOLUTION =
SkyFunctionName.createHermetic("TOOLCHAIN_RESOLUTION");
static final SkyFunctionName SINGLE_TOOLCHAIN_RESOLUTION =
SkyFunctionName.createHermetic("SINGLE_TOOLCHAIN_RESOLUTION");
public static final SkyFunctionName REPOSITORY_MAPPING =
SkyFunctionName.createHermetic("REPOSITORY_MAPPING");
public static final SkyFunctionName RESOLVED_FILE =
Original file line number Diff line number Diff line change
@@ -592,7 +592,7 @@ private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions(PackageFactory p
map.put(
SkyFunctions.REGISTERED_EXECUTION_PLATFORMS, new RegisteredExecutionPlatformsFunction());
map.put(SkyFunctions.REGISTERED_TOOLCHAINS, new RegisteredToolchainsFunction());
map.put(SkyFunctions.TOOLCHAIN_RESOLUTION, new ToolchainResolutionFunction());
map.put(SkyFunctions.SINGLE_TOOLCHAIN_RESOLUTION, new SingleToolchainResolutionFunction());
map.put(SkyFunctions.REPOSITORY_MAPPING, new RepositoryMappingFunction());
map.put(SkyFunctions.RESOLVED_HASH_VALUES, new ResolvedHashesFunction());
map.put(SkyFunctions.RESOLVED_FILE, new ResolvedFileFunction());
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@
import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.StarlarkContext;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
import javax.annotation.Nullable;
@@ -47,9 +46,11 @@
import org.junit.runners.JUnit4;
import org.mockito.Mockito;

/** Tests for {@link ToolchainResolutionValue} and {@link ToolchainResolutionFunction}. */
/**
* Tests for {@link SingleToolchainResolutionValue} and {@link SingleToolchainResolutionFunction}.
*/
@RunWith(JUnit4.class)
public class ToolchainResolutionFunctionTest extends ToolchainTestCase {
public class SingleToolchainResolutionFunctionTest extends ToolchainTestCase {
@AutoCodec @AutoCodec.VisibleForSerialization
static final ConfiguredTargetKey LINUX_CTKEY = Mockito.mock(ConfiguredTargetKey.class);

@@ -72,7 +73,7 @@ private static ConfiguredTargetValue createConfiguredTargetValue(
/*nonceVersion=*/ null);
}

private EvaluationResult<ToolchainResolutionValue> invokeToolchainResolution(SkyKey key)
private EvaluationResult<SingleToolchainResolutionValue> invokeToolchainResolution(SkyKey key)
throws InterruptedException {
ConfiguredTarget mockLinuxTarget = new SerializableConfiguredTarget(linuxPlatform);
ConfiguredTarget mockMacTarget = new SerializableConfiguredTarget(macPlatform);
@@ -97,14 +98,14 @@ private EvaluationResult<ToolchainResolutionValue> invokeToolchainResolution(Sky
@Test
public void testResolution_singleExecutionPlatform() throws Exception {
SkyKey key =
ToolchainResolutionValue.key(
SingleToolchainResolutionValue.key(
targetConfigKey, testToolchainTypeLabel, LINUX_CTKEY, ImmutableList.of(MAC_CTKEY));
EvaluationResult<ToolchainResolutionValue> result = invokeToolchainResolution(key);
EvaluationResult<SingleToolchainResolutionValue> result = invokeToolchainResolution(key);

assertThatEvaluationResult(result).hasNoError();

ToolchainResolutionValue toolchainResolutionValue = result.get(key);
assertThat(toolchainResolutionValue.availableToolchainLabels())
SingleToolchainResolutionValue singleToolchainResolutionValue = result.get(key);
assertThat(singleToolchainResolutionValue.availableToolchainLabels())
.containsExactly(MAC_CTKEY, makeLabel("//toolchain:toolchain_2_impl"));
}

@@ -123,17 +124,17 @@ public void testResolution_multipleExecutionPlatforms() throws Exception {
"'//extra:extra_toolchain')");

SkyKey key =
ToolchainResolutionValue.key(
SingleToolchainResolutionValue.key(
targetConfigKey,
testToolchainTypeLabel,
LINUX_CTKEY,
ImmutableList.of(LINUX_CTKEY, MAC_CTKEY));
EvaluationResult<ToolchainResolutionValue> result = invokeToolchainResolution(key);
EvaluationResult<SingleToolchainResolutionValue> result = invokeToolchainResolution(key);

assertThatEvaluationResult(result).hasNoError();

ToolchainResolutionValue toolchainResolutionValue = result.get(key);
assertThat(toolchainResolutionValue.availableToolchainLabels())
SingleToolchainResolutionValue singleToolchainResolutionValue = result.get(key);
assertThat(singleToolchainResolutionValue.availableToolchainLabels())
.containsExactly(
LINUX_CTKEY,
makeLabel("//extra:extra_toolchain_impl"),
@@ -147,9 +148,9 @@ public void testResolution_noneFound() throws Exception {
rewriteWorkspace();

SkyKey key =
ToolchainResolutionValue.key(
SingleToolchainResolutionValue.key(
targetConfigKey, testToolchainTypeLabel, LINUX_CTKEY, ImmutableList.of(MAC_CTKEY));
EvaluationResult<ToolchainResolutionValue> result = invokeToolchainResolution(key);
EvaluationResult<SingleToolchainResolutionValue> result = invokeToolchainResolution(key);

assertThatEvaluationResult(result)
.hasErrorEntryForKeyThat(key)
@@ -162,30 +163,30 @@ public void testResolution_noneFound() throws Exception {
public void testToolchainResolutionValue_equalsAndHashCode() {
new EqualsTester()
.addEqualityGroup(
ToolchainResolutionValue.create(
SingleToolchainResolutionValue.create(
testToolchainType,
ImmutableMap.of(LINUX_CTKEY, makeLabel("//test:toolchain_impl_1"))),
ToolchainResolutionValue.create(
SingleToolchainResolutionValue.create(
testToolchainType,
ImmutableMap.of(LINUX_CTKEY, makeLabel("//test:toolchain_impl_1"))))
// Different execution platform, same label.
.addEqualityGroup(
ToolchainResolutionValue.create(
SingleToolchainResolutionValue.create(
testToolchainType,
ImmutableMap.of(MAC_CTKEY, makeLabel("//test:toolchain_impl_1"))))
// Same execution platform, different label.
.addEqualityGroup(
ToolchainResolutionValue.create(
SingleToolchainResolutionValue.create(
testToolchainType,
ImmutableMap.of(LINUX_CTKEY, makeLabel("//test:toolchain_impl_2"))))
// Different execution platform, different label.
.addEqualityGroup(
ToolchainResolutionValue.create(
SingleToolchainResolutionValue.create(
testToolchainType,
ImmutableMap.of(MAC_CTKEY, makeLabel("//test:toolchain_impl_2"))))
// Multiple execution platforms.
.addEqualityGroup(
ToolchainResolutionValue.create(
SingleToolchainResolutionValue.create(
testToolchainType,
ImmutableMap.<ConfiguredTargetKey, Label>builder()
.put(LINUX_CTKEY, makeLabel("//test:toolchain_impl_1"))
@@ -263,13 +264,12 @@ public InfoInterface get(Provider.Key providerKey) {
public void repr(SkylarkPrinter printer) {}

@Override
public Object getIndex(Object key, Location loc, StarlarkContext context) throws EvalException {
public Object getIndex(Object key, Location loc, StarlarkContext context) {
return null;
}

@Override
public boolean containsKey(Object key, Location loc, StarlarkContext context)
throws EvalException {
public boolean containsKey(Object key, Location loc, StarlarkContext context) {
return false;
}
}

0 comments on commit 778635e

Please sign in to comment.