From ee45c6610ae213c12d57bf9e8e5ff674d7a9d7fc Mon Sep 17 00:00:00 2001 From: John Cater Date: Tue, 5 Jun 2018 11:09:01 -0700 Subject: Allow rules and targets to specify extra execution platform constraints. RuleClass.Builder now allows authors to specify whether a rule's targets can add additional constraints on the execution platform, and to declare additional constraints for all targets of that rule. Targets which support this now have an attribute, "exec_compatible_with", which supports specifying additional constraints that the execution platform used must match. This attribute is non-configurable. It will only affect execution platforms used during toolchain resolution. Part of #5217. Change-Id: Id2400dbf869a00aa2be3e3d2f085c2850cd6dc00 Closes #5227. Change-Id: If7d55f08f7f44bc7d7f6dfec86a3e6bcd68574b9 PiperOrigin-RevId: 199326255 --- .../build/lib/analysis/PlatformSemantics.java | 1 + .../devtools/build/lib/packages/RuleClass.java | 110 ++++++++++++++++- .../build/lib/skyframe/AspectFunction.java | 1 + .../lib/skyframe/ConfiguredTargetFunction.java | 26 ++++ .../build/lib/skyframe/SkyframeExecutor.java | 6 +- .../devtools/build/lib/skyframe/ToolchainUtil.java | 134 +++++++++++++++++++++ 6 files changed, 273 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java index bd3e89f97b..65c1047187 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.packages.RuleClass; public class PlatformSemantics { public static final String TOOLCHAINS_ATTR = "$toolchains"; + public static final String EXEC_COMPATIBLE_WITH_ATTR = "exec_compatible_with"; public static RuleClass.Builder platformAttributes(RuleClass.Builder builder) { return builder diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java index d83246871d..330278f1aa 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java @@ -201,6 +201,23 @@ public class RuleClass { public static final class RuleErrorException extends Exception {} } + /** + * Describes in which way a rule implementation allows additional execution platform constraints. + */ + public enum ExecutionPlatformConstraintsAllowed { + /** + * Allows additional execution platform constraints to be added in the rule definition, which + * apply to all targets of that rule. + */ + PER_RULE, + /** + * Users are allowed to specify additional execution platform constraints for each target, using + * the 'exec_compatible_with' attribute. This also allows setting constraints in the rule + * definition, like PER_RULE. + */ + PER_TARGET; + } + /** * For Bazel's constraint system: the attribute that declares the set of environments a rule * supports, overriding the defaults for their respective groups. @@ -615,6 +632,9 @@ public class RuleClass { private final Map attributes = new LinkedHashMap<>(); private final Set