aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar juliexxia <juliexxia@google.com>2018-02-02 17:32:08 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-02 17:34:15 -0800
commitf972c87c515f4b819bb6e7baca8a64b56d79d5f1 (patch)
tree57fd618ed31e98a8675b43ae92479dec67e4af87 /src/main/java/com/google/devtools
parente861ffcdf4d6680566c244e4b088035ef9d0641f (diff)
Check for nulls when making sure there is only one non-null configuration that top level targets are configured in.
PiperOrigin-RevId: 184358568
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java33
1 files changed, 21 insertions, 12 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 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<TargetAndConfiguration> 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(),