aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-07-26 14:42:54 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-26 16:22:27 +0200
commit2f8b1e519ccc4ead62be57d245d559029265a9a7 (patch)
tree231f2d14f2409c9e0106aaa50be7e6f6df55517a /src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
parented6f653834ac5069c6ab0fb871bc41554fbf36f1 (diff)
Add --toolchain_resolution_debug option to give more information about
toolchain selection. Fixes #3431. Change-Id: Ia38415575b6a121cbb6a028bfc0276691cd11b6d PiperOrigin-RevId: 163196646
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java55
1 files changed, 50 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
index 28a6ebe0ca..410578f497 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
@@ -17,11 +17,14 @@ package com.google.devtools.build.lib.skyframe;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.PlatformConfiguration;
+import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo;
import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.events.Event;
+import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.NoSuchThingException;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException;
import com.google.devtools.build.lib.skyframe.RegisteredToolchainsFunction.InvalidTargetException;
@@ -74,12 +77,14 @@ public class ToolchainResolutionFunction implements SkyFunction {
}
// Find the right one.
+ boolean debug = configuration.getOptions().get(PlatformOptions.class).toolchainResolutionDebug;
DeclaredToolchainInfo toolchain =
resolveConstraints(
key.toolchainType(),
key.execPlatform(),
key.targetPlatform(),
- toolchains.registeredToolchains());
+ toolchains.registeredToolchains(),
+ debug ? env.getListener() : null);
if (toolchain == null) {
throw new ToolchainResolutionFunctionException(
@@ -93,35 +98,75 @@ public class ToolchainResolutionFunction implements SkyFunction {
Label toolchainType,
PlatformInfo execPlatform,
PlatformInfo targetPlatform,
- ImmutableList<DeclaredToolchainInfo> toolchains) {
+ ImmutableList<DeclaredToolchainInfo> toolchains,
+ @Nullable EventHandler eventHandler) {
+
+ debugMessage(eventHandler, "Looking for toolchain of type %s...", toolchainType);
for (DeclaredToolchainInfo toolchain : toolchains) {
// Make sure the type matches.
if (!toolchain.toolchainType().equals(toolchainType)) {
continue;
}
- if (!checkConstraints(toolchain.execConstraints(), execPlatform)) {
+ debugMessage(eventHandler, " Considering toolchain %s...", toolchain.toolchainLabel());
+ if (!checkConstraints(eventHandler, toolchain.execConstraints(), "execution", execPlatform)) {
+ debugMessage(
+ eventHandler,
+ " Rejected toolchain %s, because of execution platform mismatch",
+ toolchain.toolchainLabel());
continue;
}
- if (!checkConstraints(toolchain.targetConstraints(), targetPlatform)) {
+ if (!checkConstraints(
+ eventHandler, toolchain.targetConstraints(), "target", targetPlatform)) {
+ debugMessage(
+ eventHandler,
+ " Rejected toolchain %s, because of target platform mismatch",
+ toolchain.toolchainLabel());
continue;
}
+ debugMessage(eventHandler, " Selected toolchain %s", toolchain.toolchainLabel());
return toolchain;
}
+ debugMessage(eventHandler, " No toolchain found");
return null;
}
/**
+ * Helper method to print a debugging message, if the given {@link EventHandler} is not {@code
+ * null}.
+ */
+ private static void debugMessage(
+ @Nullable EventHandler eventHandler, String template, Object... args) {
+ if (eventHandler == null) {
+ return;
+ }
+
+ eventHandler.handle(Event.info("ToolchainResolution: " + String.format(template, args)));
+ }
+
+ /**
* Returns {@code true} iff all constraints set by the toolchain are present in the {@link
* PlatformInfo}.
*/
private static boolean checkConstraints(
- Iterable<ConstraintValueInfo> toolchainConstraints, PlatformInfo platform) {
+ @Nullable EventHandler eventHandler,
+ Iterable<ConstraintValueInfo> toolchainConstraints,
+ String platformType,
+ PlatformInfo platform) {
for (ConstraintValueInfo constraint : toolchainConstraints) {
ConstraintValueInfo found = platform.getConstraint(constraint.constraint());
if (!constraint.equals(found)) {
+ debugMessage(
+ eventHandler,
+ " Toolchain constraint %s has value %s, "
+ + "which does not match value %s from the %s platform %s",
+ constraint.constraint().label(),
+ constraint.label(),
+ found != null ? found.label() : "<missing>",
+ platformType,
+ platform.label());
return false;
}
}