From f4c6fe61d0ec08d6911f914d0f57ab525a08ec0b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 16 May 2018 15:11:55 -0700 Subject: [PATCH] [vcpkg.exe] Don't error if vswhere.exe is not found --- toolsrc/src/vcpkg/commands.fetch.cpp | 68 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/toolsrc/src/vcpkg/commands.fetch.cpp b/toolsrc/src/vcpkg/commands.fetch.cpp index d50d13c59a3..c460316657c 100644 --- a/toolsrc/src/vcpkg/commands.fetch.cpp +++ b/toolsrc/src/vcpkg/commands.fetch.cpp @@ -682,45 +682,43 @@ namespace vcpkg::Commands::Fetch static std::vector get_visual_studio_instances(const VcpkgPaths& paths) { const auto& fs = paths.get_filesystem(); + std::vector instances; 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"; - Checks::check_exit( - 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, "", ""); - - std::vector instances; - for (const VcpkgStringRange& instance : instance_entries) + if (fs.exists(vswhere_exe)) { - auto maybe_is_prerelease = find_at_most_one_enclosed(instance, "", ""); + 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; - if (auto p = maybe_is_prerelease.get()) + const auto instance_entries = find_all_enclosed(code_and_output.output, "", ""); + for (const VcpkgStringRange& instance : instance_entries) { - 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); - } + auto maybe_is_prerelease = find_at_most_one_enclosed(instance, "", ""); - instances.emplace_back( - find_exactly_one_enclosed(instance, "", "").to_string(), - find_exactly_one_enclosed(instance, "", "").to_string(), - release_type); + VisualStudioInstance::ReleaseType release_type = VisualStudioInstance::ReleaseType::LEGACY; + if (const auto p = maybe_is_prerelease.get()) + { + 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, "", "").to_string(), + find_exactly_one_enclosed(instance, "", "").to_string(), + release_type); + } } 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); }; - 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;