use of com.google.devtools.build.lib.syntax.Type.ListType in project bazel by bazelbuild.
the class BuildRuleWithDefaultsBuilder method populateLabelAttribute.
/**
* Populates the label type attribute with generated values. Populates with a file if possible, or
* generates an appropriate rule. Note, that the rules are always generated in the same package.
*/
public BuildRuleWithDefaultsBuilder populateLabelAttribute(String rulePkg, String filePkg, Attribute attribute) {
Type<?> attrType = attribute.getType();
String label = null;
if (attribute.getAllowedFileTypesPredicate() != FileTypeSet.NO_FILE) {
// Try to populate with files first
String extension = null;
if (attribute.getAllowedFileTypesPredicate() == FileTypeSet.ANY_FILE) {
extension = ".txt";
} else {
FileTypeSet fileTypes = attribute.getAllowedFileTypesPredicate();
// This argument should always hold, if not that means a Blaze design/implementation error
Preconditions.checkArgument(!fileTypes.getExtensions().isEmpty());
extension = fileTypes.getExtensions().get(0);
}
label = getDummyFileLabel(rulePkg, filePkg, extension, attrType);
} else {
Predicate<RuleClass> allowedRuleClasses = attribute.getAllowedRuleClassesPredicate();
if (allowedRuleClasses != Predicates.<RuleClass>alwaysFalse()) {
// See if there is an applicable rule among the already enqueued rules
BuildRuleBuilder referencedRuleBuilder = getFirstApplicableRule(allowedRuleClasses);
if (referencedRuleBuilder != null) {
label = ":" + referencedRuleBuilder.ruleName;
} else {
RuleClass referencedRuleClass = getFirstApplicableRuleClass(allowedRuleClasses);
if (referencedRuleClass != null) {
// Generate a rule with the appropriate ruleClass and a label for it in
// the original rule
label = ":" + getDummyRuleLabel(rulePkg, referencedRuleClass);
}
}
}
}
if (label != null) {
if (attrType instanceof ListType<?>) {
addMultiValueAttributes(attribute.getName(), label);
} else {
setSingleValueAttribute(attribute.getName(), label);
}
}
return this;
}
Aggregations