When true, ccache will just call the real compiler, bypassing the cache
completely. The default is false.
++
+It is also possible to disable ccache for a specific source code file by adding
+the string `ccache:disable` in a comment in the first 4096 bytes of the file.
[#config_extra_files_to_hash]
*extra_files_to_hash* (*CCACHE_EXTRAFILES*)::
cache with other users.
+=== Disabling ccache
+
+To disable ccache completely for all invocations, set <<config_disable,*disable
+= true*>> (`CCACHE_DISABLE=1`). You can also disable ccache for a certain source
+code file by adding the string `ccache:disable` in a comment in the first 4096
+bytes of the file. In the latter case the `Ccache disabled` statistics counter
+will be increased.
+
+
== Remote storage backends
The <<config_remote_storage,*remote_storage*>> option lets you configure ccache
| Called for preprocessing |
The compiler was called for preprocessing, not compiling.
+| Ccache disabled |
+Ccache was disabled by a `ccache:disable` string in the source code file.
+
| Could not use modules |
Preconditions for using <<C++ modules>> were not fulfilled.
// 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
} // 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)
{
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(
-// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
// 65-80: size (KiB) in level 2 subdirs 0-f
subdir_size_kibibyte_base = 65,
- END = 81
+ disabled = 81,
+ END = 82
};
} // namespace core
FLAG_UNCACHEABLE),
FIELD(direct_cache_hit, nullptr),
FIELD(direct_cache_miss, nullptr),
+ FIELD(disabled, "Ccache disabled", FLAG_UNCACHEABLE),
FIELD(error_hashing_extra_file, "Error hashing extra file", FLAG_ERROR),
FIELD(files_in_cache, nullptr, FLAG_NOZERO),
FIELD(internal_error, "Internal error", FLAG_ERROR),
CCACHE_DEBUG=1 CCACHE_DEBUGDIR=debugdir $CCACHE_COMPILE -c test1.c
expect_contains debugdir"$(pwd -P)"/test1.o.*.ccache-log "Result: cache_miss"
fi
+
# -------------------------------------------------------------------------
TEST "CCACHE_DISABLE"
test_failed "$CCACHE_DIR created despite CCACHE_DISABLE being set"
fi
+ # -------------------------------------------------------------------------
+ TEST "ccache:disable"
+
+ echo '// ccache:disable' >>test1.c
+ $CCACHE_COMPILE -c test1.c 2>/dev/null
+ expect_stat disabled 1
+
# -------------------------------------------------------------------------
TEST "CCACHE_COMMENTS"