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-18 18:08:03 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-07-19 10:20:35 +0200
commit96b4081b29c639c24660411cc2d326afb826d9a7 (patch)
treebd0a96d57084814b898901b34f70f463a7c40947 /src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
parent15074a4990e167048e47ede8bdb6412998ac6798 (diff)
Implement toolchain resolution via constraint checks.
Part of #2219. Change-Id: I5777e9b6cafbb7586cbbfb5b300344fd4417513d PiperOrigin-RevId: 162359389
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.java50
1 files changed, 41 insertions, 9 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 7a61c67271..dbe0e9f02b 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
@@ -14,7 +14,9 @@
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.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;
@@ -63,25 +65,55 @@ public class ToolchainResolutionFunction implements SkyFunction {
DeclaredToolchainInfo toolchain =
resolveConstraints(
key.toolchainType(),
- key.targetPlatform(),
key.execPlatform(),
+ key.targetPlatform(),
toolchains.registeredToolchains());
+
+ if (toolchain == null) {
+ throw new ToolchainResolutionFunctionException(
+ new NoToolchainFoundException(key.toolchainType()));
+ }
return ToolchainResolutionValue.create(toolchain.toolchainLabel());
}
- // TODO(katre): Implement real resolution.
- private DeclaredToolchainInfo resolveConstraints(
+ @VisibleForTesting
+ static DeclaredToolchainInfo resolveConstraints(
Label toolchainType,
- PlatformInfo targetPlatform,
PlatformInfo execPlatform,
- ImmutableList<DeclaredToolchainInfo> toolchains)
- throws ToolchainResolutionFunctionException {
+ PlatformInfo targetPlatform,
+ ImmutableList<DeclaredToolchainInfo> toolchains) {
for (DeclaredToolchainInfo toolchain : toolchains) {
- if (toolchain.toolchainType().equals(toolchainType)) {
- return toolchain;
+ // Make sure the type matches.
+ if (!toolchain.toolchainType().equals(toolchainType)) {
+ continue;
+ }
+ if (!checkConstraints(toolchain.execConstraints(), execPlatform)) {
+ continue;
+ }
+ if (!checkConstraints(toolchain.targetConstraints(), targetPlatform)) {
+ continue;
+ }
+
+ return toolchain;
+ }
+
+ return null;
+ }
+
+ /**
+ * 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) {
+
+ for (ConstraintValueInfo constraint : toolchainConstraints) {
+ ConstraintValueInfo found = platform.getConstraint(constraint.constraint());
+ if (!constraint.equals(found)) {
+ return false;
}
}
- throw new ToolchainResolutionFunctionException(new NoToolchainFoundException(toolchainType));
+ return true;
}
@Nullable