diff options
author | jcater <jcater@google.com> | 2018-06-12 11:19:00 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-12 11:20:43 -0700 |
commit | 01cc4796b59bc0f81c2ee87fe7d8043df6b91e19 (patch) | |
tree | 8db448d22208fd81fc8dd94069e8eafd0b7963aa /src/main/java/com | |
parent | 967eebbc8b0cbaa01b281dbad1f14c2f30742195 (diff) |
Enable rules to inherit the ExecutionPlatformConstraintsAllowed value.
PiperOrigin-RevId: 200247872
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/RuleClass.java | 31 |
1 files changed, 28 insertions, 3 deletions
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()) { |