From: Joel Rosdahl Date: Wed, 8 Feb 2023 21:24:01 +0000 (+0100) Subject: fix: Log config and command line before finding compiler X-Git-Tag: v4.8~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62ce4a31bb6880510b7e878be411e1d8f06cfa3c;p=thirdparty%2Fccache.git fix: Log config and command line before finding compiler If the compiler can't be found then ccache exits early and doesn't print the config and command line to the log. This makes it harder to debug problems with finding the compiler, like issue #1249. Improve this by logging "safe things" before searching for the compiler. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index c26133a07..ff5315c1f 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -2266,10 +2266,6 @@ cache_compilation(int argc, const char* const* argv) initialize(ctx, argc, argv); - MTR_BEGIN("main", "find_compiler"); - find_compiler(ctx, &find_executable); - MTR_END("main", "find_compiler"); - const auto result = do_cache_compilation(ctx, argv); ctx.storage.local.increment_statistics(result ? *result : result.error().counters()); @@ -2330,11 +2326,6 @@ cache_compilation(int argc, const char* const* argv) static nonstd::expected do_cache_compilation(Context& ctx, const char* const* argv) { - if (ctx.actual_cwd.empty()) { - LOG("Unable to determine current working directory: {}", strerror(errno)); - return nonstd::make_unexpected(Statistic::internal_error); - } - if (!ctx.config.log_file().empty() || ctx.config.debug()) { ctx.config.visit_items([&ctx](const std::string& key, const std::string& value, @@ -2347,6 +2338,19 @@ do_cache_compilation(Context& ctx, const char* const* argv) }); } + LOG("Command line: {}", Util::format_argv_for_logging(argv)); + LOG("Hostname: {}", Util::get_hostname()); + LOG("Working directory: {}", ctx.actual_cwd); + if (ctx.apparent_cwd != ctx.actual_cwd) { + LOG("Apparent working directory: {}", ctx.apparent_cwd); + } + + // Note: do_cache_compilation must not return or use ctx.orig_args before + // find_compiler is executed. + MTR_BEGIN("main", "find_compiler"); + find_compiler(ctx, &find_executable); + MTR_END("main", "find_compiler"); + // Guess compiler after logging the config value in order to be able to // display "compiler_type = auto" before overwriting the value with the // guess. @@ -2355,20 +2359,18 @@ do_cache_compilation(Context& ctx, const char* const* argv) } DEBUG_ASSERT(ctx.config.compiler_type() != CompilerType::auto_guess); + LOG("Compiler type: {}", compiler_type_to_string(ctx.config.compiler_type())); + if (ctx.config.disable()) { LOG_RAW("ccache is disabled"); return nonstd::make_unexpected(Statistic::none); } - LOG("Command line: {}", Util::format_argv_for_logging(argv)); - LOG("Hostname: {}", Util::get_hostname()); - LOG("Working directory: {}", ctx.actual_cwd); - if (ctx.apparent_cwd != ctx.actual_cwd) { - LOG("Apparent working directory: {}", ctx.apparent_cwd); + if (ctx.actual_cwd.empty()) { + LOG("Unable to determine current working directory: {}", strerror(errno)); + return nonstd::make_unexpected(Statistic::internal_error); } - LOG("Compiler type: {}", compiler_type_to_string(ctx.config.compiler_type())); - // Set CCACHE_DISABLE so no process ccache executes from now on will risk // calling ccache second time. For instance, if the real compiler is a wrapper // script that calls "ccache $compiler ..." we want that inner ccache call to