aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
diff options
context:
space:
mode:
authorGravatar Michael Staib <mstaib@google.com>2016-10-04 21:26:37 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-10-05 12:26:44 +0000
commit6e5e8fb01e536d46ce789bc8e4e0ca167651cb74 (patch)
treea991658be5aa986758216c22926f2990fb8f5dcd /src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
parent930e89c2d2880f3342eea90e9b1160989f852ba6 (diff)
Enable Bazel commands to exit at any time.
This is the first step on a journey toward allowing commands to AbruptExit wherever they please, similar to how the user can press Ctrl+C at any time and we (should) bail out as fast as we can. By interrupting the command's main thread, we at least offer the command the ability to see that an error requiring a bail has happened, and it should trigger at potentially more locations, rather than just between phases. -- MOS_MIGRATED_REVID=135152330
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
index 974a63228c..afdde3c365 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
@@ -342,9 +342,19 @@ public final class BuildTool {
}
exitCode = e.getExitCode() != null ? e.getExitCode() : ExitCode.BUILD_FAILURE;
} catch (InterruptedException e) {
- exitCode = ExitCode.INTERRUPTED;
- env.getReporter().handle(Event.error("build interrupted"));
- env.getEventBus().post(new BuildInterruptedEvent());
+ // We may have been interrupted by an error, or the user's interruption may have raced with
+ // an error, so check to see if we should report that error code instead.
+ exitCode = env.getPendingExitCode();
+ if (exitCode == null) {
+ exitCode = ExitCode.INTERRUPTED;
+ env.getReporter().handle(Event.error("build interrupted"));
+ env.getEventBus().post(new BuildInterruptedEvent());
+ } else {
+ // Report the exception from the environment - the exception we're handling here is just an
+ // interruption.
+ reportExceptionError(env.getPendingException());
+ result.setCatastrophe();
+ }
} catch (TargetParsingException | LoadingFailedException | ViewCreationFailedException e) {
exitCode = ExitCode.PARSING_FAILURE;
reportExceptionError(e);