diff options
author | 2016-10-07 08:52:10 +0000 | |
---|---|---|
committer | 2016-10-07 13:49:40 +0000 | |
commit | fd2bdc35789f176fff12cf3f721e91d795e22a93 (patch) | |
tree | ff2b52897368714cac5fc859a8fdbf1d89e7a3d7 /src/main/java/com/google/devtools/build/lib/rules | |
parent | 6265ade1a42fae924874e3b012a631c4aba0eb91 (diff) |
Change allowedRuleClasses/mandatoryProviders semantics to "either-or" instead of "and".
Also allow native rules to require declared providers on their
dependencies.
--
MOS_MIGRATED_REVID=135454750
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
3 files changed, 36 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java index ec184b4341..347c728952 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java @@ -27,6 +27,9 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.packages.SkylarkClassObject; +import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.Key; +import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.syntax.ClassObject; import com.google.devtools.build.lib.syntax.EvalException; @@ -75,6 +78,18 @@ public final class AliasConfiguredTarget implements ConfiguredTarget, ClassObjec return actual == null ? null : actual.get(providerKey); } + @Nullable + @Override + public SkylarkClassObject get(Key providerKey) { + return actual == null ? null : actual.get(providerKey); + } + + @Nullable + @Override + public Object get(SkylarkProviderIdentifier id) { + return actual == null ? null : actual.get(id); + } + @Override public Object getIndex(Object key, Location loc) throws EvalException { return actual == null ? null : actual.getIndex(key, loc); diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java index 015b0f0421..71f176dc21 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules; +import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -26,6 +27,7 @@ import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition; import com.google.devtools.build.lib.packages.Attribute.SkylarkComputedDefaultTemplate; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.SkylarkAspect; +import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; @@ -258,7 +260,7 @@ public final class SkylarkAttr { } } if (isSingleListOfStr) { - builder.mandatoryProviders(((SkylarkList<?>) obj).getContents(String.class, PROVIDERS_ARG)); + builder.mandatoryProviders(getSkylarkProviderIdentifiers((SkylarkList<?>) obj)); } else { builder.mandatoryProvidersList(getProvidersList((SkylarkList) obj)); } @@ -283,8 +285,20 @@ public final class SkylarkAttr { return builder; } - private static List<List<String>> getProvidersList(SkylarkList skylarkList) throws EvalException { - List<List<String>> providersList = new ArrayList<>(); + private static Iterable<SkylarkProviderIdentifier> getSkylarkProviderIdentifiers( + SkylarkList<?> obj) throws EvalException { + return Iterables.transform(obj.getContents(String.class, PROVIDERS_ARG), + new Function<String, SkylarkProviderIdentifier>() { + @Override + public SkylarkProviderIdentifier apply(String s) { + return SkylarkProviderIdentifier.forLegacy(s); + } + }); + } + + private static List<Iterable<SkylarkProviderIdentifier>> getProvidersList( + SkylarkList<?> skylarkList) throws EvalException { + List<Iterable<SkylarkProviderIdentifier>> providersList = new ArrayList<>(); String errorMsg = "Illegal argument: element in '%s' is of unexpected type. " + "Should be list of string, but got %s. " + "Notice: one single list of string as 'providers' is still supported."; @@ -300,7 +314,7 @@ public final class SkylarkAttr { + EvalUtils.getDataTypeNameFromClass(value.getClass()))); } } - providersList.add(((SkylarkList<?>) o).getContents(String.class, PROVIDERS_ARG)); + providersList.add(getSkylarkProviderIdentifiers((SkylarkList<?>) o)); } return providersList; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java index 50133dae4a..6ac83f5667 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java @@ -311,7 +311,9 @@ public final class SkylarkRuleConfiguredTargetBuilder { SkylarkClassObject declaredProvider = SkylarkType.cast(o, SkylarkClassObject.class, loc, "A return value of rule implementation function should be " + "a sequence of declared providers"); - builder.addSkylarkDeclaredProvider(declaredProvider, declaredProvider.getCreationLoc()); + Location creationLoc = declaredProvider.getCreationLocOrNull(); + builder.addSkylarkDeclaredProvider(declaredProvider, + creationLoc != null ? creationLoc : loc); } } |