Search in sources :

Example 1 with SelectorList

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

the class AttributeFormatter method writeSelectorListToBuilder.

private static void writeSelectorListToBuilder(Build.Attribute.Builder attrPb, Type<?> type, SelectorList<?> selectorList) {
    Build.Attribute.SelectorList.Builder selectorListBuilder = Build.Attribute.SelectorList.newBuilder();
    selectorListBuilder.setType(ProtoUtils.getDiscriminatorFromType(type));
    for (Selector<?> selector : selectorList.getSelectors()) {
        Build.Attribute.Selector.Builder selectorBuilder = Build.Attribute.Selector.newBuilder().setNoMatchError(selector.getNoMatchError()).setHasDefaultValue(selector.hasDefault());
        // entries' order is preserved from the sorting performed by the SelectorValue constructor.
        for (Entry<Label, ?> entry : selector.getEntries().entrySet()) {
            Label condition = entry.getKey();
            Builder selectorEntryBuilder = SelectorEntry.newBuilder().setLabel(condition.toString()).setIsDefaultValue(!selector.isValueSet(condition));
            Object conditionValue = entry.getValue();
            if (conditionValue != null) {
                writeAttributeValueToBuilder(new SelectorEntryBuilderAdapter(selectorEntryBuilder), type, conditionValue);
            }
            selectorBuilder.addEntries(selectorEntryBuilder);
        }
        selectorListBuilder.addElements(selectorBuilder);
    }
    attrPb.setSelectorList(selectorListBuilder);
}
Also used : Build(com.google.devtools.build.lib.query2.proto.proto2api.Build) SelectorList(com.google.devtools.build.lib.packages.BuildType.SelectorList) Builder(com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.Builder) Label(com.google.devtools.build.lib.cmdline.Label) Selector(com.google.devtools.build.lib.packages.BuildType.Selector)

Aggregations

Label (com.google.devtools.build.lib.cmdline.Label)1 Selector (com.google.devtools.build.lib.packages.BuildType.Selector)1 SelectorList (com.google.devtools.build.lib.packages.BuildType.SelectorList)1 Build (com.google.devtools.build.lib.query2.proto.proto2api.Build)1 Builder (com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.Builder)1