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);
}
}
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());
}
}
}
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();
}
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();
}
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));
}
Aggregations