Search in sources :

Example 1 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class SkyframeBuilder method processResult.

/**
   * Process the Skyframe update, taking into account the keepGoing setting.
   *
   * <p>Returns optional {@link ExitCode} based on following conditions: 1. null, if result had no
   * errors. 2. Optional.absent(), if result had errors but none of the errors specified an exit
   * code. 3. Optional.of(e), if result had errors and one of them specified exit code 'e'. Throws
   * on fail-fast failures.
   */
@Nullable
private static Optional<ExitCode> processResult(ExtendedEventHandler eventHandler, EvaluationResult<?> result, boolean keepGoing, SkyframeExecutor skyframeExecutor) throws BuildFailedException, TestExecException {
    if (result.hasError()) {
        for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
            Iterable<CycleInfo> cycles = entry.getValue().getCycleInfo();
            skyframeExecutor.reportCycles(eventHandler, cycles, entry.getKey());
        }
        if (result.getCatastrophe() != null) {
            rethrow(result.getCatastrophe());
        }
        if (keepGoing) {
            // If build fails and keepGoing is true, an exit code is assigned using reported errors
            // in the following order:
            //   1. First infrastructure error with non-null exit code
            //   2. First non-infrastructure error with non-null exit code
            //   3. Null (later default to 1)
            ExitCode exitCode = null;
            for (Map.Entry<SkyKey, ErrorInfo> error : result.errorMap().entrySet()) {
                Throwable cause = error.getValue().getException();
                if (cause instanceof ActionExecutionException) {
                    ActionExecutionException actionExecutionCause = (ActionExecutionException) cause;
                    ExitCode code = actionExecutionCause.getExitCode();
                    // a lower 'reporting' priority.
                    if (ExitCodeComparator.INSTANCE.compare(code, exitCode) > 0) {
                        exitCode = code;
                    }
                }
            }
            return Optional.fromNullable(exitCode);
        }
        ErrorInfo errorInfo = Preconditions.checkNotNull(result.getError(), result);
        Exception exception = errorInfo.getException();
        if (exception == null) {
            Preconditions.checkState(!Iterables.isEmpty(errorInfo.getCycleInfo()), errorInfo);
            // cycles above.
            throw new BuildFailedException(null, /*hasCatastrophe=*/
            false);
        } else {
            rethrow(exception);
        }
    }
    return null;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) ExitCode(com.google.devtools.build.lib.util.ExitCode) CycleInfo(com.google.devtools.build.skyframe.CycleInfo) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) Map(java.util.Map) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException) TestExecException(com.google.devtools.build.lib.actions.TestExecException) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Nullable(javax.annotation.Nullable)

Example 2 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class SkylarkImportLookupFunctionTest method testSkylarkImportLookupNoBuildFile.

@Test
public void testSkylarkImportLookupNoBuildFile() throws Exception {
    scratch.file("pkg/ext.bzl", "");
    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("Extension file not found. Unable to load package for '//pkg:ext.bzl': " + "BUILD file not found on package path", errorMessage);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Test(org.junit.Test)

Example 3 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class SkylarkImportLookupFunctionTest method testSkylarkImportLookupNoBuildFileForLoad.

@Test
public void testSkylarkImportLookupNoBuildFileForLoad() throws Exception {
    scratch.file("pkg2/BUILD");
    scratch.file("pkg1/ext.bzl", "a = 1");
    scratch.file("pkg2/ext.bzl", "load('/pkg1/ext', '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("Extension file not found. Unable to load package for '//pkg:ext.bzl': " + "BUILD file not found on package path", errorMessage);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Test(org.junit.Test)

Example 4 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class ASTFileLookupFunctionTest method testLoadWithNonExistentBuildFile.

@Test
public void testLoadWithNonExistentBuildFile() throws Exception {
    invalidatePackages();
    SkyKey skyKey = ASTFileLookupValue.key(Label.parseAbsoluteUnchecked("@a_remote_repo//remote_pkg:BUILD"));
    EvaluationResult<ASTFileLookupValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
    false, reporter);
    ErrorInfo errorInfo = result.getError(skyKey);
    Throwable e = errorInfo.getException();
    assertEquals(skyKey, errorInfo.getRootCauseOfException());
    assertThat(e).isInstanceOf(ErrorReadingSkylarkExtensionException.class);
    assertThat(e.getMessage()).contains("no such package '@a_remote_repo//remote_pkg'");
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Test(org.junit.Test)

Example 5 with ErrorInfo

use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.

the class PackageFunctionTest method testNonExistingSkylarkExtension.

@Test
public void testNonExistingSkylarkExtension() throws Exception {
    reporter.removeHandler(failFastHandler);
    scratch.file("test/skylark/BUILD", "load('/test/skylark/bad_extension', 'some_symbol')", "genrule(name = gr,", "    outs = ['out.txt'],", "    cmd = 'echo hello >@')");
    invalidatePackages();
    SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//test/skylark"));
    EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
    false, reporter);
    assertTrue(result.hasError());
    ErrorInfo errorInfo = result.getError(skyKey);
    String expectedMsg = "error loading package 'test/skylark': " + "Extension file not found. Unable to load file '//test/skylark:bad_extension.bzl': " + "file doesn't exist or isn't a file";
    assertThat(errorInfo.getException()).hasMessage(expectedMsg);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) Test(org.junit.Test)

Aggregations

ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)30 SkyKey (com.google.devtools.build.skyframe.SkyKey)29 Test (org.junit.Test)19 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)10 Path (com.google.devtools.build.lib.vfs.Path)9 SkyValue (com.google.devtools.build.skyframe.SkyValue)8 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)6 Map (java.util.Map)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Label (com.google.devtools.build.lib.cmdline.Label)4 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)3 Dirent (com.google.devtools.build.lib.vfs.Dirent)3 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)3 RecordingDifferencer (com.google.devtools.build.skyframe.RecordingDifferencer)3 IOException (java.io.IOException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Artifact (com.google.devtools.build.lib.actions.Artifact)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2