]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix prefix command lookup from PATH (#1474)
authorRomain Geissler @ Amadeus <romain.geissler@amadeus.com>
Fri, 21 Jun 2024 08:00:15 +0000 (10:00 +0200)
committerGitHub <noreply@github.com>
Fri, 21 Jun 2024 08:00:15 +0000 (10:00 +0200)
This fixes regression in 6b85822b50cc509b4d595bf89340bdf0da526dc9.

src/ccache/ccache.cpp

index 0d8fa4cd5f9b5c70916982bf4bd3651aa4ef9531..e2d3dfd1f23a1266fc200228a27902bd37ec1979 100644 (file)
@@ -174,7 +174,7 @@ should_disable_ccache_for_input_file(const std::string& path)
 }
 
 static void
-add_prefix(Args& args, const std::string& prefix_command)
+add_prefix(const Context& ctx, Args& args, const std::string& prefix_command)
 {
   if (prefix_command.empty()) {
     return;
@@ -185,6 +185,14 @@ add_prefix(Args& args, const std::string& prefix_command)
     prefixes.push_back(prefix);
   }
 
+  if (!prefixes.empty() && !util::is_full_path(prefixes[0])) {
+    std::string path = find_executable(ctx, prefixes[0], ctx.orig_args[0]);
+    if (path.empty()) {
+      throw core::Fatal(FMT("{}: {}", prefixes[0], strerror(errno)));
+    }
+    prefixes[0] = path;
+  }
+
   LOG("Using command-line prefix {}", prefix_command);
   for (size_t i = prefixes.size(); i != 0; i--) {
     args.push_front(prefixes[i - 1]);
@@ -1314,7 +1322,7 @@ get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash)
     args.push_back(
       FMT("{}{}", ctx.args_info.input_file_prefix, ctx.args_info.input_file));
 
-    add_prefix(args, ctx.config.prefix_command_cpp());
+    add_prefix(ctx, args, ctx.config.prefix_command_cpp());
     LOG_RAW("Running preprocessor");
     const auto result = do_execute(ctx, args, false);
     args.pop_back(args.size() - orig_args_size);
@@ -2462,7 +2470,7 @@ cache_compilation(int argc, const char* const* argv)
       ASSERT(!ctx.orig_args.empty());
 
       ctx.orig_args.erase_with_prefix("--ccache-");
-      add_prefix(ctx.orig_args, ctx.config.prefix_command());
+      add_prefix(ctx, ctx.orig_args, ctx.config.prefix_command());
 
       LOG_RAW("Failed; falling back to running the real compiler");
 
@@ -2729,7 +2737,8 @@ do_cache_compilation(Context& ctx)
     return tl::unexpected(Statistic::cache_miss);
   }
 
-  add_prefix(process_args_result->compiler_args, ctx.config.prefix_command());
+  add_prefix(
+    ctx, process_args_result->compiler_args, ctx.config.prefix_command());
 
   // In depend_mode, extend the direct hash.
   Hash* depend_mode_hash = ctx.config.depend_mode() ? &direct_hash : nullptr;