From: Joel Rosdahl Date: Thu, 7 Nov 2024 20:54:35 +0000 (+0100) Subject: fix: Use util::getenv_path_list to get PATH in find_executable_in_path X-Git-Tag: v4.11~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47ae9bc335b2ee59b1f3fac6f2b07abf901a76d7;p=thirdparty%2Fccache.git fix: Use util::getenv_path_list to get PATH in find_executable_in_path This should improve support for non-ASCII paths in Windows. --- diff --git a/src/ccache/execute.cpp b/src/ccache/execute.cpp index fd6c7bdf..ce529ac2 100644 --- a/src/ccache/execute.cpp +++ b/src/ccache/execute.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -87,10 +88,14 @@ execute_noreturn(const char* const* argv, const fs::path& temp_dir) std::string win32getshell(const std::string& path) { - const char* path_list = getenv("PATH"); + auto path_list = util::getenv_path_list("PATH"); + if (path_list.empty()) { + return {}; + } + std::string sh; - if (util::to_lowercase(util::pstr(fs::path(path).extension()).str()) == ".sh" - && path_list) { + if (util::to_lowercase(util::pstr(fs::path(path).extension()).str()) + == ".sh") { sh = util::pstr(find_executable_in_path("sh.exe", path_list)); } if (sh.empty() && getenv("CCACHE_DETECT_SHEBANG")) { @@ -99,7 +104,7 @@ win32getshell(const std::string& path) if (fp) { char buf[10] = {0}; fgets(buf, sizeof(buf) - 1, fp.get()); - if (std::string(buf) == "#!/bin/sh" && path_list) { + if (std::string(buf) == "#!/bin/sh") { sh = util::pstr(find_executable_in_path("sh.exe", path_list)); } } @@ -367,9 +372,9 @@ find_executable(const Context& ctx, return name; } - std::string path_list = ctx.config.path(); + auto path_list = util::split_path_list(ctx.config.path()); if (path_list.empty()) { - path_list = getenv("PATH"); + path_list = util::getenv_path_list("PATH"); } if (path_list.empty()) { LOG_RAW("No PATH variable"); @@ -381,7 +386,7 @@ find_executable(const Context& ctx, fs::path find_executable_in_path(const std::string& name, - const std::string& path_list, + const std::vector& path_list, const std::optional& exclude_path) { if (path_list.empty()) { @@ -393,7 +398,7 @@ find_executable_in_path(const std::string& name, // Search the path list looking for the first compiler of the right name that // isn't us. - for (const auto& dir : util::split_path_list(path_list)) { + for (const auto& dir : path_list) { const std::vector candidates = { dir / name, #ifdef _WIN32 diff --git a/src/ccache/execute.hpp b/src/ccache/execute.hpp index a3ef9c59..92940692 100644 --- a/src/ccache/execute.hpp +++ b/src/ccache/execute.hpp @@ -23,6 +23,7 @@ #include #include #include +#include class Context; @@ -42,7 +43,7 @@ std::string find_executable(const Context& ctx, std::filesystem::path find_executable_in_path( const std::string& name, - const std::string& path_list, + const std::vector& path_list, const std::optional& exclude_path = std::nullopt); #ifdef _WIN32 diff --git a/src/ccache/hashutil.cpp b/src/ccache/hashutil.cpp index 4db8133c..880bedee 100644 --- a/src/ccache/hashutil.cpp +++ b/src/ccache/hashutil.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -387,7 +388,8 @@ hash_command_output(Hash& hash, STARTUPINFO si; memset(&si, 0x00, sizeof(si)); - auto path = find_executable_in_path(args[0], getenv("PATH")).string(); + auto path = + find_executable_in_path(args[0], util::getenv_path_list("PATH")).string(); if (path.empty()) { path = args[0]; }