Skip to content

Commit

Permalink
Convert ToolchainResolver to ToolchainResolutionFunction.
Browse files Browse the repository at this point in the history
Part of work on execution transitions, #7935.

Closes #8070.

PiperOrigin-RevId: 244355735
  • Loading branch information
katre authored and copybara-github committed Apr 19, 2019
1 parent 375f72b commit 77a4962
Show file tree
Hide file tree
Showing 14 changed files with 1,052 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.rules.AliasConfiguredTarget;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.skyframe.ToolchainException;
import com.google.devtools.build.lib.skyframe.UnloadedToolchainContext;
import com.google.devtools.build.lib.skylarkbuildapi.ToolchainContextApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.StarlarkContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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.UnloadedToolchainContext;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.ValueOrException2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.google.devtools.build.lib.analysis.ResolvedToolchainContext;
import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
import com.google.devtools.build.lib.analysis.ToolchainResolver;
import com.google.devtools.build.lib.analysis.UnloadedToolchainContext;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.google.devtools.build.lib.analysis.ResolvedToolchainContext;
import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
import com.google.devtools.build.lib.analysis.ToolchainResolver;
import com.google.devtools.build.lib.analysis.UnloadedToolchainContext;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

package com.google.devtools.build.lib.skyframe;

import static java.util.stream.Collectors.joining;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.Event;
Expand All @@ -41,6 +45,15 @@ public class RegisteredToolchainsCycleReporter implements CyclesReporter.SingleC
private static final Predicate<SkyKey> IS_SINGLE_TOOLCHAIN_RESOLUTION_SKY_KEY =
SkyFunctions.isSkyFunction(SkyFunctions.SINGLE_TOOLCHAIN_RESOLUTION);

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

private static final Predicate<SkyKey> IS_TOOLCHAIN_RELATED =
Predicates.or(
IS_REGISTERED_TOOLCHAINS_SKY_KEY,
IS_SINGLE_TOOLCHAIN_RESOLUTION_SKY_KEY,
IS_TOOLCHAIN_RESOLUTION_SKY_KEY);

@Override
public boolean maybeReportCycle(
SkyKey topLevelKey,
Expand All @@ -50,9 +63,7 @@ public boolean maybeReportCycle(
ImmutableList<SkyKey> cycle = cycleInfo.getCycle();
if (alreadyReported) {
return true;
} else if (!Iterables.any(cycle, IS_REGISTERED_TOOLCHAINS_SKY_KEY)
|| !Iterables.any(cycle, IS_CONFIGURED_TARGET_SKY_KEY)
|| !Iterables.any(cycle, IS_SINGLE_TOOLCHAIN_RESOLUTION_SKY_KEY)) {
} else if (!Iterables.any(cycle, IS_TOOLCHAIN_RELATED)) {
return false;
}

Expand All @@ -63,24 +74,28 @@ public boolean maybeReportCycle(
}

Function<SkyKey, String> printer =
new Function<SkyKey, String>() {
@Override
public String apply(SkyKey input) {
if (input.argument() instanceof ConfiguredTargetKey) {
Label label = ((ConfiguredTargetKey) input.argument()).getLabel();
return label.toString();
}
if (input.argument() instanceof RegisteredToolchainsValue.Key) {
return "RegisteredToolchains";
}
if (input.argument() instanceof SingleToolchainResolutionValue.Key) {
Label toolchainType =
((SingleToolchainResolutionValue.Key) input.argument()).toolchainTypeLabel();
return String.format("toolchain type %s", toolchainType.toString());
} else {
throw new UnsupportedOperationException();
}
input -> {
if (input.argument() instanceof ConfiguredTargetKey) {
Label label = ((ConfiguredTargetKey) input.argument()).getLabel();
return label.toString();
}
if (input.argument() instanceof RegisteredToolchainsValue.Key) {
return "RegisteredToolchains";
}
if (input.argument() instanceof SingleToolchainResolutionValue.Key) {
Label toolchainType =
((SingleToolchainResolutionValue.Key) input.argument()).toolchainTypeLabel();
return String.format("toolchain type %s", toolchainType);
}
if (input.argument() instanceof UnloadedToolchainContext.Key) {
ImmutableSet<Label> toolchainTypes =
((UnloadedToolchainContext.Key) input.argument()).requiredToolchainTypeLabels();
return String.format(
"toolchain types %s",
toolchainTypes.stream().map(Label::toString).collect(joining(", ")));
}

throw new UnsupportedOperationException();
};

StringBuilder cycleMessage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public final class SkyFunctions {
SkyFunctionName.createHermetic("REGISTERED_TOOLCHAINS");
static final SkyFunctionName SINGLE_TOOLCHAIN_RESOLUTION =
SkyFunctionName.createHermetic("SINGLE_TOOLCHAIN_RESOLUTION");
static final SkyFunctionName TOOLCHAIN_RESOLUTION =
SkyFunctionName.createHermetic("TOOLCHAIN_RESOLUTION");
public static final SkyFunctionName REPOSITORY_MAPPING =
SkyFunctionName.createHermetic("REPOSITORY_MAPPING");
public static final SkyFunctionName RESOLVED_FILE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions(PackageFactory p
SkyFunctions.REGISTERED_EXECUTION_PLATFORMS, new RegisteredExecutionPlatformsFunction());
map.put(SkyFunctions.REGISTERED_TOOLCHAINS, new RegisteredToolchainsFunction());
map.put(SkyFunctions.SINGLE_TOOLCHAIN_RESOLUTION, new SingleToolchainResolutionFunction());
map.put(SkyFunctions.TOOLCHAIN_RESOLUTION, new ToolchainResolutionFunction());
map.put(SkyFunctions.REPOSITORY_MAPPING, new RepositoryMappingFunction());
map.put(SkyFunctions.RESOLVED_HASH_VALUES, new ResolvedHashesFunction());
map.put(SkyFunctions.RESOLVED_FILE, new ResolvedFileFunction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;

import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException;
import javax.annotation.Nullable;

/** Base class for exceptions that happen during toolchain resolution. */
public class ToolchainException extends Exception {

Expand All @@ -27,4 +30,21 @@ public ToolchainException(Throwable cause) {
public ToolchainException(String message, Throwable cause) {
super(message, cause);
}

/**
* Attempt to find a {@link ConfiguredValueCreationException} in this exception, or its causes.
*
* <p>If one cannot be found, a new one will be created.
*/
@Nullable
public ConfiguredValueCreationException asConfiguredValueCreationException() {
for (Throwable cause = getCause();
cause != null && cause != cause.getCause();
cause = cause.getCause()) {
if (cause instanceof ConfiguredValueCreationException) {
return (ConfiguredValueCreationException) cause;
}
}
return null;
}
}
Loading

0 comments on commit 77a4962

Please sign in to comment.