diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisAndExecutionResult.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisAndExecutionResult.java new file mode 100644 index 00000000000000..3bc6dce35ccced --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisAndExecutionResult.java @@ -0,0 +1,64 @@ +// Copyright 2018 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.analysis; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection; +import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey; +import java.util.Collection; +import javax.annotation.Nullable; + +/** + * Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisAndExecutionPhaseRunner}. + * This is meant to be the drop-in replacement for AnalysisResult later on. This is part of + * https://github.com/bazelbuild/bazel/issues/14057. Internal: b/147350683. + */ +public final class AnalysisAndExecutionResult extends AnalysisResult { + + AnalysisAndExecutionResult( + BuildConfigurationCollection configurations, + ImmutableSet targetsToBuild, + ImmutableMap aspects, + @Nullable ImmutableList targetsToTest, + ImmutableSet targetsToSkip, + ImmutableSet artifactsToBuild, + ImmutableSet parallelTests, + ImmutableSet exclusiveTests, + TopLevelArtifactContext topLevelContext, + String workspaceName, + Collection topLevelTargetsWithConfigs, + ImmutableSortedSet nonSymlinkedDirectoriesUnderExecRoot) { + super( + configurations, + targetsToBuild, + aspects, + targetsToTest, + targetsToSkip, + /*failureDetail=*/ null, + /*actionGraph=*/ null, + artifactsToBuild, + parallelTests, + exclusiveTests, + topLevelContext, + /*packageRoots=*/ null, + workspaceName, + topLevelTargetsWithConfigs, + nonSymlinkedDirectoriesUnderExecRoot); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java index 5b78b8d1eadf64..dae3d10439f757 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java @@ -28,10 +28,8 @@ import java.util.Collection; import javax.annotation.Nullable; -/** - * Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner}. - */ -public final class AnalysisResult { +/** Return value for {@link com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner}. */ +public class AnalysisResult { private final BuildConfigurationCollection configurations; private final ImmutableSet targetsToBuild; @Nullable private final ImmutableList targetsToTest; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD index 64c684a0741f88..b4e6a89a7441af 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD @@ -161,6 +161,7 @@ java_library( srcs = [ "AliasProvider.java", "Allowlist.java", + "AnalysisAndExecutionResult.java", "AnalysisEnvironment.java", "AnalysisFailureEvent.java", "AnalysisIssues.java", diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java index 20f6e75ab993d2..b0c9dec777f6fa 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java @@ -202,7 +202,8 @@ public AnalysisResult update( int loadingPhaseThreads, TopLevelArtifactContext topLevelOptions, ExtendedEventHandler eventHandler, - EventBus eventBus) + EventBus eventBus, + boolean includeExecutionPhase) throws ViewCreationFailedException, InvalidConfigurationException, InterruptedException { logger.atInfo().log("Starting analysis"); pollInterruptedStatus(); @@ -369,43 +370,36 @@ public AnalysisResult update( } return result; }; - skyframeAnalysisResult = - skyframeBuildView.configureTargets( - eventHandler, - topLevelCtKeys, - aspectsKeys.build(), - Suppliers.memoize(configurationLookupSupplier), - topLevelOptions, - eventBus, - keepGoing, - loadingPhaseThreads, - viewOptions.strictConflictChecks, - checkForActionConflicts, - viewOptions.cpuHeavySkyKeysThreadPoolSize); - setArtifactRoots(skyframeAnalysisResult.getPackageRoots()); + if (!includeExecutionPhase) { + skyframeAnalysisResult = + skyframeBuildView.configureTargets( + eventHandler, + topLevelCtKeys, + aspectsKeys.build(), + Suppliers.memoize(configurationLookupSupplier), + topLevelOptions, + eventBus, + keepGoing, + loadingPhaseThreads, + viewOptions.strictConflictChecks, + checkForActionConflicts, + viewOptions.cpuHeavySkyKeysThreadPoolSize); + setArtifactRoots(skyframeAnalysisResult.getPackageRoots()); + } else { + skyframeAnalysisResult = + skyframeBuildView.analyzeAndExecuteTargets( + eventHandler, + topLevelCtKeys, + aspectsKeys.build(), + topLevelOptions, + keepGoing, + loadingPhaseThreads, + viewOptions.cpuHeavySkyKeysThreadPoolSize); + } } finally { skyframeBuildView.clearInvalidatedActionLookupKeys(); } - TopLevelConstraintSemantics topLevelConstraintSemantics = - new TopLevelConstraintSemantics( - (RuleContextConstraintSemantics) ruleClassProvider.getConstraintSemantics(), - skyframeExecutor.getPackageManager(), - input -> skyframeExecutor.getConfiguration(eventHandler, input), - eventHandler); - - PlatformRestrictionsResult platformRestrictions = - topLevelConstraintSemantics.checkPlatformRestrictions( - skyframeAnalysisResult.getConfiguredTargets(), explicitTargetPatterns, keepGoing); - - if (!platformRestrictions.targetsWithErrors().isEmpty()) { - // If there are any errored targets (e.g. incompatible targets that are explicitly specified - // on the command line), remove them from the list of targets to be built. - skyframeAnalysisResult = - skyframeAnalysisResult.withAdditionalErroredTargets( - ImmutableSet.copyOf(platformRestrictions.targetsWithErrors())); - } - int numTargetsToAnalyze = topLevelTargetsWithConfigs.size(); int numSuccessful = skyframeAnalysisResult.getConfiguredTargets().size(); if (0 < numSuccessful && numSuccessful < numTargetsToAnalyze) { @@ -417,24 +411,61 @@ public AnalysisResult update( logger.atInfo().log(msg); } - Set targetsToSkip = - Sets.union( - topLevelConstraintSemantics.checkTargetEnvironmentRestrictions( - skyframeAnalysisResult.getConfiguredTargets()), - platformRestrictions.targetsToSkip()) - .immutableCopy(); - - AnalysisResult result = - createResult( - eventHandler, - eventBus, - loadingResult, - configurations, - topLevelOptions, - viewOptions, - skyframeAnalysisResult, - targetsToSkip, - topLevelTargetsWithConfigsResult); + AnalysisResult result; + if (includeExecutionPhase) { + // TODO(b/199053098): Also consider targets with errors like below. + result = + createResult( + eventHandler, + eventBus, + loadingResult, + configurations, + topLevelOptions, + viewOptions, + skyframeAnalysisResult, + /*targetsToSkip=*/ ImmutableSet.of(), + topLevelTargetsWithConfigsResult, + /*includeExecutionPhase=*/ true); + } else { + TopLevelConstraintSemantics topLevelConstraintSemantics = + new TopLevelConstraintSemantics( + (RuleContextConstraintSemantics) ruleClassProvider.getConstraintSemantics(), + skyframeExecutor.getPackageManager(), + input -> skyframeExecutor.getConfiguration(eventHandler, input), + eventHandler); + + PlatformRestrictionsResult platformRestrictions = + topLevelConstraintSemantics.checkPlatformRestrictions( + skyframeAnalysisResult.getConfiguredTargets(), explicitTargetPatterns, keepGoing); + + if (!platformRestrictions.targetsWithErrors().isEmpty()) { + // If there are any errored targets (e.g. incompatible targets that are explicitly specified + // on the command line), remove them from the list of targets to be built. + skyframeAnalysisResult = + skyframeAnalysisResult.withAdditionalErroredTargets( + platformRestrictions.targetsWithErrors()); + } + + Set targetsToSkip = + Sets.union( + topLevelConstraintSemantics.checkTargetEnvironmentRestrictions( + skyframeAnalysisResult.getConfiguredTargets()), + platformRestrictions.targetsToSkip()) + .immutableCopy(); + + result = + createResult( + eventHandler, + eventBus, + loadingResult, + configurations, + topLevelOptions, + viewOptions, + skyframeAnalysisResult, + targetsToSkip, + topLevelTargetsWithConfigsResult, + /*includeExecutionPhase=*/ false); + } logger.atInfo().log("Finished analysis"); return result; } @@ -456,7 +487,8 @@ private AnalysisResult createResult( AnalysisOptions viewOptions, SkyframeAnalysisResult skyframeAnalysisResult, Set targetsToSkip, - TopLevelTargetsAndConfigsResult topLevelTargetsWithConfigs) + TopLevelTargetsAndConfigsResult topLevelTargetsWithConfigs, + boolean includeExecutionPhase) throws InterruptedException { Set