[vcpkg.exe] Don't error if vswhere.exe is not found

This commit is contained in:
Alexander Karatarakis 2018-05-16 15:11:55 -07:00
parent 8347101e63
commit f4c6fe61d0

View File

@ -682,45 +682,43 @@ namespace vcpkg::Commands::Fetch
static std::vector<VisualStudioInstance> get_visual_studio_instances(const VcpkgPaths& paths) static std::vector<VisualStudioInstance> get_visual_studio_instances(const VcpkgPaths& paths)
{ {
const auto& fs = paths.get_filesystem(); 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 auto& program_files_32_bit = System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO);
// Instances from vswhere
const fs::path vswhere_exe = program_files_32_bit / "Microsoft Visual Studio" / "Installer" / "vswhere.exe"; const fs::path vswhere_exe = program_files_32_bit / "Microsoft Visual Studio" / "Installer" / "vswhere.exe";
Checks::check_exit( if (fs.exists(vswhere_exe))
VCPKG_LINE_INFO, fs.exists(vswhere_exe), "Could not locate vswhere at %s", vswhere_exe.u8string());
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;
for (const VcpkgStringRange& instance : instance_entries)
{ {
auto maybe_is_prerelease = find_at_most_one_enclosed(instance, "<isPrerelease>", "</isPrerelease>"); 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);
VisualStudioInstance::ReleaseType release_type = VisualStudioInstance::ReleaseType::LEGACY; const auto instance_entries = find_all_enclosed(code_and_output.output, "<instance>", "</instance>");
if (auto p = maybe_is_prerelease.get()) for (const VcpkgStringRange& instance : instance_entries)
{ {
auto s = p->to_string(); auto maybe_is_prerelease = find_at_most_one_enclosed(instance, "<isPrerelease>", "</isPrerelease>");
if (s == "0")
release_type = VisualStudioInstance::ReleaseType::STABLE;
else if (s == "1")
release_type = VisualStudioInstance::ReleaseType::PRERELEASE;
else
Checks::unreachable(VCPKG_LINE_INFO);
}
instances.emplace_back( VisualStudioInstance::ReleaseType release_type = VisualStudioInstance::ReleaseType::LEGACY;
find_exactly_one_enclosed(instance, "<installationPath>", "</installationPath>").to_string(), if (const auto p = maybe_is_prerelease.get())
find_exactly_one_enclosed(instance, "<installationVersion>", "</installationVersion>").to_string(), {
release_type); const auto s = p->to_string();
if (s == "0")
release_type = VisualStudioInstance::ReleaseType::STABLE;
else if (s == "1")
release_type = VisualStudioInstance::ReleaseType::PRERELEASE;
else
Checks::unreachable(VCPKG_LINE_INFO);
}
instances.emplace_back(
find_exactly_one_enclosed(instance, "<installationPath>", "</installationPath>").to_string(),
find_exactly_one_enclosed(instance, "<installationVersion>", "</installationVersion>").to_string(),
release_type);
}
} }
const auto append_if_has_cl = [&](fs::path&& path_root) { const auto append_if_has_cl = [&](fs::path&& path_root) {
@ -731,8 +729,9 @@ namespace vcpkg::Commands::Fetch
instances.emplace_back(std::move(path_root), "14.0", VisualStudioInstance::ReleaseType::LEGACY); instances.emplace_back(std::move(path_root), "14.0", VisualStudioInstance::ReleaseType::LEGACY);
}; };
auto maybe_vs140comntools = System::get_environment_variable("vs140comntools"); // VS2015 instance from environment variable
if (const auto path_as_string = maybe_vs140comntools.get()) 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 // 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. // 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()); 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"); append_if_has_cl(program_files_32_bit / "Microsoft Visual Studio 14.0");
return instances; return instances;