From cd08c0af5fcf5fdbb45598e9a9a15ad6c490ded9 Mon Sep 17 00:00:00 2001 From: Matt Mackay Date: Sat, 19 Nov 2022 08:57:45 -0500 Subject: [PATCH] feat: add option to exit early if analysis cache is discarded --- .../build/lib/analysis/AnalysisOptions.java | 11 +++++++ .../build/lib/analysis/BuildView.java | 27 ++++----------- .../AnalysisAndExecutionPhaseRunner.java | 33 ++++++------------- .../lib/buildtool/AnalysisPhaseRunner.java | 9 ++--- .../build/lib/buildtool/BuildTool.java | 9 ++--- .../AnalysisCacheDiscardedException.java | 33 +++++++++++++++++++ .../google/devtools/build/lib/skyframe/BUILD | 1 + .../build/lib/skyframe/SkyframeBuildView.java | 11 +++++-- .../devtools/build/lib/util/ExitCode.java | 3 ++ src/main/protobuf/failure_details.proto | 1 + .../lib/analysis/AnalysisCachingTest.java | 14 ++++++++ .../analysis/util/BuildViewForTesting.java | 17 ++++++---- 12 files changed, 107 insertions(+), 62 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/skyframe/AnalysisCacheDiscardedException.java diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java index f6c9ed8fa3655e..a36aa48a93af9c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisOptions.java @@ -39,6 +39,17 @@ public class AnalysisOptions extends OptionsBase { ) public boolean discardAnalysisCache; + @Option( + name = "fail_on_analysis_cache_discard", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.EAGERNESS_TO_EXIT}, + help = "If discarding the analysis cache due to a change in the build system, setting this option will cause bazel" + + " to exit, rather than continuing with the build. This option has no affect when 'discard_analysis_cache'" + + " is also set." + ) + public boolean failOnAnalysisCacheDiscard; + @Option( name = "max_config_changes_to_show", defaultValue = "3", 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 cc3fa45f7fc1d0..f0e0443bc04fa1 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 @@ -81,20 +81,10 @@ import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; import com.google.devtools.build.lib.server.FailureDetails.TargetPatterns; import com.google.devtools.build.lib.server.FailureDetails.TargetPatterns.Code; -import com.google.devtools.build.lib.skyframe.AspectKeyCreator; +import com.google.devtools.build.lib.skyframe.*; import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey; import com.google.devtools.build.lib.skyframe.AspectKeyCreator.TopLevelAspectsKey; -import com.google.devtools.build.lib.skyframe.BuildConfigurationKey; -import com.google.devtools.build.lib.skyframe.BuildResultListener; -import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; -import com.google.devtools.build.lib.skyframe.CoverageReportValue; import com.google.devtools.build.lib.skyframe.RepositoryMappingValue.RepositoryMappingResolutionException; -import com.google.devtools.build.lib.skyframe.SkyframeAnalysisAndExecutionResult; -import com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult; -import com.google.devtools.build.lib.skyframe.SkyframeBuildView; -import com.google.devtools.build.lib.skyframe.SkyframeBuildView.BuildDriverKeyTestContext; -import com.google.devtools.build.lib.skyframe.SkyframeExecutor; -import com.google.devtools.build.lib.skyframe.TargetPatternPhaseValue; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.RegexFilter; @@ -223,14 +213,9 @@ public AnalysisResult update( @Nullable ResourceManager resourceManager, @Nullable BuildResultListener buildResultListener, @Nullable ExecutionSetup executionSetupCallback, - @Nullable BuildConfigurationsCreated buildConfigurationsCreatedCallback, - @Nullable BuildDriverKeyTestContext buildDriverKeyTestContext) - throws ViewCreationFailedException, - InvalidConfigurationException, - InterruptedException, - BuildFailedException, - TestExecException, - AbruptExitException { + @Nullable BuildConfigurationsCreated buildConfigurationsCreatedCallback) + throws ViewCreationFailedException, InvalidConfigurationException, InterruptedException, + BuildFailedException, TestExecException, AbruptExitException, AnalysisCacheDiscardedException { logger.atInfo().log("Starting analysis"); pollInterruptedStatus(); @@ -268,8 +253,8 @@ public AnalysisResult update( skyframeExecutor); } - skyframeBuildView.setConfiguration( - eventHandler, configuration, viewOptions.maxConfigChangesToShow); + skyframeBuildView.setConfigurations( + eventHandler, configurations, viewOptions.maxConfigChangesToShow, viewOptions.failOnAnalysisCacheDiscard); eventBus.post(new MakeEnvironmentEvent(configuration.getMakeEnvironment())); eventBus.post(configuration.toBuildEvent()); 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 ca3269e37f08bd..52c1016e5f3798 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 @@ -45,12 +45,8 @@ import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.server.FailureDetails.BuildConfiguration.Code; import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; -import com.google.devtools.build.lib.skyframe.BuildInfoCollectionFunction; -import com.google.devtools.build.lib.skyframe.BuildResultListener; -import com.google.devtools.build.lib.skyframe.PrecomputedValue; +import com.google.devtools.build.lib.skyframe.*; import com.google.devtools.build.lib.skyframe.RepositoryMappingValue.RepositoryMappingResolutionException; -import com.google.devtools.build.lib.skyframe.SkyframeBuildView.BuildDriverKeyTestContext; -import com.google.devtools.build.lib.skyframe.TargetPatternPhaseValue; import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetAnalyzedEvent; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.DetailedExitCode; @@ -79,15 +75,11 @@ static AnalysisAndExecutionResult execute( BuildOptions buildOptions, TargetPatternPhaseValue loadingResult, ExecutionSetup executionSetupCallback, - BuildConfigurationsCreated buildConfigurationCreatedCallback, - BuildDriverKeyTestContext buildDriverKeyTestContext) - throws BuildFailedException, - InterruptedException, - ViewCreationFailedException, - AbruptExitException, - InvalidConfigurationException, - TestExecException, - RepositoryMappingResolutionException { + BuildConfigurationsCreated buildConfigurationCreatedCallback) + throws BuildFailedException, InterruptedException, ViewCreationFailedException, + TargetParsingException, LoadingFailedException, AbruptExitException, + InvalidConfigurationException, TestExecException, RepositoryMappingResolutionException, + AnalysisCacheDiscardedException { // Compute the heuristic instrumentation filter if needed. if (request.needsInstrumentationFilter()) { @@ -207,15 +199,10 @@ private static AnalysisAndExecutionResult runAnalysisAndExecutionPhase( TargetPatternPhaseValue loadingResult, BuildOptions targetOptions, ExecutionSetup executionSetupCallback, - BuildConfigurationsCreated buildConfigurationCreatedCallback, - BuildDriverKeyTestContext buildDriverKeyTestContext) - throws InterruptedException, - InvalidConfigurationException, - ViewCreationFailedException, - BuildFailedException, - TestExecException, - RepositoryMappingResolutionException, - AbruptExitException { + BuildConfigurationsCreated buildConfigurationCreatedCallback) + throws InterruptedException, InvalidConfigurationException, ViewCreationFailedException, + BuildFailedException, TestExecException, RepositoryMappingResolutionException, + AbruptExitException, AnalysisCacheDiscardedException { env.getReporter().handle(Event.progress("Loading complete. Analyzing...")); ImmutableSet