diff options
Diffstat (limited to 'src/main/java/com/google')
2 files changed, 59 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java index 9237cea109..b1eef7dc85 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java @@ -318,6 +318,8 @@ public class SkylarkRuleClassFunctions implements SkylarkRuleFunctionsApi<Artifa SkylarkList<String> toolchains, String doc, SkylarkList<?> providesArg, + Boolean executionPlatformConstraintsAllowed, + SkylarkList<?> execCompatibleWith, FuncallExpression ast, Environment funcallEnv) throws EvalException, ConversionException { @@ -399,6 +401,16 @@ public class SkylarkRuleClassFunctions implements SkylarkRuleFunctionsApi<Artifa builder.advertiseSkylarkProvider(skylarkProvider); } + if (!execCompatibleWith.isEmpty()) { + builder.addExecutionPlatformConstraints( + collectConstraintLabels( + execCompatibleWith.getContents(String.class, "exec_compatile_with"), + ast.getLocation())); + } + if (executionPlatformConstraintsAllowed) { + builder.executionPlatformConstraintsAllowed(ExecutionPlatformConstraintsAllowed.PER_TARGET); + } + return new SkylarkRuleFunction(builder, type, attributes, ast.getLocation()); } @@ -445,6 +457,22 @@ public class SkylarkRuleClassFunctions implements SkylarkRuleFunctionsApi<Artifa return requiredToolchains.build(); } + private static ImmutableList<Label> collectConstraintLabels( + Iterable<String> rawLabels, Location loc) throws EvalException { + ImmutableList.Builder<Label> constraintLabels = new ImmutableList.Builder<>(); + for (String rawLabel : rawLabels) { + try { + Label constraintLabel = Label.parseAbsolute(rawLabel); + constraintLabels.add(constraintLabel); + } catch (LabelSyntaxException e) { + throw new EvalException( + loc, String.format("Unable to parse constraint %s: %s", rawLabel, e.getMessage()), e); + } + } + + return constraintLabels.build(); + } + @Override public SkylarkAspect aspect( BaseFunction implementation, @@ -657,7 +685,11 @@ public class SkylarkRuleClassFunctions implements SkylarkRuleFunctionsApi<Artifa addAttribute(definitionLocation, builder, descriptor.build(attribute.getFirst())); } - this.ruleClass = builder.build(ruleClassName, skylarkLabel + "%" + ruleClassName); + try { + this.ruleClass = builder.build(ruleClassName, skylarkLabel + "%" + ruleClassName); + } catch (IllegalArgumentException | IllegalStateException ex) { + throw new EvalException(location, ex); + } this.builder = null; this.attributes = null; diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java index 53d25e8073..645db6cd72 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java @@ -266,6 +266,30 @@ public interface SkylarkRuleFunctionsApi<FileApiT extends FileApi> { + "It is an error if a provider is listed here and the rule " + "implementation function does not return it." ), + @Param( + name = "execution_platform_constraints_allowed", + type = Boolean.class, + named = true, + positional = false, + defaultValue = "False", + doc = + "If true, a special attribute named <code>exec_compatible_with</code> of " + + "label-list type is added, which must not already exist in " + + "<code>attrs</code>. Targets may use this attribute to specify additional " + + "constraints on the execution platform beyond those given in the " + + "<code>exec_compatible_with</code> argument to <code>rule()</code>." + ), + @Param( + name = "exec_compatible_with", + type = SkylarkList.class, + generic1 = String.class, + named = true, + positional = false, + defaultValue = "[]", + doc = + "A list of constraints on the execution platform that apply to all targets of " + + "this rule type." + ) }, useAst = true, useEnvironment = true @@ -283,6 +307,8 @@ public interface SkylarkRuleFunctionsApi<FileApiT extends FileApi> { SkylarkList<String> toolchains, String doc, SkylarkList<?> providesArg, + Boolean executionPlatformConstraintsAllowed, + SkylarkList<?> execCompatibleWith, FuncallExpression ast, Environment funcallEnv) throws EvalException; |