Adds --[no]use_action_cache startup option to disable the action cache.
Disabling the action cache is helpful in contexts where incremental builds are
not required, or where actions need to be repeatedly executed for debugging.
--
PiperOrigin-RevId: 147485055
MOS_MIGRATED_REVID=147485055
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 4240be5..bfb8e15 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -482,6 +482,11 @@
} else {
result.push_back("--use_custom_exit_code_on_abrupt_exit=false");
}
+ if (globals->options->use_action_cache) {
+ result.push_back("--use_action_cache=true");
+ } else {
+ result.push_back("--use_action_cache=false");
+ }
// This is only for Blaze reporting purposes; the real interpretation of the
// jvm flags occurs when we set up the java command line.
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index f54c900..a78b559 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -38,7 +38,7 @@
: StartupOptions("Bazel", workspace_layout) {}
StartupOptions::StartupOptions(const string &product_name,
- const WorkspaceLayout* workspace_layout)
+ const WorkspaceLayout *workspace_layout)
: product_name(product_name),
deep_execroot(true),
block_for_lock(true),
@@ -57,7 +57,8 @@
invocation_policy(NULL),
client_debug(false),
use_custom_exit_code_on_abrupt_exit(true),
- java_logging_formatter("java.util.logging.SimpleFormatter") {
+ java_logging_formatter("java.util.logging.SimpleFormatter"),
+ use_action_cache(true) {
bool testing = !blaze::GetEnv("TEST_TMPDIR").empty();
if (testing) {
output_root = MakeAbsolute(blaze::GetEnv("TEST_TMPDIR"));
@@ -83,7 +84,8 @@
"write_command_log",
"watchfs",
"client_debug",
- "use_custom_exit_code_on_abrupt_exit"};
+ "use_custom_exit_code_on_abrupt_exit",
+ "use_action_cache"};
unary_options = {"output_base", "install_base",
"output_user_root", "host_jvm_profile", "host_javabase",
"host_jvm_args", "bazelrc", "blazerc", "io_nice_level",
@@ -283,6 +285,12 @@
} else if (GetNullaryOption(arg, "--nouse_custom_exit_code_on_abrupt_exit")) {
use_custom_exit_code_on_abrupt_exit = false;
option_sources["use_custom_exit_code_on_abrupt_exit"] = rcfile;
+ } else if (GetNullaryOption(arg, "--nouse_action_cache")) {
+ use_action_cache = false;
+ option_sources["use_action_cache"] = rcfile;
+ } else if (GetNullaryOption(arg, "--use_action_cache")) {
+ use_action_cache = true;
+ option_sources["use_action_cache"] = rcfile;
} else if ((value = GetUnaryOption(
arg, next_arg, "--connect_timeout_secs")) != NULL) {
if (!blaze_util::safe_strto32(value, &connect_timeout_secs) ||
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index 7bde6e7..cddebe3 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -215,6 +215,9 @@
// Value of the java.util.logging.FileHandler.formatter Java property.
std::string java_logging_formatter;
+ // Whether to use the action cache.
+ bool use_action_cache;
+
protected:
// Constructor for subclasses only so that site-specific extensions of this
// class can override the product name. The product_name must be the
diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java b/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java
new file mode 100644
index 0000000..9e1cdd3
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java
@@ -0,0 +1,40 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.actions.cache;
+
+import java.io.PrintStream;
+
+/** An {@link ActionCache} which does not store entries. */
+public class StubActionCache implements ActionCache {
+
+ @Override
+ public void put(String key, Entry entry) {}
+
+ @Override
+ public Entry get(String key) {
+ return null;
+ }
+
+ @Override
+ public void remove(String key) {}
+
+ @Override
+ public long save() {
+ return 0;
+ }
+
+ @Override
+ public void dump(PrintStream out) {}
+}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
index fe4fe8c..3f6bcf1 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
@@ -298,4 +298,12 @@
+ "Please do not use this flag."
)
public boolean useCustomExitCodeOnAbruptExit;
+
+ @Option(
+ name = "use_action_cache",
+ defaultValue = "true",
+ category = "server startup",
+ help = "Whether to use the action cache"
+ )
+ public boolean useActionCache;
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
index 98c56c4..e2d08b1 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
@@ -21,6 +21,7 @@
import com.google.common.eventbus.SubscriberExceptionHandler;
import com.google.devtools.build.lib.actions.cache.ActionCache;
import com.google.devtools.build.lib.actions.cache.CompactPersistentActionCache;
+import com.google.devtools.build.lib.actions.cache.StubActionCache;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction;
import com.google.devtools.build.lib.analysis.config.BinTools;
@@ -219,6 +220,16 @@
*/
public ActionCache getPersistentActionCache(Reporter reporter) throws IOException {
if (actionCache == null) {
+ boolean useActionCache =
+ runtime
+ .getStartupOptionsProvider()
+ .getOptions(BlazeServerStartupOptions.class)
+ .useActionCache;
+ if (!useActionCache) {
+ reporter.handle(Event.info("Action cache disabled"));
+ actionCache = new StubActionCache();
+ return actionCache;
+ }
try (AutoProfiler p = profiledAndLogged("Loading action cache", ProfilerTask.INFO, LOG)) {
try {
actionCache = new CompactPersistentActionCache(getCacheDirectory(), runtime.getClock());