Search in sources :

Example 1 with RuleClass

use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.

the class TransitiveTraversalValue method forTarget.

static TransitiveTraversalValue forTarget(Target target, @Nullable String firstErrorMessage) {
    if (target instanceof Rule) {
        Rule rule = (Rule) target;
        RuleClass ruleClass = rule.getRuleClassObject();
        if (firstErrorMessage == null && !ruleClass.isSkylark()) {
            TransitiveTraversalValue value = VALUES_BY_RULE_CLASS.get(ruleClass);
            if (value != null) {
                return value;
            }
            AdvertisedProviderSet providers = ruleClass.getAdvertisedProviders();
            value = new TransitiveTraversalValue(providers, null);
            // May already be there from another RuleClass or a concurrent put.
            value = VALUE_INTERNER.intern(value);
            // May already be there from a concurrent put.
            VALUES_BY_RULE_CLASS.putIfAbsent(ruleClass, value);
            return value;
        } else {
            // same providers.
            return TransitiveTraversalValue.create(rule.getRuleClassObject().getAdvertisedProviders(), firstErrorMessage);
        }
    }
    if (firstErrorMessage == null) {
        return EMPTY_VALUE;
    } else {
        return new TransitiveTraversalValue(AdvertisedProviderSet.EMPTY, firstErrorMessage);
    }
}
Also used : AdvertisedProviderSet(com.google.devtools.build.lib.packages.AdvertisedProviderSet) Rule(com.google.devtools.build.lib.packages.Rule) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 2 with RuleClass

use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.

the class DependencyResolver method collectOriginatingAspects.

/**
   * Collect all aspects that originate on {@code attribute} of {@code originalRule}
   * and are applicable to a {@code target}
   *
   * They are appended to {@code filteredAspectPath} and registered in {@code visibleAspects} set.
   */
private static void collectOriginatingAspects(Rule originalRule, Attribute attribute, Rule target, ImmutableList.Builder<Aspect> filteredAspectPath, ImmutableSet.Builder<AspectDescriptor> visibleAspects) {
    ImmutableList<Aspect> baseAspects = attribute.getAspects(originalRule);
    RuleClass ruleClass = target.getRuleClassObject();
    for (Aspect baseAspect : baseAspects) {
        if (baseAspect.getDefinition().getRequiredProviders().isSatisfiedBy(ruleClass.getAdvertisedProviders())) {
            filteredAspectPath.add(baseAspect);
            visibleAspects.add(baseAspect.getDescriptor());
        }
    }
}
Also used : Aspect(com.google.devtools.build.lib.packages.Aspect) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 3 with RuleClass

use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.

the class ConfiguredTargetFactory method missingFragmentError.

private String missingFragmentError(RuleContext ruleContext, ConfigurationFragmentPolicy configurationFragmentPolicy) {
    RuleClass ruleClass = ruleContext.getRule().getRuleClassObject();
    Set<Class<?>> missingFragments = new LinkedHashSet<>();
    for (Class<?> fragment : configurationFragmentPolicy.getRequiredConfigurationFragments()) {
        if (!ruleContext.getConfiguration().hasFragment(fragment.asSubclass(Fragment.class))) {
            missingFragments.add(fragment);
        }
    }
    Preconditions.checkState(!missingFragments.isEmpty());
    StringBuilder result = new StringBuilder();
    result.append("all rules of type " + ruleClass.getName() + " require the presence of ");
    List<String> names = new ArrayList<>();
    for (Class<?> fragment : missingFragments) {
        // TODO(bazel-team): Using getSimpleName here is sub-optimal, but we don't have anything
        // better right now.
        names.add(fragment.getSimpleName());
    }
    result.append("all of [");
    Joiner.on(",").appendTo(result, names);
    result.append("], but these were all disabled");
    return result.toString();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) RuleClass(com.google.devtools.build.lib.packages.RuleClass) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 4 with RuleClass

use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.

the class InfoItem method getAllowedRuleClasses.

private static AllowedRuleClassInfo getAllowedRuleClasses(Collection<RuleClass> ruleClasses, Attribute attr) {
    AllowedRuleClassInfo.Builder info = AllowedRuleClassInfo.newBuilder();
    info.setPolicy(AllowedRuleClassInfo.AllowedRuleClasses.ANY);
    if (attr.isStrictLabelCheckingEnabled() && attr.getAllowedRuleClassesPredicate() != Predicates.<RuleClass>alwaysTrue()) {
        info.setPolicy(AllowedRuleClassInfo.AllowedRuleClasses.SPECIFIED);
        Predicate<RuleClass> filter = attr.getAllowedRuleClassesPredicate();
        for (RuleClass otherClass : Iterables.filter(ruleClasses, filter)) {
            if (otherClass.isDocumented()) {
                info.addAllowedRuleClass(otherClass.getName());
            }
        }
    }
    return info.build();
}
Also used : AllowedRuleClassInfo(com.google.devtools.build.lib.query2.proto.proto2api.Build.AllowedRuleClassInfo) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 5 with RuleClass

use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleAddMultipleAttributes.

@Test
public void testRuleAddMultipleAttributes() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl,", "     attrs = {", "            'a1': attr.label_list(allow_files=True),", "            'a2': attr.int()", "})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    assertTrue(c.hasAttr("a1", BuildType.LABEL_LIST));
    assertTrue(c.hasAttr("a2", Type.INTEGER));
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Aggregations

RuleClass (com.google.devtools.build.lib.packages.RuleClass)23 RuleFunction (com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction)9 Test (org.junit.Test)9 Attribute (com.google.devtools.build.lib.packages.Attribute)6 ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)2 Rule (com.google.devtools.build.lib.packages.Rule)2 ArrayList (java.util.ArrayList)2 NoBuildEvent (com.google.devtools.build.lib.analysis.NoBuildEvent)1 ConfigurationFragmentFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory)1 FragmentOptions (com.google.devtools.build.lib.analysis.config.FragmentOptions)1 Label (com.google.devtools.build.lib.cmdline.Label)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 AdvertisedProviderSet (com.google.devtools.build.lib.packages.AdvertisedProviderSet)1 Aspect (com.google.devtools.build.lib.packages.Aspect)1 FileTarget (com.google.devtools.build.lib.packages.FileTarget)1 ImplicitOutputsFunction (com.google.devtools.build.lib.packages.ImplicitOutputsFunction)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)1 RuleClassProvider (com.google.devtools.build.lib.packages.RuleClassProvider)1 AllowedRuleClassInfo (com.google.devtools.build.lib.query2.proto.proto2api.Build.AllowedRuleClassInfo)1