From 01cc4796b59bc0f81c2ee87fe7d8043df6b91e19 Mon Sep 17 00:00:00 2001 From: jcater Date: Tue, 12 Jun 2018 11:19:00 -0700 Subject: Enable rules to inherit the ExecutionPlatformConstraintsAllowed value. PiperOrigin-RevId: 200247872 --- .../devtools/build/lib/packages/RuleClass.java | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/google') 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 330278f1aa..78abb6fe5d 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 @@ -209,13 +209,34 @@ public class RuleClass { * Allows additional execution platform constraints to be added in the rule definition, which * apply to all targets of that rule. */ - PER_RULE, + PER_RULE(1), /** * 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; + PER_TARGET(2); + + private final int priority; + + ExecutionPlatformConstraintsAllowed(int priority) { + this.priority = priority; + } + + public int priority() { + return priority; + } + + public static ExecutionPlatformConstraintsAllowed highestPriority( + ExecutionPlatformConstraintsAllowed first, ExecutionPlatformConstraintsAllowed... rest) { + ExecutionPlatformConstraintsAllowed result = first; + for (ExecutionPlatformConstraintsAllowed value : rest) { + if (result == null || result.priority() < value.priority()) { + result = value; + } + } + return result; + } } /** @@ -668,7 +689,11 @@ public class RuleClass { addRequiredToolchains(parent.getRequiredToolchains()); supportsPlatforms = parent.supportsPlatforms; - // executionPlatformConstraintsAllowed is not inherited and takes the default. + + // Make sure we use the highest priority value from all parents. + executionPlatformConstraintsAllowed( + ExecutionPlatformConstraintsAllowed.highestPriority( + executionPlatformConstraintsAllowed, parent.executionPlatformConstraintsAllowed())); addExecutionPlatformConstraints(parent.getExecutionPlatformConstraints()); for (Attribute attribute : parent.getAttributes()) { -- cgit v1.2.3