Skip to content

Commit

Permalink
Check in the majority of the prototype's code.
Browse files Browse the repository at this point in the history
This is the MVP of Skyframe with merged analysis and execution. It's meant to only handle the most straightforward "happy path" of a build and is currently ignoring all failures and extra features.

RELNOTES: None
PiperOrigin-RevId: 399632160
  • Loading branch information
joeleba authored and copybara-github committed Sep 29, 2021
1 parent 26b94ff commit 94b810f
Show file tree
Hide file tree
Showing 16 changed files with 719 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -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<ConfiguredTarget> targetsToBuild,
ImmutableMap<AspectKey, ConfiguredAspect> aspects,
@Nullable ImmutableList<ConfiguredTarget> targetsToTest,
ImmutableSet<ConfiguredTarget> targetsToSkip,
ImmutableSet<Artifact> artifactsToBuild,
ImmutableSet<ConfiguredTarget> parallelTests,
ImmutableSet<ConfiguredTarget> exclusiveTests,
TopLevelArtifactContext topLevelContext,
String workspaceName,
Collection<TargetAndConfiguration> topLevelTargetsWithConfigs,
ImmutableSortedSet<String> nonSymlinkedDirectoriesUnderExecRoot) {
super(
configurations,
targetsToBuild,
aspects,
targetsToTest,
targetsToSkip,
/*failureDetail=*/ null,
/*actionGraph=*/ null,
artifactsToBuild,
parallelTests,
exclusiveTests,
topLevelContext,
/*packageRoots=*/ null,
workspaceName,
topLevelTargetsWithConfigs,
nonSymlinkedDirectoriesUnderExecRoot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfiguredTarget> targetsToBuild;
@Nullable private final ImmutableList<ConfiguredTarget> targetsToTest;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ java_library(
srcs = [
"AliasProvider.java",
"Allowlist.java",
"AnalysisAndExecutionResult.java",
"AnalysisEnvironment.java",
"AnalysisFailureEvent.java",
"AnalysisIssues.java",
Expand Down
154 changes: 101 additions & 53 deletions src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -417,24 +411,61 @@ public AnalysisResult update(
logger.atInfo().log(msg);
}

Set<ConfiguredTarget> 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<ConfiguredTarget> 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;
}
Expand All @@ -456,7 +487,8 @@ private AnalysisResult createResult(
AnalysisOptions viewOptions,
SkyframeAnalysisResult skyframeAnalysisResult,
Set<ConfiguredTarget> targetsToSkip,
TopLevelTargetsAndConfigsResult topLevelTargetsWithConfigs)
TopLevelTargetsAndConfigsResult topLevelTargetsWithConfigs,
boolean includeExecutionPhase)
throws InterruptedException {
Set<Label> testsToRun = loadingResult.getTestsToRunLabels();
Set<ConfiguredTarget> configuredTargets =
Expand Down Expand Up @@ -525,6 +557,22 @@ private AnalysisResult createResult(
ImmutableSet<ConfiguredTarget> parallelTests = testsPair.first;
ImmutableSet<ConfiguredTarget> exclusiveTests = testsPair.second;

if (includeExecutionPhase) {
return new AnalysisAndExecutionResult(
configurations,
ImmutableSet.copyOf(configuredTargets),
aspects,
allTargetsToTest == null ? null : ImmutableList.copyOf(allTargetsToTest),
ImmutableSet.copyOf(targetsToSkip),
artifactsToBuild.build(),
parallelTests,
exclusiveTests,
topLevelOptions,
loadingResult.getWorkspaceName(),
topLevelTargetsWithConfigs.getTargetsAndConfigs(),
loadingResult.getNotSymlinkedInExecrootDirectories());
}

FailureDetail failureDetail =
createFailureDetail(loadingResult, skyframeAnalysisResult, topLevelTargetsWithConfigs);

Expand Down
Loading

0 comments on commit 94b810f

Please sign in to comment.