Search in sources :

Example 1 with Builder

use of com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult.Builder in project bazel by bazelbuild.

the class SkyQueryEnvironment method buildTransitiveClosure.

@Override
public void buildTransitiveClosure(QueryExpression caller, Set<Target> targets, int maxDepth) throws QueryException, InterruptedException {
    // Everything has already been loaded, so here we just check for errors so that we can
    // pre-emptively throw/report if needed.
    Iterable<SkyKey> transitiveTraversalKeys = makeTransitiveTraversalKeys(targets);
    ImmutableList.Builder<String> errorMessagesBuilder = ImmutableList.builder();
    // First, look for errors in the successfully evaluated TransitiveTraversalValues. They may
    // have encountered errors that they were able to recover from.
    Set<Entry<SkyKey, SkyValue>> successfulEntries = graph.getSuccessfulValues(transitiveTraversalKeys).entrySet();
    Builder<SkyKey> successfulKeysBuilder = ImmutableSet.builder();
    for (Entry<SkyKey, SkyValue> successfulEntry : successfulEntries) {
        successfulKeysBuilder.add(successfulEntry.getKey());
        TransitiveTraversalValue value = (TransitiveTraversalValue) successfulEntry.getValue();
        String firstErrorMessage = value.getFirstErrorMessage();
        if (firstErrorMessage != null) {
            errorMessagesBuilder.add(firstErrorMessage);
        }
    }
    ImmutableSet<SkyKey> successfulKeys = successfulKeysBuilder.build();
    // Next, look for errors from the unsuccessfully evaluated TransitiveTraversal skyfunctions.
    Iterable<SkyKey> unsuccessfulKeys = Iterables.filter(transitiveTraversalKeys, Predicates.not(Predicates.in(successfulKeys)));
    Set<Entry<SkyKey, Exception>> errorEntries = graph.getMissingAndExceptions(unsuccessfulKeys).entrySet();
    for (Map.Entry<SkyKey, Exception> entry : errorEntries) {
        if (entry.getValue() == null) {
            // Targets may be in the graph because they are not in the universe or depend on cycles.
            eventHandler.handle(Event.warn(entry.getKey().argument() + " does not exist in graph"));
        } else {
            errorMessagesBuilder.add(entry.getValue().getMessage());
        }
    }
    // Lastly, report all found errors.
    ImmutableList<String> errorMessages = errorMessagesBuilder.build();
    for (String errorMessage : errorMessages) {
        reportBuildFileError(caller, errorMessage);
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ImmutableList(com.google.common.collect.ImmutableList) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) IOException(java.io.IOException) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) BuildFileContainsErrorsException(com.google.devtools.build.lib.packages.BuildFileContainsErrorsException) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) QueryException(com.google.devtools.build.lib.query2.engine.QueryException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SkyValue(com.google.devtools.build.skyframe.SkyValue) Entry(java.util.Map.Entry) TransitiveTraversalValue(com.google.devtools.build.lib.skyframe.TransitiveTraversalValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 2 with Builder

use of com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult.Builder in project bazel by bazelbuild.

the class BazelRulesModule method workspaceInit.

@Override
public void workspaceInit(BlazeDirectories directories, WorkspaceBuilder builder) {
    builder.addSkyFunction(FdoSupportValue.SKYFUNCTION, new FdoSupportFunction());
    builder.addPrecomputedValue(PrecomputedValue.injected(GenQuery.QUERY_OUTPUT_FORMATTERS, new Supplier<ImmutableList<OutputFormatter>>() {

        @Override
        public ImmutableList<OutputFormatter> get() {
            return env.getRuntime().getQueryOutputFormatters();
        }
    }));
}
Also used : FdoSupportFunction(com.google.devtools.build.lib.rules.cpp.FdoSupportFunction) Supplier(com.google.common.base.Supplier) OutputFormatter(com.google.devtools.build.lib.query2.output.OutputFormatter)

Example 3 with Builder

use of com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult.Builder in project bazel by bazelbuild.

the class AttributeFormatter method writeAttributeValueToBuilder.

/**
   * Set the appropriate type and value. Since string and string list store values for multiple
   * types, use the toString() method on the objects instead of casting them.
   */
@SuppressWarnings("unchecked")
private static void writeAttributeValueToBuilder(AttributeValueBuilderAdapter builder, Type<?> type, Object value) {
    if (type == INTEGER) {
        builder.setIntValue((Integer) value);
    } else if (type == STRING || type == LABEL || type == NODEP_LABEL || type == OUTPUT) {
        builder.setStringValue(value.toString());
    } else if (type == STRING_LIST || type == LABEL_LIST || type == NODEP_LABEL_LIST || type == OUTPUT_LIST || type == DISTRIBUTIONS) {
        for (Object entry : (Collection<?>) value) {
            builder.addStringListValue(entry.toString());
        }
    } else if (type == INTEGER_LIST) {
        for (Integer entry : (Collection<Integer>) value) {
            builder.addIntListValue(entry);
        }
    } else if (type == BOOLEAN) {
        builder.setBooleanValue((Boolean) value);
    } else if (type == TRISTATE) {
        builder.setTristateValue(triStateToProto((TriState) value));
    } else if (type == LICENSE) {
        License license = (License) value;
        Build.License.Builder licensePb = Build.License.newBuilder();
        for (License.LicenseType licenseType : license.getLicenseTypes()) {
            licensePb.addLicenseType(licenseType.toString());
        }
        for (Label exception : license.getExceptions()) {
            licensePb.addException(exception.toString());
        }
        builder.setLicense(licensePb);
    } else if (type == STRING_DICT) {
        Map<String, String> dict = (Map<String, String>) value;
        for (Map.Entry<String, String> keyValueList : dict.entrySet()) {
            StringDictEntry.Builder entry = StringDictEntry.newBuilder().setKey(keyValueList.getKey()).setValue(keyValueList.getValue());
            builder.addStringDictValue(entry);
        }
    } else if (type == STRING_DICT_UNARY) {
        Map<String, String> dict = (Map<String, String>) value;
        for (Map.Entry<String, String> dictEntry : dict.entrySet()) {
            StringDictUnaryEntry.Builder entry = StringDictUnaryEntry.newBuilder().setKey(dictEntry.getKey()).setValue(dictEntry.getValue());
            builder.addStringDictUnaryValue(entry);
        }
    } else if (type == STRING_LIST_DICT) {
        Map<String, List<String>> dict = (Map<String, List<String>>) value;
        for (Map.Entry<String, List<String>> dictEntry : dict.entrySet()) {
            StringListDictEntry.Builder entry = StringListDictEntry.newBuilder().setKey(dictEntry.getKey());
            for (Object dictEntryValue : dictEntry.getValue()) {
                entry.addValue(dictEntryValue.toString());
            }
            builder.addStringListDictValue(entry);
        }
    } else if (type == LABEL_DICT_UNARY) {
        Map<String, Label> dict = (Map<String, Label>) value;
        for (Map.Entry<String, Label> dictEntry : dict.entrySet()) {
            LabelDictUnaryEntry.Builder entry = LabelDictUnaryEntry.newBuilder().setKey(dictEntry.getKey()).setValue(dictEntry.getValue().toString());
            builder.addLabelDictUnaryValue(entry);
        }
    } else if (type == LABEL_KEYED_STRING_DICT) {
        Map<Label, String> dict = (Map<Label, String>) value;
        for (Map.Entry<Label, String> dictEntry : dict.entrySet()) {
            LabelKeyedStringDictEntry.Builder entry = LabelKeyedStringDictEntry.newBuilder().setKey(dictEntry.getKey().toString()).setValue(dictEntry.getValue());
            builder.addLabelKeyedStringDictValue(entry);
        }
    } else if (type == FILESET_ENTRY_LIST) {
        List<FilesetEntry> filesetEntries = (List<FilesetEntry>) value;
        for (FilesetEntry filesetEntry : filesetEntries) {
            Build.FilesetEntry.Builder filesetEntryPb = Build.FilesetEntry.newBuilder().setSource(filesetEntry.getSrcLabel().toString()).setDestinationDirectory(filesetEntry.getDestDir().getPathString()).setSymlinkBehavior(symlinkBehaviorToPb(filesetEntry.getSymlinkBehavior())).setStripPrefix(filesetEntry.getStripPrefix()).setFilesPresent(filesetEntry.getFiles() != null);
            if (filesetEntry.getFiles() != null) {
                for (Label file : filesetEntry.getFiles()) {
                    filesetEntryPb.addFile(file.toString());
                }
            }
            if (filesetEntry.getExcludes() != null) {
                for (String exclude : filesetEntry.getExcludes()) {
                    filesetEntryPb.addExclude(exclude);
                }
            }
            builder.addFilesetListValue(filesetEntryPb);
        }
    } else {
        throw new AssertionError("Unknown type: " + type);
    }
}
Also used : Builder(com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.Builder) Label(com.google.devtools.build.lib.cmdline.Label) SelectorEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry) LabelKeyedStringDictEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.LabelKeyedStringDictEntry) LabelDictUnaryEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.LabelDictUnaryEntry) StringDictEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.StringDictEntry) LabelListDictEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.LabelListDictEntry) StringDictUnaryEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.StringDictUnaryEntry) Entry(java.util.Map.Entry) StringListDictEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.StringListDictEntry) LabelDictUnaryEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.LabelDictUnaryEntry) StringDictUnaryEntry(com.google.devtools.build.lib.query2.proto.proto2api.Build.StringDictUnaryEntry) Collection(java.util.Collection) List(java.util.List) SelectorList(com.google.devtools.build.lib.packages.BuildType.SelectorList) Map(java.util.Map)

Example 4 with Builder

use of com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult.Builder 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)2 SelectorList (com.google.devtools.build.lib.packages.BuildType.SelectorList)2 Builder (com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.Builder)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)1 Selector (com.google.devtools.build.lib.packages.BuildType.Selector)1 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)1 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)1 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)1 QueryException (com.google.devtools.build.lib.query2.engine.QueryException)1 OutputFormatter (com.google.devtools.build.lib.query2.output.OutputFormatter)1 Build (com.google.devtools.build.lib.query2.proto.proto2api.Build)1 SelectorEntry (com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry)1 LabelDictUnaryEntry (com.google.devtools.build.lib.query2.proto.proto2api.Build.LabelDictUnaryEntry)1