aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-09-12 14:42:27 +0200
committerGravatar Philipp Wollermann <philwo@google.com>2017-09-12 15:48:17 +0200
commit87cc92e5df35d02a7c9bc50b229c513563dc1689 (patch)
treeff52660d47e154fcabb959aade5386353cb07ee3 /src/main/java/com
parent139543d3320f0336b012c2af020ed68fe5c49367 (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')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/NoTestsFound.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java1
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();
}