diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisAndExecutionPhaseRunner.java b/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisAndExecutionPhaseRunner.java index 648660c3e67696..2b31142b4586a5 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisAndExecutionPhaseRunner.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisAndExecutionPhaseRunner.java @@ -135,9 +135,14 @@ static AnalysisAndExecutionResult execute( executionSetupCallback, buildConfigurationCreatedCallback); } + BuildResultListener buildResultListener = env.getBuildResultListener(); - AnalysisPhaseRunner.reportTargets( - env, buildResultListener.getAnalyzedTargets(), buildResultListener.getAnalyzedTests()); + if (request.shouldRunTests()) { + AnalysisPhaseRunner.reportTargetsWithTests( + env, buildResultListener.getAnalyzedTargets(), buildResultListener.getAnalyzedTests()); + } else { + AnalysisPhaseRunner.reportTargets(env, buildResultListener.getAnalyzedTargets()); + } } else { env.getReporter().handle(Event.progress("Loading complete.")); diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java b/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java index 0f6600de39fe4a..ee5f93c166baa0 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.buildtool; +import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -143,7 +144,14 @@ public static AnalysisResult execute( module.afterAnalysis(env, request, buildOptions, analysisResult); } - reportTargets(env, analysisResult.getTargetsToBuild(), analysisResult.getTargetsToTest()); + if (request.shouldRunTests()) { + reportTargetsWithTests( + env, + analysisResult.getTargetsToBuild(), + Preconditions.checkNotNull(analysisResult.getTargetsToTest())); + } else { + reportTargets(env, analysisResult.getTargetsToBuild()); + } for (ConfiguredTarget target : analysisResult.getTargetsToSkip()) { BuildConfigurationValue config = @@ -323,39 +331,38 @@ private static void postTopLevelStatusEvents( } } - static void reportTargets( + static void reportTargetsWithTests( CommandEnvironment env, Collection targetsToBuild, Collection targetsToTest) { - if (targetsToTest != null) { - int testCount = targetsToTest.size(); - int targetCount = targetsToBuild.size() - testCount; - if (targetCount == 0) { - env.getReporter() - .handle( - Event.info( - "Found " - + testCount - + (testCount == 1 ? " test target..." : " test targets..."))); - } else { - env.getReporter() - .handle( - Event.info( - "Found " - + targetCount - + (targetCount == 1 ? " target and " : " targets and ") - + testCount - + (testCount == 1 ? " test target..." : " test targets..."))); - } + int testCount = targetsToTest.size(); + int targetCount = targetsToBuild.size() - testCount; + if (targetCount == 0) { + env.getReporter() + .handle( + Event.info( + "Found " + + testCount + + (testCount == 1 ? " test target..." : " test targets..."))); } else { - int targetCount = targetsToBuild.size(); env.getReporter() .handle( Event.info( - "Found " + targetCount + (targetCount == 1 ? " target..." : " targets..."))); + "Found " + + targetCount + + (targetCount == 1 ? " target and " : " targets and ") + + testCount + + (testCount == 1 ? " test target..." : " test targets..."))); } } + static void reportTargets(CommandEnvironment env, Collection targetsToBuild) { + int targetCount = targetsToBuild.size(); + env.getReporter() + .handle( + Event.info("Found " + targetCount + (targetCount == 1 ? " target..." : " targets..."))); + } + /** * Turns target patterns from the command line into parsed equivalents for single targets. *