diff options
author | 2015-11-26 11:18:12 +0000 | |
---|---|---|
committer | 2015-11-26 13:20:30 +0000 | |
commit | c1b1eedc14856997d2bf68be5d94f937fb21d3a3 (patch) | |
tree | 9ff682be1b4cea1f5c6586efe07f4c50c708d939 /src/main/java/com/google/devtools/build | |
parent | 1d0086089f48c7bf3cd7bedf4ac5412841f884ae (diff) |
Implements 'extra_deps' for Skylark aspects.
--
MOS_MIGRATED_REVID=108779139
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java index df27c88169..7d32b7705b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java @@ -356,20 +356,45 @@ public class SkylarkRuleClassFunctions { type = SkylarkList.class, generic1 = String.class, defaultValue = "[]" + ), + @Param( + name = "extra_deps", + type = SkylarkList.class, + generic1 = String.class, + defaultValue = "[]" ) }, - useEnvironment = true + useEnvironment = true, + useAst = true ) private static final BuiltinFunction aspect = new BuiltinFunction("aspect") { public SkylarkAspect invoke( - BaseFunction implementation, SkylarkList attributeAspects, Environment funcallEnv) - throws ConversionException { - ImmutableList.Builder<String> builder = ImmutableList.<String>builder(); + BaseFunction implementation, + SkylarkList attributeAspects, + SkylarkList extraDeps, + FuncallExpression ast, + Environment funcallEnv) throws EvalException { + ImmutableList.Builder<String> attributeListBuilder = ImmutableList.builder(); for (Object attributeAspect : attributeAspects) { - builder.add(STRING.convert(attributeAspect, "")); + attributeListBuilder.add(STRING.convert(attributeAspect, "attr_aspects")); + } + ImmutableList.Builder<Label> extraDepsBuilder = ImmutableList.builder(); + for (Object extraDep : extraDeps) { + String extraDepsString = STRING.convert(extraDep, "extra_deps"); + Label label; + try { + label = Label.parseAbsolute(extraDepsString); + } catch (LabelSyntaxException e) { + throw new EvalException(ast.getLocation(), e.getMessage()); + } + extraDepsBuilder.add(label); } - return new SkylarkAspect(implementation, builder.build(), funcallEnv); + + return new SkylarkAspect(implementation, + attributeListBuilder.build(), + extraDepsBuilder.build(), + funcallEnv); } }; @@ -433,6 +458,7 @@ public class SkylarkRuleClassFunctions { } attributeBuilder.aspect(new SkylarkAspectClass(skylarkAspect)); } + addAttribute(definitionLocation, builder, descriptor.getAttributeBuilder().build(attribute.getFirst())); } @@ -609,15 +635,17 @@ public class SkylarkRuleClassFunctions { public static class SkylarkAspect implements SkylarkValue { private final BaseFunction implementation; private final ImmutableList<String> attributeAspects; + private final ImmutableList<Label> extraDeps; private final Environment funcallEnv; private Exported exported; public SkylarkAspect( BaseFunction implementation, ImmutableList<String> attributeAspects, - Environment funcallEnv) { + ImmutableList<Label> extraDeps, Environment funcallEnv) { this.implementation = implementation; this.attributeAspects = attributeAspects; + this.extraDeps = extraDeps; this.funcallEnv = funcallEnv; } @@ -633,6 +661,10 @@ public class SkylarkRuleClassFunctions { return funcallEnv; } + public ImmutableList<Label> getExtraDeps() { + return extraDeps; + } + @Override public boolean isImmutable() { return implementation.isImmutable(); @@ -698,6 +730,7 @@ public class SkylarkRuleClassFunctions { for (String attributeAspect : skylarkAspect.getAttributeAspects()) { builder.attributeAspect(attributeAspect, this); } + builder.add(attr("$extra_deps", LABEL_LIST).value(skylarkAspect.getExtraDeps())); this.aspectDefinition = builder.build(); this.extensionLabel = skylarkAspect.getExtensionLabel(); |