mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 12:06:49 +08:00
[vcpkg.exe] Don't error if vswhere.exe is not found
This commit is contained in:
parent
8347101e63
commit
f4c6fe61d0
@ -682,33 +682,30 @@ namespace vcpkg::Commands::Fetch
|
||||
static std::vector<VisualStudioInstance> get_visual_studio_instances(const VcpkgPaths& paths)
|
||||
{
|
||||
const auto& fs = paths.get_filesystem();
|
||||
std::vector<VisualStudioInstance> instances;
|
||||
|
||||
const auto& program_files_32_bit = System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO);
|
||||
const fs::path vswhere_exe = program_files_32_bit / "Microsoft Visual Studio" / "Installer" / "vswhere.exe";
|
||||
Checks::check_exit(
|
||||
VCPKG_LINE_INFO, fs.exists(vswhere_exe), "Could not locate vswhere at %s", vswhere_exe.u8string());
|
||||
|
||||
// Instances from vswhere
|
||||
const fs::path vswhere_exe = program_files_32_bit / "Microsoft Visual Studio" / "Installer" / "vswhere.exe";
|
||||
if (fs.exists(vswhere_exe))
|
||||
{
|
||||
const auto code_and_output = System::cmd_execute_and_capture_output(
|
||||
Strings::format(R"("%s" -prerelease -legacy -products * -format xml)", vswhere_exe.u8string()));
|
||||
|
||||
Checks::check_exit(VCPKG_LINE_INFO,
|
||||
code_and_output.exit_code == 0,
|
||||
"Running vswhere.exe failed with message:\n%s",
|
||||
code_and_output.output);
|
||||
|
||||
const auto& xml_as_string = code_and_output.output;
|
||||
|
||||
const auto instance_entries = find_all_enclosed(xml_as_string, "<instance>", "</instance>");
|
||||
|
||||
std::vector<VisualStudioInstance> instances;
|
||||
const auto instance_entries = find_all_enclosed(code_and_output.output, "<instance>", "</instance>");
|
||||
for (const VcpkgStringRange& instance : instance_entries)
|
||||
{
|
||||
auto maybe_is_prerelease = find_at_most_one_enclosed(instance, "<isPrerelease>", "</isPrerelease>");
|
||||
|
||||
VisualStudioInstance::ReleaseType release_type = VisualStudioInstance::ReleaseType::LEGACY;
|
||||
if (auto p = maybe_is_prerelease.get())
|
||||
if (const auto p = maybe_is_prerelease.get())
|
||||
{
|
||||
auto s = p->to_string();
|
||||
const auto s = p->to_string();
|
||||
if (s == "0")
|
||||
release_type = VisualStudioInstance::ReleaseType::STABLE;
|
||||
else if (s == "1")
|
||||
@ -722,6 +719,7 @@ namespace vcpkg::Commands::Fetch
|
||||
find_exactly_one_enclosed(instance, "<installationVersion>", "</installationVersion>").to_string(),
|
||||
release_type);
|
||||
}
|
||||
}
|
||||
|
||||
const auto append_if_has_cl = [&](fs::path&& path_root) {
|
||||
const auto cl_exe = path_root / "VC" / "bin" / "cl.exe";
|
||||
@ -731,8 +729,9 @@ namespace vcpkg::Commands::Fetch
|
||||
instances.emplace_back(std::move(path_root), "14.0", VisualStudioInstance::ReleaseType::LEGACY);
|
||||
};
|
||||
|
||||
auto maybe_vs140comntools = System::get_environment_variable("vs140comntools");
|
||||
if (const auto path_as_string = maybe_vs140comntools.get())
|
||||
// VS2015 instance from environment variable
|
||||
auto maybe_vs140_comntools = System::get_environment_variable("vs140comntools");
|
||||
if (const auto path_as_string = maybe_vs140_comntools.get())
|
||||
{
|
||||
// We want lexically_normal(), but it is not available
|
||||
// Correct root path might be 2 or 3 levels up, depending on if the path has trailing backslash. Try both.
|
||||
@ -741,6 +740,7 @@ namespace vcpkg::Commands::Fetch
|
||||
append_if_has_cl(fs::path{*path_as_string}.parent_path().parent_path().parent_path());
|
||||
}
|
||||
|
||||
// VS2015 instance from Program Files
|
||||
append_if_has_cl(program_files_32_bit / "Microsoft Visual Studio 14.0");
|
||||
|
||||
return instances;
|
||||
|
Loading…
Reference in New Issue
Block a user