}
if (!prefixes.empty() && !util::is_full_path(prefixes[0])) {
- std::string path = find_executable(ctx, prefixes[0], ctx.orig_args[0]);
+ std::string path =
+ find_non_ccache_executable(ctx, prefixes[0], ctx.orig_args[0]);
if (path.empty()) {
throw core::Fatal(FMT("{}: {}", prefixes[0], strerror(errno)));
}
TRY(hash_compiler(ctx, hash, de, path, false));
}
} else {
- std::string path = find_executable(ctx, compiler, ctx.orig_args[0]);
+ std::string path =
+ find_non_ccache_executable(ctx, compiler, ctx.orig_args[0]);
if (!path.empty()) {
DirEntry de(path, DirEntry::LogOnError::yes);
TRY(hash_compiler(ctx, hash, de, ccbin, false));
ctx.storage.initialize();
- find_compiler(ctx, &find_executable, masquerading_as_compiler);
+ find_compiler(ctx, &find_non_ccache_executable, masquerading_as_compiler);
// Guess compiler after logging the config value in order to be able to
// display "compiler_type = auto" before overwriting the value with the
#endif
std::string
-find_executable(const Context& ctx,
- const std::string& name,
- const std::string& exclude_path)
+find_non_ccache_executable(const Context& ctx,
+ const std::string& name,
+ const std::string& exclude_path)
{
if (fs::path(name).is_absolute()) {
return name;
return {};
}
- return find_executable_in_path(name, path_list, exclude_path).string();
+ auto check = [](const fs::path& path) { return !is_ccache_executable(path); };
+ return find_executable_in_path(name, path_list, exclude_path, check).string();
}
fs::path
-find_executable_in_path(const std::string& name,
+find_executable_in_path(std::string_view name,
const std::vector<fs::path>& path_list,
- const std::optional<fs::path>& exclude_path)
+ const std::optional<fs::path>& exclude_path,
+ std::function<bool(const fs::path&)> extra_check)
{
if (path_list.empty()) {
return {};
if (candidate_exists) {
auto real_candidate = fs::canonical(candidate);
if (real_candidate && *real_candidate != real_exclude_path
- && !is_ccache_executable(*real_candidate)) {
+ && (!extra_check || extra_check(*real_candidate))) {
return candidate;
}
}
#include <ccache/util/fd.hpp>
#include <filesystem>
+#include <functional>
#include <optional>
#include <string>
+#include <string_view>
#include <vector>
class Context;
void execute_noreturn(const char* const* argv,
const std::filesystem::path& temp_dir);
-// Find an executable named `name` in `$PATH`. Exclude any executables that are
-// links to `exclude_path`.
-std::string find_executable(const Context& ctx,
- const std::string& name,
- const std::string& exclude_path);
+// Find an executable named `name` in `$PATH` that is not a ccache executable.
+// Exclude any executables that are links to `exclude_path`.
+std::string find_non_ccache_executable(const Context& ctx,
+ const std::string& name,
+ const std::string& exclude_path);
std::filesystem::path find_executable_in_path(
- const std::string& name,
+ std::string_view name,
const std::vector<std::filesystem::path>& path_list,
- const std::optional<std::filesystem::path>& exclude_path = std::nullopt);
+ const std::optional<std::filesystem::path>& exclude_path = std::nullopt,
+ std::function<bool(const std::filesystem::path&)> extra_check = {});