use of com.google.devtools.build.skyframe.ErrorInfo 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.skyframe.ErrorInfo in project bazel by bazelbuild.
the class TimestampBuilderTestCase method createBuilder.
protected Builder createBuilder(final ActionCache actionCache, final int threadCount, final boolean keepGoing, @Nullable EvaluationProgressReceiver evaluationProgressReceiver) throws Exception {
AtomicReference<PathPackageLocator> pkgLocator = new AtomicReference<>(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)));
AtomicReference<TimestampGranularityMonitor> tsgmRef = new AtomicReference<>(tsgm);
BlazeDirectories directories = new BlazeDirectories(rootDirectory, outputBase, rootDirectory, TestConstants.PRODUCT_NAME);
ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocator, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, directories);
differencer = new RecordingDifferencer();
ActionExecutionStatusReporter statusReporter = ActionExecutionStatusReporter.create(new StoredEventHandler());
final SkyframeActionExecutor skyframeActionExecutor = new SkyframeActionExecutor(eventBusRef, new AtomicReference<>(statusReporter));
Path actionOutputBase = scratch.dir("/usr/local/google/_blaze_jrluser/FAKEMD5/action_out/");
skyframeActionExecutor.setActionLogBufferPathGenerator(new ActionLogBufferPathGenerator(actionOutputBase));
ActionInputFileCache cache = new SingleBuildFileCache(rootDirectory.getPathString(), scratch.getFileSystem());
skyframeActionExecutor.setFileCache(cache);
final InMemoryMemoizingEvaluator evaluator = new InMemoryMemoizingEvaluator(ImmutableMap.<SkyFunctionName, SkyFunction>builder().put(SkyFunctions.FILE_STATE, new FileStateFunction(tsgmRef, externalFilesHelper)).put(SkyFunctions.FILE, new FileFunction(pkgLocator)).put(SkyFunctions.ARTIFACT, new ArtifactFunction(Predicates.<PathFragment>alwaysFalse())).put(SkyFunctions.ACTION_EXECUTION, new ActionExecutionFunction(skyframeActionExecutor, tsgmRef)).put(SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null)).put(SkyFunctions.PACKAGE_LOOKUP, new PackageLookupFunction(null, CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD))).put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())).put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(TestRuleClassProvider.getRuleClassProvider(), TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create(TestRuleClassProvider.getRuleClassProvider(), scratch.getFileSystem()), directories)).put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()).put(SkyFunctions.ACTION_TEMPLATE_EXPANSION, new DelegatingActionTemplateExpansionFunction()).build(), differencer, evaluationProgressReceiver);
final SequentialBuildDriver driver = new SequentialBuildDriver(evaluator);
PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
PrecomputedValue.ACTION_ENV.set(differencer, ImmutableMap.<String, String>of());
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
return new Builder() {
private void setGeneratingActions() {
if (evaluator.getExistingValueForTesting(OWNER_KEY) == null) {
differencer.inject(ImmutableMap.of(OWNER_KEY, new ActionLookupValue(ImmutableList.copyOf(actions))));
}
}
@Override
public void buildArtifacts(Reporter reporter, Set<Artifact> artifacts, Set<ConfiguredTarget> parallelTests, Set<ConfiguredTarget> exclusiveTests, Collection<ConfiguredTarget> targetsToBuild, Collection<AspectValue> aspects, Executor executor, Set<ConfiguredTarget> builtTargets, boolean explain, Range<Long> lastExecutionTimeRange, TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, AbruptExitException, InterruptedException, TestExecException {
skyframeActionExecutor.prepareForExecution(reporter, executor, keepGoing, /*explain=*/
false, new ActionCacheChecker(actionCache, null, ALWAYS_EXECUTE_FILTER, null), null);
List<SkyKey> keys = new ArrayList<>();
for (Artifact artifact : artifacts) {
keys.add(ArtifactSkyKey.key(artifact, true));
}
setGeneratingActions();
EvaluationResult<SkyValue> result = driver.evaluate(keys, keepGoing, threadCount, reporter);
if (result.hasError()) {
boolean hasCycles = false;
for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
Iterable<CycleInfo> cycles = entry.getValue().getCycleInfo();
hasCycles |= !Iterables.isEmpty(cycles);
}
if (hasCycles) {
throw new BuildFailedException(CYCLE_MSG);
} else if (result.errorMap().isEmpty() || keepGoing) {
throw new BuildFailedException();
} else {
SkyframeBuilder.rethrow(Preconditions.checkNotNull(result.getError().getException()));
}
}
}
};
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class SkylarkImportLookupFunctionTest method testSkylarkAbsoluteImportFilenameWithControlChars.
@Test
public void testSkylarkAbsoluteImportFilenameWithControlChars() throws Exception {
scratch.file("pkg/BUILD", "");
scratch.file("pkg/ext.bzl", "load('/pkg/oops ', 'a')");
SkyKey skylarkImportLookupKey = SkylarkImportLookupValue.key(Label.parseAbsoluteUnchecked("//pkg:ext.bzl"), false);
EvaluationResult<SkylarkImportLookupValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skylarkImportLookupKey);
String errorMessage = errorInfo.getException().getMessage();
assertEquals("invalid target name 'oops<?>.bzl': " + "target names may not contain non-printable characters: '\\x00'", errorMessage);
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class TargetMarkerFunctionTest method getErrorFromTargetValue.
private Throwable getErrorFromTargetValue(String labelName) throws Exception {
reporter.removeHandler(failFastHandler);
SkyKey targetKey = TargetMarkerValue.key(Label.parseAbsolute(labelName));
EvaluationResult<TargetMarkerValue> evaluationResult = SkyframeExecutorTestUtils.evaluate(skyframeExecutor, targetKey, /*keepGoing=*/
false, reporter);
Preconditions.checkState(evaluationResult.hasError());
reporter.addHandler(failFastHandler);
ErrorInfo errorInfo = evaluationResult.getError(skyKey(labelName));
// Ensures that TargetFunction rethrows all transitive exceptions.
assertEquals(targetKey, Iterables.getOnlyElement(errorInfo.getRootCauses()));
return errorInfo.getException();
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class ASTFileLookupFunctionTest method testIOExceptionOccursDuringReading.
@Test
public void testIOExceptionOccursDuringReading() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("/workspace/tools/build_rules/BUILD");
scratch.file("foo/BUILD", "genrule(name = 'foo',", " outs = ['out.txt'],", " cmd = 'echo hello >@')");
mockFS.statThrowsIoException = true;
// We don't want to fail early on config creation.
invalidatePackages(/*alsoConfigs=*/
false);
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
Throwable e = errorInfo.getException();
assertEquals(skyKey, errorInfo.getRootCauseOfException());
assertThat(e).isInstanceOf(NoSuchPackageException.class);
assertThat(e.getMessage()).contains("bork");
}
Aggregations