From f59a234606110a94e4870d3d27cc0773d32beed3 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 | 15 ++------- .../AnalysisAndExecutionPhaseRunner.java | 10 +++--- .../lib/buildtool/AnalysisPhaseRunner.java | 9 ++--- .../build/lib/buildtool/BuildTool.java | 7 ++-- .../AnalysisCacheDiscardedException.java | 33 +++++++++++++++++++ .../google/devtools/build/lib/skyframe/BUILD | 1 + .../build/lib/skyframe/SkyframeBuildView.java | 7 +++- .../devtools/build/lib/util/ExitCode.java | 3 ++ src/main/protobuf/failure_details.proto | 1 + .../analysis/util/BuildViewForTesting.java | 11 +++++-- 11 files changed, 77 insertions(+), 31 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 f7cc3967b0b436..3cc5941ff8b329 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 bf672e8ce0bc4c..23298c2ad7fec4 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 @@ -79,19 +79,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.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; @@ -222,7 +213,7 @@ public AnalysisResult update( @Nullable ExecutionSetup executionSetupCallback, @Nullable BuildConfigurationsCreated buildConfigurationsCreatedCallback) throws ViewCreationFailedException, InvalidConfigurationException, InterruptedException, - BuildFailedException, TestExecException, AbruptExitException { + BuildFailedException, TestExecException, AbruptExitException, AnalysisCacheDiscardedException { logger.atInfo().log("Starting analysis"); pollInterruptedStatus(); @@ -261,7 +252,7 @@ public AnalysisResult update( } skyframeBuildView.setConfigurations( - eventHandler, configurations, viewOptions.maxConfigChangesToShow); + eventHandler, configurations, viewOptions.maxConfigChangesToShow, viewOptions.failOnAnalysisCacheDiscard); eventBus.post( new MakeEnvironmentEvent(configurations.getTargetConfiguration().getMakeEnvironment())); 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 2b31142b4586a5..5248a73267faaf 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,11 +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.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; @@ -81,7 +78,8 @@ static AnalysisAndExecutionResult execute( BuildConfigurationsCreated buildConfigurationCreatedCallback) throws BuildFailedException, InterruptedException, ViewCreationFailedException, TargetParsingException, LoadingFailedException, AbruptExitException, - InvalidConfigurationException, TestExecException, RepositoryMappingResolutionException { + InvalidConfigurationException, TestExecException, RepositoryMappingResolutionException, + AnalysisCacheDiscardedException { // Compute the heuristic instrumentation filter if needed. if (request.needsInstrumentationFilter()) { @@ -203,7 +201,7 @@ private static AnalysisAndExecutionResult runAnalysisAndExecutionPhase( BuildConfigurationsCreated buildConfigurationCreatedCallback) throws InterruptedException, InvalidConfigurationException, ViewCreationFailedException, BuildFailedException, TestExecException, RepositoryMappingResolutionException, - AbruptExitException { + AbruptExitException, AnalysisCacheDiscardedException { env.getReporter().handle(Event.progress("Loading complete. Analyzing...")); ImmutableSet