From 2cd5c3af92441ce473bf47cd30dadeadcc26dfe1 Mon Sep 17 00:00:00 2001 From: Matt Mackay Date: Mon, 31 Jul 2023 13:26:50 -0700 Subject: [PATCH] feat: add option to exit early if analysis cache is discarded Adds `--allow_analysis_cache_discard` option that allows the build to exit early if the analysis cache would have been discarded. The flag name is of course open to bikeshedding etc. fixes #16804 Closes #16805. PiperOrigin-RevId: 552575951 Change-Id: Ia336eb3a5b7d7e41665fd0e0adf3edc03ed50f18 --- .../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 | 18 ++++++++++++-- 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, 81 insertions(+), 11 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