From 0692c7f95333d8355463ac2a3c4228a8afdb1054 Mon Sep 17 00:00:00 2001 From: Dmitry Lomov Date: Fri, 30 Sep 2016 16:43:30 +0000 Subject: Implement Skylark syntax to propagate an aspect to all attributes. -- MOS_MIGRATED_REVID=134793032 --- .../google/devtools/build/lib/packages/SkylarkAspect.java | 13 +++++++++++-- .../devtools/build/lib/rules/SkylarkRuleClassFunctions.java | 11 ++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java index be74013e5e..ca921a3a0a 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java @@ -26,6 +26,8 @@ import com.google.devtools.build.lib.syntax.Printer; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.Preconditions; +import java.util.Arrays; +import java.util.List; import javax.annotation.Nullable; /** A Skylark value that is a result of an 'aspect(..)' function call. */ @@ -111,11 +113,18 @@ public class SkylarkAspect implements SkylarkExportable { this.aspectClass = new SkylarkAspectClass(extensionLabel, name); } + private static final List allAttrAspects = Arrays.asList("*"); + public AspectDefinition getDefinition(AspectParameters aspectParams) { AspectDefinition.Builder builder = new AspectDefinition.Builder(getName()); - for (String attributeAspect : attributeAspects) { - builder.attributeAspect(attributeAspect, aspectClass); + if (allAttrAspects.equals(attributeAspects)) { + builder.allAttributesAspect(aspectClass); + } else { + for (String attributeAspect : attributeAspects) { + builder.attributeAspect(attributeAspect, aspectClass); + } } + for (Attribute attribute : attributes) { Attribute attr = attribute; // Might be reassigned. if (!aspectParams.getAttribute(attr.getName()).isEmpty()) { 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 95db14182e..292f123e38 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 @@ -394,7 +394,8 @@ public class SkylarkRuleClassFunctions { @Param(name = "attr_aspects", type = SkylarkList.class, generic1 = String.class, defaultValue = "[]", doc = "List of attribute names. The aspect propagates along dependencies specified by " - + " attributes of a target with this name" + + " attributes of a target with this name. The list can also contain a single string '*':" + + " in that case aspect propagates along all dependencies of a target." ), @Param(name = "attrs", type = SkylarkDict.class, noneable = true, defaultValue = "None", doc = "dictionary to declare all the attributes of the aspect. " @@ -444,6 +445,14 @@ public class SkylarkRuleClassFunctions { ImmutableList.Builder attrAspects = ImmutableList.builder(); for (Object attributeAspect : attributeAspects) { String attrName = STRING.convert(attributeAspect, "attr_aspects"); + + if (attrName.equals("*") && attributeAspects.size() != 1) { + throw new EvalException( + ast.getLocation(), + "'*' must be the only string in 'attr_aspects' list" + ); + } + if (!attrName.startsWith("_")) { attrAspects.add(attrName); } else { -- cgit v1.2.3