]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve LOG macro to accept format string without arguments
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 2 Feb 2026 20:35:14 +0000 (21:35 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 13 Feb 2026 21:17:39 +0000 (22:17 +0100)
15 files changed:
cmake/DevModeWarnings.cmake
src/ccache/.clang-tidy
src/ccache/argprocessing.cpp
src/ccache/ccache.cpp
src/ccache/core/cacheentry.cpp
src/ccache/core/manifest.cpp
src/ccache/core/resultretriever.cpp
src/ccache/depfile.cpp
src/ccache/execute.cpp
src/ccache/storage/local/localstorage.cpp
src/ccache/storage/remote/helper.cpp
src/ccache/storage/remote/redisstorage.cpp
src/ccache/storage/storage.cpp
src/ccache/util/logging.hpp
src/ccache/util/longlivedlockfilemanager.cpp

index cd89b7c973e0c690f205a508d504d06237a00219..b24e9ce991f348e720b87c294797156ebb5d3c1b 100644 (file)
@@ -41,10 +41,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
   add_compile_flag_if_supported_ex(
     CCACHE_COMPILER_WARNINGS "-Wno-shadow-field-in-constructor" "-Wno-shadow")
 
-  # Disable C++20 compatibility for now.
-  add_compile_flag_if_supported(CCACHE_COMPILER_WARNINGS "-Wno-c++2a-compat")
-  add_compile_flag_if_supported(CCACHE_COMPILER_WARNINGS "-Wno-c99-extensions")
-  add_compile_flag_if_supported(CCACHE_COMPILER_WARNINGS "-Wno-language-extension-token")
+  # https://github.com/llvm/llvm-project/issues/76375
+  add_compile_flag_if_supported(CCACHE_COMPILER_WARNINGS "-Wno-gnu-zero-variadic-macro-arguments")
 
   # If compiler supports these warnings they have to be disabled for now.
   add_compile_flag_if_supported(
index 0a11a7ed9fec8cc461a420d601d42b0601b6b7dc..8f002c2b5db08d3a6301b81ce9129db8929e1d88 100644 (file)
@@ -28,6 +28,7 @@ Checks: '
   -clang-analyzer-optin.performance.Padding,
   -clang-analyzer-valist.Uninitialized,
   clang-diagnostic-*,
+  -clang-diagnostic-gnu-zero-variadic-macro-arguments,
   cppcoreguidelines-*,
   -cppcoreguidelines-avoid-c-arrays,
   -cppcoreguidelines-avoid-do-while,
index 3809a00938e022de1dcbc6855ef4f8b1cc7f4f09..6aa3878e215325aa854f6a34374695bcff81cc3c 100644 (file)
@@ -323,7 +323,7 @@ process_profiling_option(const Context& ctx,
 
   if (new_profile_use) {
     if (args_info.profile_use) {
-      LOG_RAW("Multiple profiling options not supported");
+      LOG("Multiple profiling options not supported");
       return false;
     }
     args_info.profile_use = true;
@@ -336,7 +336,7 @@ process_profiling_option(const Context& ctx,
 
   if (args_info.profile_generate && args_info.profile_use) {
     // Too hard to figure out what the compiler will do.
-    LOG_RAW("Both generating and using profile info, giving up");
+    LOG("Both generating and using profile info, giving up");
     return false;
   }
 
@@ -384,7 +384,7 @@ process_option_arg(const Context& ctx,
   if (args[i] == "--ccache-skip") {
     i++;
     if (i == args.size()) {
-      LOG_RAW("--ccache-skip lacks an argument");
+      LOG("--ccache-skip lacks an argument");
       return Statistic::bad_compiler_arguments;
     }
     state.add_common_arg(args[i]);
@@ -402,7 +402,7 @@ process_option_arg(const Context& ctx,
 
   if (arg == "-ivfsoverlay"
       && !(config.sloppiness().contains(core::Sloppy::ivfsoverlay))) {
-    LOG_RAW(
+    LOG(
       "You have to specify \"ivfsoverlay\" sloppiness when using"
       " -ivfsoverlay to get hits");
     ++i;
@@ -545,8 +545,7 @@ process_option_arg(const Context& ctx,
     for (const auto part : util::Tokenizer(&arg[4], ",")) {
       if (part.starts_with("-a")) {
         if (state.found_Wa_a_opt) {
-          LOG_RAW(
-            "Multiple assembler listing options (-Wa,-a) are not supported");
+          LOG("Multiple assembler listing options (-Wa,-a) are not supported");
           return Statistic::unsupported_compiler_option;
         }
         state.found_Wa_a_opt = true;
@@ -607,7 +606,7 @@ process_option_arg(const Context& ctx,
           args[i]);
       return Statistic::could_not_use_modules;
     } else if (!(config.sloppiness().contains(core::Sloppy::modules))) {
-      LOG_RAW(
+      LOG(
         "You have to specify \"modules\" sloppiness when using"
         " -fmodules to get hits");
       return Statistic::could_not_use_modules;
@@ -1232,7 +1231,7 @@ process_option_arg(const Context& ctx,
 
   if (arg == "-frecord-gcc-switches") {
     state.hash_full_command_line = true;
-    LOG_RAW(
+    LOG(
       "Found -frecord-gcc-switches, hashing original command line unmodified");
   }
 
@@ -1440,19 +1439,19 @@ process_args(Context& ctx)
       || state.found_syntax_only || state.found_analyze_opt);
 
   if (state.input_files.empty()) {
-    LOG_RAW("No input file found");
+    LOG("No input file found");
     return tl::unexpected(Statistic::no_input_file);
   }
   if (state.input_files.size() > 1) {
     if (is_link) {
-      LOG_RAW("Called for link");
+      LOG("Called for link");
       return tl::unexpected(
         util::pstr(state.input_files.front()).str().find("conftest.")
             != std::string::npos
           ? Statistic::autoconf_test
           : Statistic::called_for_link);
     } else {
-      LOG_RAW("Multiple input files");
+      LOG("Multiple input files");
       return tl::unexpected(Statistic::multiple_source_files);
     }
   }
@@ -1468,7 +1467,7 @@ process_args(Context& ctx)
     // are used: GCC writes to wp.d but Clang writes to mf.d. We could
     // potentially support this by behaving differently depending on the
     // compiler type, but let's just bail out for now.
-    LOG_RAW("-Wp,-M[M]D in combination with -MF is not supported");
+    LOG("-Wp,-M[M]D in combination with -MF is not supported");
     return tl::unexpected(Statistic::unsupported_compiler_option);
   }
 
@@ -1482,7 +1481,7 @@ process_args(Context& ctx)
 
   // Don't try to second guess the compiler's heuristics for stdout handling.
   if (args_info.output_obj == "-") {
-    LOG_RAW("Output file is -");
+    LOG("Output file is -");
     return tl::unexpected(Statistic::output_to_stdout);
   }
 
@@ -1547,10 +1546,10 @@ process_args(Context& ctx)
   if (state.found_pch || state.found_fpch_preprocess) {
     args_info.using_precompiled_header = true;
     if (!(config.sloppiness().contains(core::Sloppy::time_macros))) {
-      LOG_RAW(
+      LOG(
         "You have to specify \"time_macros\" sloppiness when using"
         " precompiled headers to get direct hits");
-      LOG_RAW("Disabling direct mode");
+      LOG("Disabling direct mode");
       return tl::unexpected(Statistic::could_not_use_precompiled_header);
     }
   }
@@ -1586,7 +1585,7 @@ process_args(Context& ctx)
 
   if (args_info.output_is_precompiled_header
       && !(config.sloppiness().contains(core::Sloppy::pch_defines))) {
-    LOG_RAW(
+    LOG(
       "You have to specify \"pch_defines,time_macros\" sloppiness when"
       " creating precompiled headers");
     return tl::unexpected(Statistic::could_not_use_precompiled_header);
@@ -1596,7 +1595,7 @@ process_args(Context& ctx)
     if (args_info.output_is_precompiled_header) {
       state.add_common_arg("-c");
     } else {
-      LOG_RAW("No -c option found");
+      LOG("No -c option found");
       // Having a separate statistic for autoconf tests is useful, as they are
       // the dominant form of "called for link" in many cases.
       return tl::unexpected(
@@ -1719,7 +1718,7 @@ process_args(Context& ctx)
                                  get_default_object_file_extension(ctx.config));
         } else {
           // How other compilers behave is currently unknown, so bail out.
-          LOG_RAW(
+          LOG(
             "-Wp,-M[M]D with -o without -MMD, -MQ or -MT is only supported for"
             " GCC or Clang");
           return tl::unexpected(Statistic::unsupported_compiler_option);
@@ -1750,11 +1749,11 @@ process_args(Context& ctx)
 
   if (state.xarch_args.size() > 1) {
     if (state.xarch_args.contains("host")) {
-      LOG_RAW("-Xarch_host in combination with other -Xarch_* is too hard");
+      LOG("-Xarch_host in combination with other -Xarch_* is too hard");
       return tl::unexpected(Statistic::unsupported_compiler_option);
     }
     if (state.xarch_args.contains("device")) {
-      LOG_RAW("-Xarch_device in combination with other -Xarch_* is too hard");
+      LOG("-Xarch_device in combination with other -Xarch_* is too hard");
       return tl::unexpected(Statistic::unsupported_compiler_option);
     }
   }
index 5dc99c96ee6b08aa81b24af658417834c7839b3b..e946b4569f292086de56579520c64ee1ab9d7bda 100644 (file)
@@ -466,7 +466,7 @@ remember_include_file(Context& ctx,
         return tl::unexpected(Statistic::bad_input_file);
       }
       if (ret.contains(HashSourceCode::found_time)) {
-        LOG_RAW("Disabling direct mode");
+        LOG("Disabling direct mode");
         ctx.config.set_direct_mode(false);
       }
     }
@@ -604,7 +604,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const fs::path& path)
       }
       q++;
       if (q >= end) {
-        LOG_RAW("Failed to parse included file path");
+        LOG("Failed to parse included file path");
         return tl::unexpected(Statistic::internal_error);
       }
       // q points to the beginning of an include file path
@@ -661,7 +661,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const fs::path& path)
                     && (q[8] == '"' || (q[8] == '\\' && q[9] == '"')))
                    || q[7] == '"')) {
       if (ctx.config.sloppiness().contains(core::Sloppy::incbin)) {
-        LOG_RAW(
+        LOG(
           "Found potential unsupported .inc"
           "bin directive in source code but continuing due to enabled sloppy"
           " incbin handling");
@@ -672,7 +672,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const fs::path& path)
       // part of inline assembly, refers to an external file. If the file
       // changes, the hash should change as well, but finding out what file to
       // hash is too hard for ccache, so just bail out.
-      LOG_RAW(
+      LOG(
         "Found potential unsupported .inc"
         "bin directive in source code");
       return tl::unexpected(Failure(Statistic::unsupported_code_directive));
@@ -841,7 +841,7 @@ do_execute(Context& ctx, util::Args& args, const bool capture_stdout = true)
       // flag. (Note that there intentionally is no leading dash in
       // "fdiagnostics-color" since some compilers don't include the dash in the
       // error message.)
-      LOG_RAW("-fdiagnostics-color is unsupported; trying again without it");
+      LOG("-fdiagnostics-color is unsupported; trying again without it");
 
       ctx.diagnostics_color_failed = true;
       return do_execute(ctx, args, capture_stdout);
@@ -952,7 +952,7 @@ find_coverage_file(const Context& ctx)
   if (DirEntry(unmangled_form).is_regular_file()) {
     LOG("Found coverage file {}", unmangled_form);
     if (!found_file.empty()) {
-      LOG_RAW("Found two coverage files, cannot continue");
+      LOG("Found two coverage files, cannot continue");
       return {};
     }
     found_file = unmangled_form;
@@ -1002,7 +1002,7 @@ write_result(Context& ctx,
   if (ctx.args_info.generating_coverage) {
     const auto coverage_file = find_coverage_file(ctx);
     if (!coverage_file.found) {
-      LOG_RAW("Coverage file not found");
+      LOG("Coverage file not found");
       return false;
     }
     if (!serializer.add_file(coverage_file.mangled
@@ -1229,7 +1229,7 @@ to_cache(Context& ctx,
     }
   }
 
-  LOG_RAW("Running real compiler");
+  LOG("Running real compiler");
 
   tl::expected<DoExecuteResult, Failure> result;
   result = do_execute(ctx, args);
@@ -1278,7 +1278,7 @@ to_cache(Context& ctx,
     } else {
       ASSERT(false);
     }
-    LOG_RAW("Got result key from dependency file");
+    LOG("Got result key from dependency file");
     LOG("Result key: {}", util::format_base16(*result_key));
   }
 
@@ -1305,14 +1305,14 @@ to_cache(Context& ctx,
   if (!ctx.args_info.expect_output_obj) {
     // Don't probe for object file when we don't expect one since we otherwise
     // will be fooled by an already existing object file.
-    LOG_RAW("Compiler not expected to produce an object file");
+    LOG("Compiler not expected to produce an object file");
   } else {
     DirEntry dir_entry(ctx.args_info.output_obj);
     if (!dir_entry.is_regular_file()) {
-      LOG_RAW("Compiler didn't produce an object file");
+      LOG("Compiler didn't produce an object file");
       return tl::unexpected(Statistic::compiler_produced_no_output);
     } else if (dir_entry.size() == 0) {
-      LOG_RAW("Compiler produced an empty object file");
+      LOG("Compiler produced an empty object file");
       return tl::unexpected(Statistic::compiler_produced_empty_output);
     }
   }
@@ -1437,7 +1437,7 @@ get_result_key_from_cpp(Context& ctx, util::Args& args, Hash& hash)
       FMT("{}{}", ctx.args_info.input_file_prefix, ctx.args_info.input_file));
 
     add_prefix(ctx, args, ctx.config.prefix_command_cpp());
-    LOG_RAW("Running preprocessor");
+    LOG("Running preprocessor");
     const auto result = do_execute(ctx, args, capture_stdout);
     args.pop_back(args.size() - orig_args_size);
 
@@ -1457,7 +1457,7 @@ get_result_key_from_cpp(Context& ctx, util::Args& args, Hash& hash)
         "warning C4828: The file contains a character starting at offset";
       if (util::to_string_view(cpp_stderr_data).find(warning_c4828)
           != std::string_view::npos) {
-        LOG_RAW("Non-UTF-8 source code unsupported in preprocessor mode");
+        LOG("Non-UTF-8 source code unsupported in preprocessor mode");
         return tl::unexpected(Statistic::unsupported_source_encoding);
       }
     }
@@ -1760,7 +1760,7 @@ hash_common_info(const Context& ctx, const util::Args& args, Hash& hash)
     // corresponding .dwo file based on the target object filename, so hashing
     // the object file path will do it, although just hashing the object file
     // base name would be enough.
-    LOG_RAW("Hashing object filename due to -gsplit-dwarf");
+    LOG("Hashing object filename due to -gsplit-dwarf");
     hash.hash_delimiter("object file");
     hash.hash(util::pstr(ctx.args_info.output_obj.filename()));
   }
@@ -1773,7 +1773,7 @@ hash_common_info(const Context& ctx, const util::Args& args, Hash& hash)
     fs::path apparent_absolute_path =
       ctx.apparent_cwd / ctx.args_info.output_obj;
     if (ctx.args_info.profile_prefix_path.empty()) {
-      LOG_RAW("Hashing absolute object filename due to -fprofile-arcs");
+      LOG("Hashing absolute object filename due to -fprofile-arcs");
       hash.hash_delimiter("Absolute object file path");
       // -fprofile-arcs stores "apparent absolute path" for .gcda file
       // names/paths.
@@ -1781,7 +1781,7 @@ hash_common_info(const Context& ctx, const util::Args& args, Hash& hash)
     } else {
       if (util::path_starts_with(apparent_absolute_path,
                                  ctx.args_info.profile_prefix_path)) {
-        LOG_RAW(
+        LOG(
           "Hashing trimmed absolute object filename due to -fprofile-arcs and "
           "-fprofile-prefix-path=path");
         std::string trimmed_absolute_path = apparent_absolute_path.string();
@@ -1793,7 +1793,7 @@ hash_common_info(const Context& ctx, const util::Args& args, Hash& hash)
         hash.hash_delimiter("Trimmed absolute object file path");
         hash.hash(trimmed_absolute_path);
       } else {
-        LOG_RAW(
+        LOG(
           "Hashing absolute object filename due to -fprofile-arcs and "
           "-fprofile-prefix-path=path not being a prefix to the absolute "
           "filename.");
@@ -1808,7 +1808,7 @@ hash_common_info(const Context& ctx, const util::Args& args, Hash& hash)
     // GCC 9+ includes $PWD in the .gcno file. Since we don't have knowledge
     // about compiler version we always (unless sloppiness is wanted) include
     // the directory in the hash for now.
-    LOG_RAW("Hashing apparent CWD due to generating a .gcno file");
+    LOG("Hashing apparent CWD due to generating a .gcno file");
     hash.hash_delimiter("CWD in .gcno");
     hash.hash(ctx.apparent_cwd);
   }
@@ -2321,7 +2321,7 @@ get_manifest_key(Context& ctx, Hash& hash)
     return tl::unexpected(Statistic::internal_error);
   }
   if (ret.contains(HashSourceCode::found_time)) {
-    LOG_RAW("Disabling direct mode");
+    LOG("Disabling direct mode");
     ctx.config.set_direct_mode(false);
     return {};
   }
@@ -2407,7 +2407,7 @@ hash_profiling_related_data(const Context& ctx, Hash& hash)
   }
 
   if (ctx.args_info.profile_use && !hash_profile_data_file(ctx, hash)) {
-    LOG_RAW("No profile data file found");
+    LOG("No profile data file found");
     return tl::unexpected(Statistic::no_input_file);
   }
 
@@ -2416,7 +2416,7 @@ hash_profiling_related_data(const Context& ctx, Hash& hash)
         ctx.args_info.thinlto_index_path);
     hash.hash_delimiter("-fthinlto-index");
     if (!hash_binary_file(ctx, hash, ctx.args_info.thinlto_index_path)) {
-      LOG_RAW("No thinlto index file found");
+      LOG("No thinlto index file found");
       return tl::unexpected(Statistic::no_input_file);
     }
   }
@@ -2439,10 +2439,10 @@ get_result_key_from_manifest(Context& ctx, const Hash::Digest& manifest_key)
         LOG("Failed to look up result key in manifest: {}", e.what());
       }
       if (result_key) {
-        LOG_RAW("Got result key from manifest");
+        LOG("Got result key from manifest");
         return true;
       } else {
-        LOG_RAW("Did not find result key in manifest");
+        LOG("Did not find result key in manifest");
         return false;
       }
     });
@@ -2527,7 +2527,7 @@ calculate_result_and_manifest_key(Context& ctx,
   } else if (ctx.args_info.arch_args.empty()) {
     TRY_ASSIGN(result_key,
                get_result_key_from_cpp(ctx, *preprocessor_args, hash));
-    LOG_RAW("Got result key from preprocessor");
+    LOG("Got result key from preprocessor");
   } else {
     preprocessor_args->push_back("-arch");
     for (size_t i = 0; i < ctx.args_info.arch_args.size(); ++i) {
@@ -2581,7 +2581,7 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Hash::Digest& result_key)
        || ctx.config.compiler_type() == CompilerType::other)
       && ctx.args_info.output_is_precompiled_header
       && mode == FromCacheCallMode::cpp) {
-    LOG_RAW("Not considering cached precompiled header in preprocessor mode");
+    LOG("Not considering cached precompiled header in preprocessor mode");
     return false;
   }
 
@@ -2615,7 +2615,7 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Hash::Digest& result_key)
     return false;
   }
 
-  LOG_RAW("Succeeded getting cached result");
+  LOG("Succeeded getting cached result");
   return true;
 }
 
@@ -2738,7 +2738,7 @@ finalize_at_exit(Context& ctx)
   try {
     if (ctx.config.disable()) {
       // Just log result, don't update statistics.
-      LOG_RAW("Result: disabled");
+      LOG("Result: disabled");
       return;
     }
 
@@ -2846,7 +2846,7 @@ cache_compilation(int argc, const char* const* argv)
       ctx.orig_args.erase_with_prefix("--ccache-");
       add_prefix(ctx, ctx.orig_args, ctx.config.prefix_command());
 
-      LOG_RAW("Failed; falling back to running the real compiler");
+      LOG("Failed; falling back to running the real compiler");
 
       saved_temp_dir = ctx.config.temporary_dir();
       saved_orig_args = std::move(ctx.orig_args);
@@ -2867,7 +2867,7 @@ cache_compilation(int argc, const char* const* argv)
       FMT("execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno)));
   }
 
-  LOG_RAW("=== CCACHE DONE ===");
+  LOG("=== CCACHE DONE ===");
   return EXIT_SUCCESS;
 }
 
@@ -2875,7 +2875,7 @@ static tl::expected<core::StatisticsCounters, Failure>
 do_cache_compilation(Context& ctx)
 {
   if (ctx.config.disable()) {
-    LOG_RAW("ccache is disabled");
+    LOG("ccache is disabled");
     return tl::unexpected(Statistic::none);
   }
 
@@ -2917,17 +2917,17 @@ do_cache_compilation(Context& ctx)
   if (ctx.config.depend_mode()
       && !(ctx.args_info.generating_dependencies
            || ctx.args_info.generating_includes)) {
-    LOG_RAW("Disabling depend mode");
+    LOG("Disabling depend mode");
     ctx.config.set_depend_mode(false);
   }
 
   if (!ctx.config.remote_storage().empty()) {
     if (ctx.config.file_clone()) {
-      LOG_RAW("Disabling file clone mode since remote storage is enabled");
+      LOG("Disabling file clone mode since remote storage is enabled");
       ctx.config.set_file_clone(false);
     }
     if (ctx.config.hard_link()) {
-      LOG_RAW("Disabling hard link mode since remote storage is enabled");
+      LOG("Disabling hard link mode since remote storage is enabled");
       ctx.config.set_hard_link(false);
     }
   }
@@ -2937,7 +2937,7 @@ do_cache_compilation(Context& ctx)
     LOG("Dependency file: {}", ctx.args_info.output_dep);
   }
   if (ctx.args_info.generating_coverage) {
-    LOG_RAW("Coverage file is being generated");
+    LOG("Coverage file is being generated");
   }
   if (ctx.args_info.generating_stackusage) {
     LOG("Stack usage file: {}", ctx.args_info.output_su);
@@ -3006,7 +3006,7 @@ do_cache_compilation(Context& ctx)
   std::optional<Hash::Digest> manifest_key;
 
   if (ctx.config.direct_mode()) {
-    LOG_RAW("Trying direct lookup");
+    LOG("Trying direct lookup");
     TRY_ASSIGN(const auto result_and_manifest_key,
                calculate_result_and_manifest_key(
                  ctx, args_to_hash, direct_hash, nullptr));
@@ -3035,7 +3035,7 @@ do_cache_compilation(Context& ctx)
   }
 
   if (ctx.config.read_only_direct()) {
-    LOG_RAW("Read-only direct mode; running real compiler");
+    LOG("Read-only direct mode; running real compiler");
     return tl::unexpected(Statistic::cache_miss);
   }
 
@@ -3073,9 +3073,9 @@ do_cache_compilation(Context& ctx)
       // The best thing here would probably be to remove the hash entry from
       // the manifest. For now, we use a simpler method: just remove the
       // manifest file.
-      LOG_RAW("Hash from manifest doesn't match preprocessor output");
-      LOG_RAW("Likely reason: different CCACHE_BASEDIRs used");
-      LOG_RAW("Removing manifest as a safety measure");
+      LOG("Hash from manifest doesn't match preprocessor output");
+      LOG("Likely reason: different CCACHE_BASEDIRs used");
+      LOG("Removing manifest as a safety measure");
       ctx.storage.remove(*manifest_key, core::CacheEntryType::manifest);
 
       put_result_in_manifest = true;
@@ -3096,7 +3096,7 @@ do_cache_compilation(Context& ctx)
   }
 
   if (ctx.config.read_only()) {
-    LOG_RAW("Read-only mode; running real compiler");
+    LOG("Read-only mode; running real compiler");
     return tl::unexpected(Statistic::cache_miss);
   }
 
index 8ea8488f444a09a89d64144c8059e0732604c9a4..30c8fdb07585209d117d6e6ebec2ca4139b4ac8b 100644 (file)
@@ -98,7 +98,7 @@ CacheEntry::Header::Header(const Config& config,
     entry_size(0)
 {
   if (compression_type == CompressionType::none) {
-    LOG_RAW("Using no compression");
+    LOG("Using no compression");
   } else if (compression_level == 0) {
     compression_level = default_compression_level;
     LOG("Using Zstandard with default compression level {}", compression_level);
index 14d91f2d413a6b7345536a5390de5353e58f98a5..b635a2888d8ed20978b3f7736bc309a1a3c7eb22 100644 (file)
@@ -222,7 +222,7 @@ Manifest::add_result(
     auto index = get_file_info_index(
       path, digest, mf_files, mf_file_infos, stat_file_function);
     if (!index) {
-      LOG_RAW("Index overflow in manifest");
+      LOG("Index overflow in manifest");
       return false;
     }
     file_info_indexes.push_back(*index);
index 2137acae7f248b3a9221e0e2c29563533a4921a3..fa222e6ab7d6b269931b0cac621f53550600c121 100644 (file)
@@ -78,7 +78,7 @@ ResultRetriever::on_embedded_file(uint8_t file_number,
   } else {
     const auto dest_path = get_dest_path(file_type);
     if (dest_path.empty()) {
-      LOG_RAW("Not writing");
+      LOG("Not writing");
     } else if (util::is_dev_null_path(dest_path)) {
       LOG("Not writing to {}", dest_path);
     } else {
index 9d823a847832f4b743ab6fed633d213a4229e581..a3a84c583e66f4fb200a977628e06dfd9acb6fe7 100644 (file)
@@ -97,7 +97,7 @@ tl::expected<void, std::string>
 make_paths_relative_in_output_dep(const Context& ctx)
 {
   if (ctx.config.base_dirs().empty()) {
-    LOG_RAW("Base dir not set, skip using relative paths");
+    LOG("Base dir not set, skip using relative paths");
     return {}; // nothing to do
   }
 
index b1776236685d55584635b5dbeb2b9f8530c32b83..7a631014f4ccaee97a69660efcaa2fbf32e21a98 100644 (file)
@@ -387,7 +387,7 @@ find_non_ccache_executable(const Context& ctx,
     path_list = util::getenv_path_list("PATH");
   }
   if (path_list.empty()) {
-    LOG_RAW("No PATH variable");
+    LOG("No PATH variable");
     return {};
   }
 
index eccfab6eb96264d951966d3bb9f8420484fb7c20..3fe11a27f708308e5e03daae56e6c083948d6974 100644 (file)
@@ -901,10 +901,13 @@ LocalStorage::recompress(const std::optional<int8_t> level,
         auto l2_content_lock = get_level_2_content_lock(l1_index, l2_index);
         l2_content_lock.make_long_lived(lock_manager);
         if (!l2_content_lock.acquire()) {
-          // LOG_RAW+fmt::format instead of LOG due to GCC 12.3 bug #109241
-          LOG_RAW(fmt::format("Failed to acquire content lock for {:x}/{:x}",
-                              l1_index,
-                              l2_index));
+          // Not using LOG here due to GCC 12.3 bug #109241.
+          if (util::logging::enabled()) {
+            util::logging::log(
+              FMT("Failed to acquire content lock for {:x}/{:x}",
+                  l1_index,
+                  l2_index));
+          }
           ++completed_dirs;
           progress_receiver(static_cast<double>(completed_dirs) / 256.0);
           return;
@@ -922,13 +925,15 @@ LocalStorage::recompress(const std::optional<int8_t> level,
                   file, level, core::FileRecompressor::KeepAtime::no);
                 auto old_size = file.size();
                 auto new_size = new_dir_entry.size();
-                // LOG_RAW+fmt::format instead of LOG due to GCC 12.3 bug
-                // #109241
+                // Not using LOG here due to GCC 12.3 bug #109241.
                 if (new_size != old_size) {
-                  LOG_RAW(fmt::format("Recompressed {} from {} to {} bytes",
-                                      file.path(),
-                                      old_size,
-                                      new_size));
+                  if (util::logging::enabled()) {
+                    util::logging::log(
+                      FMT("Recompressed {} from {} to {} bytes",
+                          file.path(),
+                          old_size,
+                          new_size));
+                  }
                   auto size_change_kibibyte =
                     kibibyte_size_diff(file, new_dir_entry);
                   if (size_change_kibibyte != 0) {
@@ -943,10 +948,11 @@ LocalStorage::recompress(const std::optional<int8_t> level,
                   }
                 }
               } catch (core::Error& e) {
-                // LOG_RAW+fmt::format instead of LOG due to GCC 12.3 bug
-                // #109241
-                LOG_RAW(fmt::format(
-                  "Error when recompressing {}: {}", file.path(), e.what()));
+                // Not using LOG here due to GCC 12.3 bug #109241.
+                if (util::logging::enabled()) {
+                  util::logging::log(FMT(
+                    "Error when recompressing {}: {}", file.path(), e.what()));
+                }
                 incompressible_size += file.size_on_disk();
               }
             });
index 707c4e9a515a34bd8520df11bc8972852fd4f80f..f33f0edce5cc3baa3f85fd28f6ca5d37dbc324a3 100644 (file)
@@ -447,7 +447,7 @@ HelperBackend::finalize_connection()
   }
 
   if (!m_client.has_capability(Client::Capability::get_put_remove_stop)) {
-    LOG_RAW("Remote storage helper does not support capability 0");
+    LOG("Remote storage helper does not support capability 0");
     return tl::unexpected(Failure::error);
   }
 
@@ -490,7 +490,7 @@ HelperBackend::ensure_connected(bool spawn)
   // processes from spawning simultaneously.
   util::LockFile spawn_lock(m_endpoint_lock_path);
   if (!spawn_lock.acquire()) {
-    LOG_RAW("Failed to acquire spawn lock");
+    LOG("Failed to acquire spawn lock");
     return tl::unexpected(Failure::error);
   }
 
@@ -600,7 +600,7 @@ void
 HelperBackend::stop()
 {
   if (auto r = ensure_connected(false); !r) {
-    LOG_RAW("Failed to connect to remote storage helper");
+    LOG("Failed to connect to remote storage helper");
     return;
   }
   if (!m_connected) {
index e632a77530998f1d265607726a7a7d3e915f26a2..abe3a6887674a1b17f64987dc7d2e97bd65de54a 100644 (file)
@@ -274,7 +274,7 @@ RedisStorageBackend::connect(const Url& url,
     throw Failed("Failed to set operation timeout");
   }
 
-  LOG_RAW("Redis connection OK");
+  LOG("Redis connection OK");
 }
 
 void
index 9d782404745f1e4d62da941002e8ad90f0030962..cc3186a829ff0fd1d8744fbfbad7a894ce520f79 100644 (file)
@@ -377,7 +377,7 @@ get_remote_storage(std::string_view scheme,
   }
 
   if (config.helper == "_builtin_" || scheme == "file") {
-    LOG_RAW("Forcing use of builtin storage backend");
+    LOG("Forcing use of builtin storage backend");
   } else {
     // Look up and use storage helper if available.
     std::string helper_name =
index 5c1e5a77fbdc5933a82b05ae70d929157e727343..c48049f7f2044d6c20a23c52de00dc4bcba46485 100644 (file)
 #include <optional>
 #include <string_view>
 
-// Log a raw message (plus a newline character).
-#define LOG_RAW(message_)                                                      \
+// Log a message (plus a newline character).
+#define LOG(format_, ...)                                                      \
   do {                                                                         \
     if (util::logging::enabled()) {                                            \
-      util::logging::log(std::string_view(message_));                          \
+      util::logging::log(fmt::format(format_ __VA_OPT__(, ) __VA_ARGS__));     \
     }                                                                          \
   } while (false)
 
-// Log a message (plus a newline character) described by a format string with at
-// least one placeholder.
-#define LOG(format_, ...) LOG_RAW(fmt::format(format_, __VA_ARGS__))
-
-// Log a message (plus a newline character) described by a format string with at
-// least one placeholder without flushing and with a reused timestamp.
+// Log a message (plus a newline character) without flushing and with a reused
+// timestamp.
 #define BULK_LOG(logger_, format_, ...)                                        \
-  logger_.log(fmt::format(format_, __VA_ARGS__))
+  logger_.log(fmt::format(format_ __VA_OPT__(, ) __VA_ARGS__))
 
 namespace util::logging {
 
index 452b00f5ee0f77157b5101c9bae51bd95e88b140..39043ca912202b829cddefcb813949b090ac470d 100644 (file)
@@ -36,14 +36,14 @@ LongLivedLockFileManager::~LongLivedLockFileManager()
 {
 #ifndef _WIN32
   if (m_thread.joinable()) {
-    LOG_RAW("Stopping keep-alive thread");
+    LOG("Stopping keep-alive thread");
     {
       std::unique_lock<std::mutex> lock(m_mutex);
       m_stop = true;
     }
     m_stop_condition.notify_one();
     m_thread.join();
-    LOG_RAW("Stopped keep-alive thread");
+    LOG("Stopped keep-alive thread");
   }
 #endif
 }
@@ -75,7 +75,7 @@ LongLivedLockFileManager::deregister_alive_file(
 void
 LongLivedLockFileManager::start_thread()
 {
-  LOG_RAW("Starting keep-alive thread");
+  LOG("Starting keep-alive thread");
   m_thread = std::thread([&] {
     auto awake_time = std::chrono::steady_clock::now();
     while (true) {
@@ -90,7 +90,7 @@ LongLivedLockFileManager::start_thread()
       awake_time += k_keep_alive_interval;
     }
   });
-  LOG_RAW("Started keep-alive thread");
+  LOG("Started keep-alive thread");
 }
 #endif