aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java13
3 files changed, 30 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java
index a92fbb3dc7..87392b092e 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequestOptions.java
@@ -402,6 +402,17 @@ public class BuildRequestOptions extends OptionsBase {
)
public boolean trackIncrementalState;
+ @Option(
+ name = "keep_state_after_build",
+ defaultValue = "true",
+ documentationCategory = OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
+ effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE},
+ help =
+ "If false, Blaze will discard the inmemory state from this build when the build finishes. "
+ + "Subsequent builds will not have any incrementality with respect to this one."
+ )
+ public boolean keepStateAfterBuild;
+
/** Converter for jobs: [0, MAX_JOBS] or "auto". */
public static class JobsConverter extends RangeConverter {
/**
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index 65e5954fc9..7789605f1d 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -33,6 +33,7 @@ import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.test.CoverageReportActionFactory;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
+import com.google.devtools.build.lib.buildtool.BuildRequestOptions;
import com.google.devtools.build.lib.clock.BlazeClock;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.events.Event;
@@ -424,10 +425,7 @@ public final class BlazeRuntime {
workspace.getSkyframeExecutor().getEventBus().post(new CommandCompleteEvent(exitCode));
}
- /**
- * Hook method called by the BlazeCommandDispatcher after the dispatch of each
- * command.
- */
+ /** Hook method called by the BlazeCommandDispatcher after the dispatch of each command. */
@VisibleForTesting
public void afterCommand(CommandEnvironment env, int exitCode) {
// Remove any filters that the command might have added to the reporter.
@@ -439,6 +437,15 @@ public final class BlazeRuntime {
module.afterCommand();
}
+ // If the command just completed was or inherits from Build, wipe the dependency graph if
+ // requested. This is sufficient, as this method is always run at the end of commands unless
+ // the server crashes, in which case no inmemory state will linger for the next build anyway.
+ BuildRequestOptions buildRequestOptions =
+ env.getOptions().getOptions(BuildRequestOptions.class);
+ if (buildRequestOptions != null && !buildRequestOptions.keepStateAfterBuild) {
+ workspace.getSkyframeExecutor().resetEvaluator();
+ }
+
env.getBlazeWorkspace().clearEventBus();
try {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
index c9f87fad3b..d32e94602f 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
@@ -523,7 +523,7 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
Preconditions.checkState(!active);
BuildView.Options viewOptions = options.getOptions(BuildView.Options.class);
BuildRequestOptions requestOptions = options.getOptions(BuildRequestOptions.class);
- boolean oldState = trackIncrementalState;
+ boolean oldValueOfTrackIncrementalState = trackIncrementalState;
// First check if the incrementality state should be kept around during the build.
boolean explicitlyRequestedNoIncrementalData =
@@ -532,6 +532,7 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
batch && viewOptions != null && viewOptions.discardAnalysisCache;
trackIncrementalState =
!explicitlyRequestedNoIncrementalData && !implicitlyRequestedNoIncrementalData;
+ boolean keepStateAfterBuild = requestOptions != null && requestOptions.keepStateAfterBuild;
if (explicitlyRequestedNoIncrementalData != implicitlyRequestedNoIncrementalData) {
if (requestOptions != null && !explicitlyRequestedNoIncrementalData) {
eventHandler.handle(
@@ -541,17 +542,19 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
+ " to specify --notrack_incremental_state in the future if you want to "
+ "maximize memory savings."));
}
- if (!batch) {
+ if (!batch && keepStateAfterBuild) {
eventHandler.handle(
Event.warn(
- "--batch not specified with --notrack_incremental_state: the server will "
- + "remain running, but the next build will not be incremental on this one."));
+ "--notrack_incremental_state was specified, but without "
+ + "--nokeep_state_after_build. Inmemory state from this build will not be "
+ + "reusable, but it will not get fully wiped until the beginning of the next "
+ + "build. Use --nokeep_state_after_build to clean up eagerly."));
}
}
// Now check if it is necessary to wipe the previous state. We do this if either the previous
// or current incrementalStateRetentionStrategy requires the build to have been isolated.
- if (oldState != trackIncrementalState) {
+ if (oldValueOfTrackIncrementalState != trackIncrementalState) {
logger.info("Set incremental state to " + trackIncrementalState);
evaluatorNeedsReset = true;
removeActionsAfterEvaluation.set(!trackIncrementalState);