From f972c87c515f4b819bb6e7baca8a64b56d79d5f1 Mon Sep 17 00:00:00 2001 From: juliexxia Date: Fri, 2 Feb 2018 17:32:08 -0800 Subject: Check for nulls when making sure there is only one non-null configuration that top level targets are configured in. PiperOrigin-RevId: 184358568 --- .../devtools/build/lib/buildtool/BuildTool.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/google/devtools') 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 a60042922b..3530399a9c 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 @@ -86,6 +86,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * Provides the bulk of the implementation of the 'blaze build' command. @@ -449,17 +450,25 @@ public final class BuildTool { // Currently, CTQE assumes that all top level targets take on the same default config and we // don't have the ability to map multiple configs to multiple top level targets. // So for now, we only allow multiple targets when they all carry the same config. - // TODO: fully support multiple top level targets - TargetAndConfiguration sampleTAndC = topLevelTargetsWithConfigs.get(0); - BuildConfiguration sampleConfig = sampleTAndC.getConfiguration(); - for (TargetAndConfiguration targAndConfig : topLevelTargetsWithConfigs) { - if (!targAndConfig.getConfiguration().equals(sampleConfig)) { - throw new QueryException( - new TargetLiteral(queryExpression.toString()), - String.format( - "Top level targets %s and %s have different configurations (top level " - + "targets with different configurations is not supported)", - sampleTAndC.getLabel(), targAndConfig.getLabel())); + // TODO: b/71508373 - fully support multiple top level targets + List nonNullTargets = + topLevelTargetsWithConfigs + .stream() + .filter(targetAndConfig -> targetAndConfig.getConfiguration() != null) + .collect(Collectors.toList()); + BuildConfiguration targetConfig = null; + if (!nonNullTargets.isEmpty()) { + targetConfig = nonNullTargets.get(0).getConfiguration(); + for (TargetAndConfiguration targAndConfig : topLevelTargetsWithConfigs) { + if (targAndConfig.getConfiguration() != null + && !targAndConfig.getConfiguration().equals(targetConfig)) { + throw new QueryException( + new TargetLiteral(queryExpression.toString()), + String.format( + "Top-level targets %s and %s have different configurations (top-level " + + "targets with different configurations is not supported)", + nonNullTargets.get(0).getLabel(), targAndConfig.getLabel())); + } } } @@ -470,7 +479,7 @@ public final class BuildTool { request.getKeepGoing(), env.getReporter(), env.getRuntime().getQueryFunctions(), - sampleConfig, + targetConfig, hostConfiguration, env.newTargetPatternEvaluator().getOffset(), env.getPackageManager().getPackagePath(), -- cgit v1.2.3