diff options
Diffstat (limited to 'src')
4 files changed, 61 insertions, 39 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java index 14de806ac6..86b0cb333b 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java @@ -1816,28 +1816,37 @@ public final class RuleContext extends TargetContext private String getMissingMandatoryNativeProviders( ConfiguredTarget prerequisite, Attribute attribute) { - List<Class<? extends TransitiveInfoProvider>> mandatoryProvidersList = - attribute.getMandatoryNativeProviders(); + List<ImmutableList<Class<? extends TransitiveInfoProvider>>> mandatoryProvidersList = + attribute.getMandatoryNativeProvidersList(); if (mandatoryProvidersList.isEmpty()) { return null; } - List<Class<? extends TransitiveInfoProvider>> missing = new ArrayList<>(); - for (Class<? extends TransitiveInfoProvider> provider : mandatoryProvidersList) { - if (prerequisite.getProvider(provider) == null) { - missing.add(provider); + List<List<String>> missingProvidersList = new ArrayList<>(); + for (ImmutableList<Class<? extends TransitiveInfoProvider>> providers + : mandatoryProvidersList) { + List<String> missing = new ArrayList<>(); + for (Class<? extends TransitiveInfoProvider> provider : providers) { + if (prerequisite.getProvider(provider) == null) { + missing.add(provider.getSimpleName()); + } + } + if (missing.isEmpty()) { + return null; + } else { + missingProvidersList.add(missing); } } - if (missing.isEmpty()) { - return null; - } - StringBuilder sb = new StringBuilder(); - for (Class<? extends TransitiveInfoProvider> provider : missing) { - if (sb.length() > 0) { - sb.append(", "); + StringBuilder missingProviders = new StringBuilder(); + Joiner joinProvider = Joiner.on(", "); + for (List<String> providers : missingProvidersList) { + if (missingProviders.length() > 0) { + missingProviders.append(" or "); } - sb.append(provider.getSimpleName()); + missingProviders.append((providers.size() > 1) ? "[" : ""); + joinProvider.appendTo(missingProviders, providers); + missingProviders.append((providers.size() > 1) ? "]" : ""); } - return sb.toString(); + return missingProviders.toString(); } /** @@ -1872,7 +1881,7 @@ public final class RuleContext extends TargetContext // if no providers were mandatory (thus, none are missing), which would cause an early return // below without emitting the error message about the not-allowed rule class if that // requirement was unfulfilled. - if (!attribute.getMandatoryNativeProviders().isEmpty() + if (!attribute.getMandatoryNativeProvidersList().isEmpty() || !attribute.getMandatoryProvidersList().isEmpty()) { boolean hadAllMandatoryProviders = true; diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java index 1cd8dc97d9..584be8666d 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java @@ -78,7 +78,7 @@ public class BazelJavaRuleClasses { return builder .add( attr(":java_toolchain", LABEL) - .mandatoryNativeProviders(JavaToolchainProvider.class) + .mandatoryNativeProviders(ImmutableList.of(JavaToolchainProvider.class)) .value(JavaSemantics.JAVA_TOOLCHAIN)) .setPreferredDependencyPredicate(JavaSemantics.JAVA_SOURCE) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 80bba9bde3..593254acaa 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -436,8 +436,8 @@ public final class Attribute implements Comparable<Attribute> { private PredicateWithMessage<Object> allowedValues = null; private ImmutableList<ImmutableSet<String>> mandatoryProvidersList = ImmutableList.<ImmutableSet<String>>of(); - private ImmutableList<Class<? extends TransitiveInfoProvider>> mandatoryNativeProviders = - ImmutableList.of(); + private ImmutableList<ImmutableList<Class<? extends TransitiveInfoProvider>>> + mandatoryNativeProvidersList = ImmutableList.of(); private HashMap<String, RuleAspect<?>> aspects = new LinkedHashMap<>(); /** @@ -877,18 +877,28 @@ public final class Attribute implements Comparable<Attribute> { } /** - * Sets a list of mandatory native providers. Every configured target occurring in this label - * type attribute has to provide all the providers, otherwise an error is produced during the - * analysis phase. + * Sets a list of lists of mandatory native providers. Every configured target occurring in this + * label type attribute has to provide all the providers from one of those lists, otherwise an + * error is produced during the analysis phase. */ - @SafeVarargs - public final Builder<TYPE> mandatoryNativeProviders( - Class<? extends TransitiveInfoProvider>... providers) { - Preconditions.checkState( - (type == BuildType.LABEL) || (type == BuildType.LABEL_LIST), + public final Builder<TYPE> mandatoryNativeProvidersList( + Iterable<? extends Iterable<Class<? extends TransitiveInfoProvider>>> providersList) { + Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST), "must be a label-valued type"); - this.mandatoryNativeProviders = - ImmutableList.<Class<? extends TransitiveInfoProvider>>copyOf(providers); + ImmutableList.Builder<ImmutableList<Class<? extends TransitiveInfoProvider>>> listBuilder + = ImmutableList.builder(); + for (Iterable<Class<? extends TransitiveInfoProvider>> providers : providersList) { + listBuilder.add(ImmutableList.<Class<? extends TransitiveInfoProvider>>copyOf(providers)); + } + this.mandatoryNativeProvidersList = listBuilder.build(); + return this; + } + + public Builder<TYPE> mandatoryNativeProviders( + Iterable<Class<? extends TransitiveInfoProvider>> providers) { + if (providers.iterator().hasNext()) { + mandatoryNativeProvidersList(ImmutableList.of(providers)); + } return this; } @@ -1051,7 +1061,7 @@ public final class Attribute implements Comparable<Attribute> { condition, allowedValues, mandatoryProvidersList, - mandatoryNativeProviders, + mandatoryNativeProvidersList, ImmutableList.copyOf(aspects.values())); } } @@ -1664,7 +1674,8 @@ public final class Attribute implements Comparable<Attribute> { private final ImmutableList<ImmutableSet<String>> mandatoryProvidersList; - private final ImmutableList<Class<? extends TransitiveInfoProvider>> mandatoryNativeProviders; + private final ImmutableList<ImmutableList<Class<? extends TransitiveInfoProvider>>> + mandatoryNativeProvidersList; private final ImmutableList<RuleAspect<?>> aspects; @@ -1698,7 +1709,8 @@ public final class Attribute implements Comparable<Attribute> { Predicate<AttributeMap> condition, PredicateWithMessage<Object> allowedValues, ImmutableList<ImmutableSet<String>> mandatoryProvidersList, - ImmutableList<Class<? extends TransitiveInfoProvider>> mandatoryNativeProviders, + ImmutableList<ImmutableList<Class<? extends TransitiveInfoProvider>>> + mandatoryNativeProvidersList, ImmutableList<RuleAspect<?>> aspects) { Preconditions.checkNotNull(configTransition); Preconditions.checkArgument( @@ -1733,7 +1745,7 @@ public final class Attribute implements Comparable<Attribute> { this.condition = condition; this.allowedValues = allowedValues; this.mandatoryProvidersList = mandatoryProvidersList; - this.mandatoryNativeProviders = mandatoryNativeProviders; + this.mandatoryNativeProvidersList = mandatoryNativeProvidersList; this.aspects = aspects; } @@ -1933,9 +1945,10 @@ public final class Attribute implements Comparable<Attribute> { return mandatoryProvidersList; } - /** Returns the list of mandatory native providers. */ - public ImmutableList<Class<? extends TransitiveInfoProvider>> getMandatoryNativeProviders() { - return mandatoryNativeProviders; + /** Returns the list of lists of mandatory native providers. */ + public ImmutableList<ImmutableList<Class<? extends TransitiveInfoProvider>>> + getMandatoryNativeProvidersList() { + return mandatoryNativeProvidersList; } public FileTypeSet getAllowedFileTypesPredicate() { @@ -2066,7 +2079,7 @@ public final class Attribute implements Comparable<Attribute> { builder.allowedFileTypesForLabels = allowedFileTypesForLabels; builder.allowedRuleClassesForLabels = allowedRuleClassesForLabels; builder.allowedRuleClassesForLabelsWarning = allowedRuleClassesForLabelsWarning; - builder.mandatoryNativeProviders = mandatoryNativeProviders; + builder.mandatoryNativeProvidersList = mandatoryNativeProvidersList; builder.mandatoryProvidersList = mandatoryProvidersList; builder.validityPredicate = validityPredicate; builder.condition = condition; diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java index ae9b7d8f48..5d093ab994 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java @@ -738,7 +738,7 @@ public class ObjcRuleClasses { attr("deps", LABEL_LIST) .direct_compile_time_input() .allowedRuleClasses(ALLOWED_DEPS_RULE_CLASSES) - .mandatoryNativeProviders(ObjcProvider.class) + .mandatoryNativeProviders(ImmutableList.of(ObjcProvider.class)) .allowedFileTypes()) /* <!-- #BLAZE_RULE($objc_compiling_rule).ATTRIBUTE(runtime_deps) --> The list of framework targets that are late loaded at runtime. They are included in the @@ -761,7 +761,7 @@ public class ObjcRuleClasses { attr("non_propagated_deps", LABEL_LIST) .direct_compile_time_input() .allowedRuleClasses(ALLOWED_DEPS_RULE_CLASSES) - .mandatoryNativeProviders(ObjcProvider.class) + .mandatoryNativeProviders(ImmutableList.of(ObjcProvider.class)) .allowedFileTypes()) /* <!-- #BLAZE_RULE($objc_compiling_rule).ATTRIBUTE(defines) --> Extra <code>-D</code> flags to pass to the compiler. They should be in |