]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Log config and command line before finding compiler
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 8 Feb 2023 21:24:01 +0000 (22:24 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 9 Feb 2023 21:07:21 +0000 (22:07 +0100)
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.

src/ccache.cpp

index c26133a075258490cbafa25d233e3e649feb1970..ff5315c1f81d674c491ee3d3e8547719fd161c92 100644 (file)
@@ -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