summaryrefslogtreecommitdiff
path: root/src/ccache.cpp
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-03-06 21:22:25 +0100
committerJoel Rosdahl <joel@rosdahl.net>2023-03-07 20:17:35 +0100
commitb3c3e7998c6497f8d354da77c7ed6184381c6247 (patch)
tree8c5a2f79fd3217a519c6b4d4bf58c664765f4d6f /src/ccache.cpp
parent62858602c6aaa8c6c28bf82aa4e1244c1214b869 (diff)
downloadccache-b3c3e7998c6497f8d354da77c7ed6184381c6247.tar.gz
feat: Make it possible to disable ccache for a certain source code file
Diffstat (limited to 'src/ccache.cpp')
-rw-r--r--src/ccache.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp
index 9efbd563..9547f538 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -86,6 +86,14 @@ using core::Statistic;
// stored in the cache changes in a backwards-incompatible way.
const char HASH_PREFIX[] = "4";
+// Search for k_ccache_disable_token within the first
+// k_ccache_disable_search_limit bytes of the input file.
+const size_t k_ccache_disable_search_limit = 4096;
+
+// String to look for when checking whether to disable ccache for the input
+// file.
+const char k_ccache_disable_token[] = "ccache:disable";
+
namespace {
// Return nonstd::make_unexpected<Failure> if ccache did not succeed in getting
@@ -136,6 +144,14 @@ Failure::set_exit_code(const int exit_code)
} // namespace
+static bool
+should_disable_ccache_for_input_file(const std::string& path)
+{
+ auto content =
+ util::read_file_part<std::string>(path, 0, k_ccache_disable_search_limit);
+ return content && content->find(k_ccache_disable_token) != std::string::npos;
+}
+
static void
add_prefix(const Context& ctx, Args& args, const std::string& prefix_command)
{
@@ -2488,6 +2504,13 @@ do_cache_compilation(Context& ctx)
Hash common_hash;
init_hash_debug(ctx, common_hash, 'c', "COMMON", debug_text_file);
+ if (should_disable_ccache_for_input_file(ctx.args_info.input_file)) {
+ LOG("{} found in {}, disabling ccache",
+ k_ccache_disable_token,
+ ctx.args_info.input_file);
+ return nonstd::make_unexpected(Statistic::disabled);
+ }
+
{
MTR_SCOPE("hash", "common_hash");
TRY(hash_common_info(