Search in sources :

Example 1 with ParseFailureListener

use of com.google.devtools.build.lib.pkgcache.ParseFailureListener in project bazel by bazelbuild.

the class PrepareDepsOfPatternsFunction method getSkyKeys.

public static ImmutableList<SkyKey> getSkyKeys(SkyKey skyKey, EventHandler eventHandler) {
    TargetPatternSequence targetPatternSequence = (TargetPatternSequence) skyKey.argument();
    Iterable<PrepareDepsOfPatternSkyKeyOrException> keysMaybe = PrepareDepsOfPatternValue.keys(targetPatternSequence.getPatterns(), targetPatternSequence.getOffset());
    ImmutableList.Builder<SkyKey> skyKeyBuilder = ImmutableList.builder();
    boolean handlerIsParseFailureListener = eventHandler instanceof ParseFailureListener;
    for (PrepareDepsOfPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
        try {
            skyKeyBuilder.add(skyKeyOrException.getSkyKey());
        } catch (TargetParsingException e) {
            handleTargetParsingException(eventHandler, handlerIsParseFailureListener, skyKeyOrException.getOriginalPattern(), e);
        }
    }
    return skyKeyBuilder.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ImmutableList(com.google.common.collect.ImmutableList) ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener) PrepareDepsOfPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternValue.PrepareDepsOfPatternSkyKeyOrException) TargetPatternSequence(com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternsValue.TargetPatternSequence)

Example 2 with ParseFailureListener

use of com.google.devtools.build.lib.pkgcache.ParseFailureListener in project bazel by bazelbuild.

the class SkyframeTargetPatternEvaluator method parseTargetPatternList.

/**
   * Loads a list of target patterns (eg, "foo/..."). When policy is set to FILTER_TESTS,
   * test_suites are going to be expanded.
   */
ResolvedTargets<Target> parseTargetPatternList(String offset, ExtendedEventHandler eventHandler, List<String> targetPatterns, FilteringPolicy policy, boolean keepGoing) throws InterruptedException, TargetParsingException {
    Iterable<TargetPatternSkyKeyOrException> keysMaybe = TargetPatternValue.keys(targetPatterns, policy, offset);
    ImmutableList.Builder<SkyKey> builder = ImmutableList.builder();
    for (TargetPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
        try {
            builder.add(skyKeyOrException.getSkyKey());
        } catch (TargetParsingException e) {
            if (!keepGoing) {
                throw e;
            }
            String pattern = skyKeyOrException.getOriginalPattern();
            eventHandler.handle(Event.error("Skipping '" + pattern + "': " + e.getMessage()));
            if (eventHandler instanceof ParseFailureListener) {
                ((ParseFailureListener) eventHandler).parsingError(pattern, e.getMessage());
            }
        }
    }
    ImmutableList<SkyKey> skyKeys = builder.build();
    return parseTargetPatternKeys(targetPatterns, skyKeys, SkyframeExecutor.DEFAULT_THREAD_COUNT, keepGoing, eventHandler, createTargetPatternEvaluatorUtil(policy, eventHandler, keepGoing));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ImmutableList(com.google.common.collect.ImmutableList) ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener) TargetPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException)

Example 3 with ParseFailureListener

use of com.google.devtools.build.lib.pkgcache.ParseFailureListener in project bazel by bazelbuild.

the class SkyframeTargetPatternEvaluator method parseTargetPatternKeys.

ResolvedTargets<Target> parseTargetPatternKeys(List<String> targetPattern, Iterable<SkyKey> patternSkyKeys, int numThreads, boolean keepGoing, ExtendedEventHandler eventHandler, TargetPatternsResultBuilder finalTargetSetEvaluator) throws InterruptedException, TargetParsingException {
    EvaluationResult<TargetPatternValue> result = skyframeExecutor.targetPatterns(patternSkyKeys, numThreads, keepGoing, eventHandler);
    String errorMessage = null;
    for (SkyKey key : patternSkyKeys) {
        TargetPatternValue resultValue = result.get(key);
        if (resultValue != null) {
            ResolvedTargets<Label> results = resultValue.getTargets();
            if (((TargetPatternValue.TargetPatternKey) key.argument()).isNegative()) {
                finalTargetSetEvaluator.addLabelsOfNegativePattern(results);
            } else {
                finalTargetSetEvaluator.addLabelsOfPositivePattern(results);
            }
        } else {
            TargetPatternValue.TargetPatternKey patternKey = (TargetPatternValue.TargetPatternKey) key.argument();
            String rawPattern = patternKey.getPattern();
            ErrorInfo error = result.errorMap().get(key);
            if (error == null) {
                Preconditions.checkState(!keepGoing);
                continue;
            }
            if (error.getException() != null) {
                // This exception may not be a TargetParsingException because in a nokeep_going build, the
                // target pattern parser may swallow a NoSuchPackageException but the framework will
                // bubble it up anyway.
                Preconditions.checkArgument(!keepGoing || error.getException() instanceof TargetParsingException, error);
                errorMessage = error.getException().getMessage();
            } else if (!Iterables.isEmpty(error.getCycleInfo())) {
                errorMessage = "cycles detected during target parsing";
                skyframeExecutor.getCyclesReporter().reportCycles(error.getCycleInfo(), key, eventHandler);
            } else {
                throw new IllegalStateException(error.toString());
            }
            if (keepGoing) {
                eventHandler.handle(Event.error("Skipping '" + rawPattern + "': " + errorMessage));
                eventHandler.post(PatternExpandingError.skipped(rawPattern, errorMessage));
            }
            finalTargetSetEvaluator.setError();
            if (eventHandler instanceof ParseFailureListener) {
                ParseFailureListener parseListener = (ParseFailureListener) eventHandler;
                parseListener.parsingError(rawPattern, errorMessage);
            }
        }
    }
    if (result.hasError()) {
        Preconditions.checkState(errorMessage != null, "unexpected errors: %s", result.errorMap());
        finalTargetSetEvaluator.setError();
        if (!keepGoing) {
            eventHandler.post(PatternExpandingError.failed(targetPattern, errorMessage));
            throw new TargetParsingException(errorMessage);
        }
    }
    WalkableGraph walkableGraph = Preconditions.checkNotNull(result.getWalkableGraph(), result);
    return finalTargetSetEvaluator.build(walkableGraph);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Label(com.google.devtools.build.lib.cmdline.Label) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener)

Example 4 with ParseFailureListener

use of com.google.devtools.build.lib.pkgcache.ParseFailureListener in project bazel by bazelbuild.

the class PrepareDepsOfPatternsFunction method compute.

/**
   * Given a {@link SkyKey} that contains a sequence of target patterns, when this function returns
   * {@link PrepareDepsOfPatternsValue}, then all targets matching that sequence, and those targets'
   * transitive dependencies, have been loaded.
   */
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    EventHandler eventHandler = env.getListener();
    ImmutableList<SkyKey> skyKeys = getSkyKeys(skyKey, eventHandler);
    Map<SkyKey, ValueOrException<TargetParsingException>> tokensByKey = env.getValuesOrThrow(skyKeys, TargetParsingException.class);
    if (env.valuesMissing()) {
        return null;
    }
    boolean handlerIsParseFailureListener = eventHandler instanceof ParseFailureListener;
    for (SkyKey key : skyKeys) {
        try {
            // The only exception type throwable by PrepareDepsOfPatternFunction is
            // TargetParsingException. Therefore all ValueOrException values in the map will either
            // be non-null or throw TargetParsingException when get is called.
            Preconditions.checkNotNull(tokensByKey.get(key).get());
        } catch (TargetParsingException e) {
            // If a target pattern can't be evaluated, notify the user of the problem and keep going.
            handleTargetParsingException(eventHandler, handlerIsParseFailureListener, key, e);
        }
    }
    return new PrepareDepsOfPatternsValue(getTargetPatternKeys(skyKeys));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener) EventHandler(com.google.devtools.build.lib.events.EventHandler) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) Nullable(javax.annotation.Nullable)

Example 5 with ParseFailureListener

use of com.google.devtools.build.lib.pkgcache.ParseFailureListener in project bazel by bazelbuild.

the class PrepareDepsOfPatternsFunction method handleTargetParsingException.

private static void handleTargetParsingException(EventHandler eventHandler, boolean handlerIsParseFailureListener, String rawPattern, TargetParsingException e) {
    String errorMessage = e.getMessage();
    eventHandler.handle(Event.error("Skipping '" + rawPattern + "': " + errorMessage));
    if (handlerIsParseFailureListener) {
        ParseFailureListener parseListener = (ParseFailureListener) eventHandler;
        parseListener.parsingError(rawPattern, errorMessage);
    }
}
Also used : ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener)

Aggregations

ParseFailureListener (com.google.devtools.build.lib.pkgcache.ParseFailureListener)5 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)4 ImmutableList (com.google.common.collect.ImmutableList)2 Label (com.google.devtools.build.lib.cmdline.Label)1 EventHandler (com.google.devtools.build.lib.events.EventHandler)1 PrepareDepsOfPatternSkyKeyOrException (com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternValue.PrepareDepsOfPatternSkyKeyOrException)1 TargetPatternSequence (com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternsValue.TargetPatternSequence)1 TargetPatternSkyKeyOrException (com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException)1 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)1 ValueOrException (com.google.devtools.build.skyframe.ValueOrException)1 WalkableGraph (com.google.devtools.build.skyframe.WalkableGraph)1 Nullable (javax.annotation.Nullable)1