aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2018-05-16 15:11:55 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2018-05-16 15:11:55 -0700
commitf4c6fe61d0ec08d6911f914d0f57ab525a08ec0b (patch)
treeb3360f88a970852c8d38aed7740a2fd7310d5c93
parent8347101e63649dab2930bbc11dab39fa37c1e927 (diff)
downloadvcpkg-f4c6fe61d0ec08d6911f914d0f57ab525a08ec0b.tar.gz
vcpkg-f4c6fe61d0ec08d6911f914d0f57ab525a08ec0b.zip
[vcpkg.exe] Don't error if vswhere.exe is not found
-rw-r--r--toolsrc/src/vcpkg/commands.fetch.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/toolsrc/src/vcpkg/commands.fetch.cpp b/toolsrc/src/vcpkg/commands.fetch.cpp
index d50d13c59..c46031665 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<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());
-
- 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)
+ // Instances from vswhere
+ const fs::path vswhere_exe = program_files_32_bit / "Microsoft Visual Studio" / "Installer" / "vswhere.exe";
+ if (fs.exists(vswhere_exe))
{
- 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;
- if (auto p = maybe_is_prerelease.get())
+ const auto instance_entries = find_all_enclosed(code_and_output.output, "<instance>", "</instance>");
+ 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, "<isPrerelease>", "</isPrerelease>");
- instances.emplace_back(
- find_exactly_one_enclosed(instance, "<installationPath>", "</installationPath>").to_string(),
- find_exactly_one_enclosed(instance, "<installationVersion>", "</installationVersion>").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, "<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) {
@@ -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;