Search in sources :

Example 1 with Argument

use of com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument 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 Argument

use of com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument in project bazel by bazelbuild.

the class QueryExpressionMapper method map.

public QueryExpression map(FunctionExpression functionExpression) {
    boolean changed = false;
    ImmutableList.Builder<Argument> mappedArgumentBuilder = ImmutableList.builder();
    for (Argument argument : functionExpression.getArgs()) {
        switch(argument.getType()) {
            case EXPRESSION:
                {
                    QueryExpression expr = argument.getExpression();
                    QueryExpression mappedExpression = expr.getMapped(this);
                    mappedArgumentBuilder.add(Argument.of(mappedExpression));
                    if (expr != mappedExpression) {
                        changed = true;
                    }
                    break;
                }
            default:
                mappedArgumentBuilder.add(argument);
                break;
        }
    }
    return changed ? new FunctionExpression(functionExpression.getFunction(), mappedArgumentBuilder.build()) : functionExpression;
}
Also used : Argument(com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with Argument

use of com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument in project bazel by bazelbuild.

the class JavaToolchainDataParser method parseBuildRuleProto.

private static JavaToolchainData parseBuildRuleProto(Build.Rule rule) {
    String source = "";
    String target = "";
    ImmutableList<String> bootclasspath = ImmutableList.of();
    ImmutableList<String> extclasspath = ImmutableList.of();
    String encoding = "";
    ImmutableList<String> xlint = ImmutableList.of();
    ImmutableList<String> misc = ImmutableList.of();
    ImmutableList<String> jvmOpts = ImmutableList.of();
    SupportsWorkers javacSupportsWorkers = SupportsWorkers.NO;
    for (Build.Attribute attribute : rule.getAttributeList()) {
        switch(attribute.getName()) {
            case "source_version":
                source = attribute.getStringValue();
                break;
            case "target_version":
                target = attribute.getStringValue();
                break;
            case "bootclasspath":
                bootclasspath = ImmutableList.copyOf(attribute.getStringListValueList());
                break;
            case "extclasspath":
                extclasspath = ImmutableList.copyOf(attribute.getStringListValueList());
                break;
            case "encoding":
                encoding = attribute.getStringValue();
                break;
            case "xlint":
                xlint = ImmutableList.copyOf(attribute.getStringListValueList());
                break;
            case "misc":
                {
                    List<String> options = new ArrayList<>();
                    for (String option : attribute.getStringListValueList()) {
                        try {
                            ShellUtils.tokenize(options, option);
                        } catch (ShellUtils.TokenizationException e) {
                            // Tokenization failed; this likely means that the user
                            // did not want tokenization to happen on the argument.
                            // (see JavaHelper.tokenizeJavaOptions)
                            options.add(option);
                        }
                    }
                    misc = ImmutableList.copyOf(options);
                    break;
                }
            case "jvm_opts":
                jvmOpts = ImmutableList.copyOf(attribute.getStringListValueList());
                break;
            case "javac_supports_workers":
                if (attribute.getBooleanValue()) {
                    javacSupportsWorkers = SupportsWorkers.YES;
                }
                break;
        }
    }
    return new JavaToolchainData(source, target, bootclasspath, extclasspath, encoding, xlint, misc, jvmOpts, javacSupportsWorkers);
}
Also used : SupportsWorkers(com.google.devtools.build.lib.rules.java.JavaToolchainData.SupportsWorkers) Build(com.google.devtools.build.lib.query2.proto.proto2api.Build) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 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 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 Argument (com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument)1 QueryException (com.google.devtools.build.lib.query2.engine.QueryException)1 Build (com.google.devtools.build.lib.query2.proto.proto2api.Build)1 SupportsWorkers (com.google.devtools.build.lib.rules.java.JavaToolchainData.SupportsWorkers)1 TransitiveTraversalValue (com.google.devtools.build.lib.skyframe.TransitiveTraversalValue)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 SkyValue (com.google.devtools.build.skyframe.SkyValue)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1