From: Romain Geissler @ Amadeus Date: Fri, 21 Jun 2024 08:00:15 +0000 (+0200) Subject: fix: Fix prefix command lookup from PATH (#1474) X-Git-Tag: v4.11~145 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8372b56ead496a2f9d152590263bcd7b23013f77;p=thirdparty%2Fccache.git fix: Fix prefix command lookup from PATH (#1474) This fixes regression in 6b85822b50cc509b4d595bf89340bdf0da526dc9. --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 0d8fa4cd..e2d3dfd1 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -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;