diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2023-02-08 22:24:01 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2023-02-09 22:07:21 +0100 |
commit | 62ce4a31bb6880510b7e878be411e1d8f06cfa3c (patch) | |
tree | 3a6548a2683eaf4a3d0fc2aaccb8874bf83999a0 | |
parent | b59f21d608e4f7d0a2d17965aa1f2f6fa7f643ff (diff) | |
download | ccache-62ce4a31bb6880510b7e878be411e1d8f06cfa3c.tar.gz |
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.
-rw-r--r-- | src/ccache.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp index c26133a0..ff5315c1 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<core::StatisticsCounters, Failure> 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 |