use of com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.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);
}
}
use of com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.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();
}
}));
}
use of com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.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);
}
}
use of com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.SelectorEntry.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);
}
Aggregations