Search in sources :

Example 1 with Descriptor

use of com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method buildAttribute.

private Attribute buildAttribute(String name, String... lines) throws Exception {
    String[] strings = lines.clone();
    strings[strings.length - 1] = String.format("%s = %s", name, strings[strings.length - 1]);
    evalAndExport(strings);
    Descriptor lookup = (Descriptor) ev.lookup(name);
    return lookup != null ? lookup.build(name) : null;
}
Also used : Descriptor(com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor)

Example 2 with Descriptor

use of com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor in project bazel by bazelbuild.

the class SkylarkRuleClassFunctions method attrObjectToAttributesList.

protected static ImmutableList<Pair<String, Descriptor>> attrObjectToAttributesList(Object attrs, FuncallExpression ast) throws EvalException {
    ImmutableList.Builder<Pair<String, Descriptor>> attributes = ImmutableList.builder();
    if (attrs != Runtime.NONE) {
        for (Map.Entry<String, Descriptor> attr : castMap(attrs, String.class, Descriptor.class, "attrs").entrySet()) {
            Descriptor attrDescriptor = attr.getValue();
            AttributeValueSource source = attrDescriptor.getValueSource();
            String attrName = source.convertToNativeName(attr.getKey(), ast.getLocation());
            attributes.add(Pair.of(attrName, attrDescriptor));
        }
    }
    return attributes.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Descriptor(com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor) AttributeValueSource(com.google.devtools.build.lib.packages.AttributeValueSource) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SkylarkImplicitOutputsFunctionWithMap(com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SkylarkImplicitOutputsFunctionWithMap) SkylarkType.castMap(com.google.devtools.build.lib.syntax.SkylarkType.castMap) BuildLangTypedAttributeValuesMap(com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap) AttributeMap(com.google.devtools.build.lib.packages.AttributeMap) Pair(com.google.devtools.build.lib.util.Pair)

Aggregations

Descriptor (com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 AttributeMap (com.google.devtools.build.lib.packages.AttributeMap)1 AttributeValueSource (com.google.devtools.build.lib.packages.AttributeValueSource)1 SkylarkImplicitOutputsFunctionWithMap (com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SkylarkImplicitOutputsFunctionWithMap)1 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)1 SkylarkType.castMap (com.google.devtools.build.lib.syntax.SkylarkType.castMap)1 Pair (com.google.devtools.build.lib.util.Pair)1 Map (java.util.Map)1