[vcpkg] Fix tool lookup without which (#10375)

On Linux and macOS, if `which` is not installed (notably in Amazon's
amazonlinux docker base image), vcpkg fails to find system-installed
versions of tools. This is an issue when we don't attempt to install our
own versions of the tools, like with git (we fail to find any version of
git, and thus can't install any ports which come from a git repository).

Fixes #9927
This commit is contained in:
nicole mazzuca 2020-03-13 13:14:38 -07:00 committed by GitHub
parent b2e928f19b
commit 42fa9b0c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -666,6 +666,10 @@ namespace vcpkg::Files
#if defined(_WIN32)
static constexpr StringLiteral EXTS[] = {".cmd", ".exe", ".bat"};
auto paths = Strings::split(System::get_environment_variable("PATH").value_or_exit(VCPKG_LINE_INFO), ";");
#else
static constexpr StringLiteral EXTS[] = {""};
auto paths = Strings::split(System::get_environment_variable("PATH").value_or_exit(VCPKG_LINE_INFO), ":");
#endif
std::vector<fs::path> ret;
std::error_code ec;
@ -684,16 +688,6 @@ namespace vcpkg::Files
}
return ret;
#else
const std::string cmd = Strings::concat("which ", name);
auto out = System::cmd_execute_and_capture_output(cmd);
if (out.exit_code != 0)
{
return {};
}
return Util::fmap(Strings::split(out.output, "\n"), [](auto&& s) { return fs::path(s); });
#endif
}
};