diff options
author | 2017-09-12 14:42:27 +0200 | |
---|---|---|
committer | 2017-09-12 15:48:17 +0200 | |
commit | 87cc92e5df35d02a7c9bc50b229c513563dc1689 (patch) | |
tree | ff52660d47e154fcabb959aade5386353cb07ee3 /src/main/java/com | |
parent | 139543d3320f0336b012c2af020ed68fe5c49367 (diff) |
BEP: always close stream, even if aborted due to missing tests
If testing is requested, but no tests are found, the build is aborted.
Ensure that even in this case the steam of build events is internally
closed (i.e., all announced events are reported, the last event is marked
as such).
Change-Id: I88763ed6ccd7793deedbcb3428df7e8d289efa23
PiperOrigin-RevId: 168364127
Diffstat (limited to 'src/main/java/com')
3 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java index 069044cbe4..189ce3fb06 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java @@ -57,6 +57,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetView; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Reporter; +import com.google.devtools.build.lib.runtime.commands.NoTestsFound; import com.google.devtools.build.lib.util.Pair; import java.util.ArrayList; import java.util.Collection; @@ -374,6 +375,11 @@ public class BuildEventStreamer implements EventHandler { } @Subscribe + public void noTestsFound(NoTestsFound event) { + buildComplete(); + } + + @Subscribe public void buildEvent(BuildEvent event) { if (isActionWithoutError(event) || bufferUntilPrerequisitesReceived(event) diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/NoTestsFound.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/NoTestsFound.java new file mode 100644 index 0000000000..ba2d3b98ef --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/NoTestsFound.java @@ -0,0 +1,18 @@ +// Copyright 2014 The Bazel Authors. 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.runtime.commands; + +/** This event is posted by the {@link TestCommand} if no tests were found. */ +public class NoTestsFound {} diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java index 2de82d7639..db2797d3cd 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java @@ -137,6 +137,7 @@ public class TestCommand implements BlazeCommand { if (testTargets.isEmpty()) { env.getReporter().handle(Event.error( null, "No test targets were found, yet testing was requested")); + env.getEventBus().post(new NoTestsFound()); return buildResult.getSuccess() ? ExitCode.NO_TESTS_FOUND : buildResult.getExitCondition(); } |