From aab790a5905a3cb526fbf6148b6e3c297a16f697 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 12 Sep 2023 19:44:44 -0400 Subject: [PATCH] [6.4.0] feat: add option to exit early if analysis cache is discarded (#19503) Forked from https://github.com/bazelbuild/bazel/pull/16805. Manually merged conflicts observed at https://github.com/bazelbuild/bazel/pull/16805#issuecomment-1664767974. Fixes https://github.com/bazelbuild/bazel/issues/19162. --------- Co-authored-by: Matt Mackay --- .../build/lib/analysis/AnalysisOptions.java | 11 +++++++++ .../build/lib/analysis/BuildView.java | 5 ++-- .../devtools/build/lib/buildeventstream/BUILD | 1 + .../BuildCompletingEvent.java | 24 +++++++++++++++---- .../proto/build_event_stream.proto | 3 +++ .../buildevent/BuildCompleteEvent.java | 2 +- .../build/lib/skyframe/SkyframeBuildView.java | 12 +++++++++- src/main/protobuf/failure_details.proto | 2 ++ .../lib/analysis/AnalysisCachingTest.java | 13 ++++++++++ .../google/devtools/build/lib/analysis/BUILD | 1 + .../analysis/util/BuildViewForTesting.java | 12 ++++++++-- 11 files changed, 76 insertions(+), 10 deletions(-) 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 95256a0549fd24..6810d1f0525816 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 = "allow_analysis_cache_discard", + defaultValue = "true", + 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 to false will cause bazel to exit, rather than continuing with the build." + + " This option has no effect when 'discard_analysis_cache' is also set.") + public boolean allowAnalysisCacheDiscards; + @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 c4208b0a9325c0..14a955d0b205a5 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 @@ -256,7 +256,8 @@ public AnalysisResult update( } skyframeBuildView.setConfigurations( - eventHandler, configurations, viewOptions.maxConfigChangesToShow); + eventHandler, configurations, viewOptions.maxConfigChangesToShow, + viewOptions.allowAnalysisCacheDiscards); eventBus.post( new MakeEnvironmentEvent(configurations.getTargetConfiguration().getMakeEnvironment())); @@ -535,7 +536,7 @@ private AnalysisResult createResult( TopLevelTargetsAndConfigsResult topLevelTargetsWithConfigs, boolean includeExecutionPhase) throws InterruptedException { - Set