diff options
author | Janak Ramakrishnan <janakr@google.com> | 2015-08-10 21:53:54 +0000 |
---|---|---|
committer | Laszlo Csomor <laszlocsomor@google.com> | 2015-08-11 07:53:44 +0000 |
commit | c28fc96e6269c09fa817e17a0b72c11e2a4a5532 (patch) | |
tree | c2a46c00dc995ca1aa54e27bcdf28a9039f8c3ff /src/main/java/com/google/devtools | |
parent | e079284f106b72a53d0b37969338443abfa3bacf (diff) |
Tolerate BuildFileNotFoundExceptions during the execution phase.
--
MOS_MIGRATED_REVID=100317285
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/BuilderUtils.java | 55 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/buildtool/SkyframeBuilder.java | 48 |
2 files changed, 46 insertions, 57 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/BuilderUtils.java b/src/main/java/com/google/devtools/build/lib/actions/BuilderUtils.java deleted file mode 100644 index f30ecfec27..0000000000 --- a/src/main/java/com/google/devtools/build/lib/actions/BuilderUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.actions; - -/** - * Methods needed by {@code SkyframeBuilder}. - */ -public final class BuilderUtils { - - private BuilderUtils() {} - - /** - * Figure out why an action's execution failed and rethrow the right kind of exception. - */ - public static void rethrow(Throwable cause) throws BuildFailedException, TestExecException { - Throwable innerCause = cause.getCause(); - if (innerCause instanceof TestExecException) { - throw (TestExecException) innerCause; - } - if (cause instanceof ActionExecutionException) { - ActionExecutionException actionExecutionCause = (ActionExecutionException) cause; - // Sometimes ActionExecutionExceptions are caused by Actions with no owner. - String message = - (actionExecutionCause.getLocation() != null) ? - (actionExecutionCause.getLocation().print() + " " + cause.getMessage()) : - cause.getMessage(); - throw new BuildFailedException(message, actionExecutionCause.isCatastrophe(), - actionExecutionCause.getAction(), actionExecutionCause.getRootCauses(), - /*errorAlreadyShown=*/ !actionExecutionCause.showError()); - } else if (cause instanceof MissingInputFileException) { - throw new BuildFailedException(cause.getMessage()); - } else if (cause instanceof RuntimeException) { - throw (RuntimeException) cause; - } else if (cause instanceof Error) { - throw (Error) cause; - } else { - // We encountered an exception we don't think we should have encountered. This can indicate - // a bug in our code, such as lower level exceptions not being properly handled, or in our - // expectations in this method. - throw new IllegalArgumentException("action terminated with " - + "unexpected exception: " + cause.getMessage(), cause); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/SkyframeBuilder.java b/src/main/java/com/google/devtools/build/lib/buildtool/SkyframeBuilder.java index fff507e922..d01609d3d5 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/SkyframeBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/SkyframeBuilder.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.buildtool; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Range; @@ -22,17 +23,20 @@ import com.google.common.collect.Sets; import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionCacheChecker; +import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.ActionExecutionStatusReporter; import com.google.devtools.build.lib.actions.ActionInputFileCache; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.BuildFailedException; -import com.google.devtools.build.lib.actions.BuilderUtils; import com.google.devtools.build.lib.actions.Executor; +import com.google.devtools.build.lib.actions.MissingInputFileException; import com.google.devtools.build.lib.actions.ResourceManager; import com.google.devtools.build.lib.actions.TestExecException; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.TargetCompleteEvent; +import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.rules.test.TestProvider; +import com.google.devtools.build.lib.runtime.BugReport; import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog; import com.google.devtools.build.lib.skyframe.ActionExecutionValue; import com.google.devtools.build.lib.skyframe.Builder; @@ -192,12 +196,52 @@ public class SkyframeBuilder implements Builder { // error map may be empty in the case of a catastrophe. throw new BuildFailedException(); } else { - BuilderUtils.rethrow(Preconditions.checkNotNull(result.getError().getException())); + rethrow(Preconditions.checkNotNull(result.getError().getException())); } } return true; } + /** Figure out why an action's execution failed and rethrow the right kind of exception. */ + @VisibleForTesting + public static void rethrow(Throwable cause) throws BuildFailedException, TestExecException { + Throwable innerCause = cause.getCause(); + if (innerCause instanceof TestExecException) { + throw (TestExecException) innerCause; + } + if (cause instanceof ActionExecutionException) { + ActionExecutionException actionExecutionCause = (ActionExecutionException) cause; + // Sometimes ActionExecutionExceptions are caused by Actions with no owner. + String message = + (actionExecutionCause.getLocation() != null) + ? (actionExecutionCause.getLocation().print() + " " + cause.getMessage()) + : cause.getMessage(); + throw new BuildFailedException( + message, + actionExecutionCause.isCatastrophe(), + actionExecutionCause.getAction(), + actionExecutionCause.getRootCauses(), + /*errorAlreadyShown=*/ !actionExecutionCause.showError()); + } else if (cause instanceof MissingInputFileException) { + throw new BuildFailedException(cause.getMessage()); + } else if (cause instanceof BuildFileNotFoundException) { + // Sadly, this can happen because we may load new packages during input discovery. Any + // failures reading those packages shouldn't terminate the build, but in Skyframe they do. + BugReport.sendBugReport(cause, ImmutableList.<String>of()); + throw new BuildFailedException(cause.getMessage()); + } else if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else if (cause instanceof Error) { + throw (Error) cause; + } else { + // We encountered an exception we don't think we should have encountered. This can indicate + // a bug in our code, such as lower level exceptions not being properly handled, or in our + // expectations in this method. + throw new IllegalArgumentException( + "action terminated with " + "unexpected exception: " + cause.getMessage(), cause); + } + } + private static int countTestActions(Iterable<ConfiguredTarget> testTargets) { int count = 0; for (ConfiguredTarget testTarget : testTargets) { |