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();
}
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));
}
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);
}
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));
}
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);
}
}
Aggregations