aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/VcpkgPaths.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc/src/VcpkgPaths.cpp')
-rw-r--r--toolsrc/src/VcpkgPaths.cpp78
1 files changed, 54 insertions, 24 deletions
diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp
index 3dd32de01..9068e3903 100644
--- a/toolsrc/src/VcpkgPaths.cpp
+++ b/toolsrc/src/VcpkgPaths.cpp
@@ -269,7 +269,7 @@ namespace vcpkg
return nullopt;
}
- static Toolset find_toolset_instance(const VcpkgPaths& paths)
+ static std::vector<Toolset> find_toolset_instances(const VcpkgPaths& paths)
{
const auto& fs = paths.get_filesystem();
@@ -277,7 +277,28 @@ namespace vcpkg
// Note: this will contain a mix of vcvarsall.bat locations and dumpbin.exe locations.
std::vector<fs::path> paths_examined;
+ std::vector<Toolset> found_toolsets;
+
+ // VS2015
+ const Optional<fs::path> vs_2015_installation_instance = get_VS2015_installation_instance();
+ if (auto v = vs_2015_installation_instance.get())
+ {
+ const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat";
+
+ paths_examined.push_back(vs2015_vcvarsall_bat);
+ if (fs.exists(vs2015_vcvarsall_bat))
+ {
+ const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe";
+ paths_examined.push_back(vs2015_dumpbin_exe);
+ if (fs.exists(vs2015_dumpbin_exe))
+ {
+ found_toolsets.push_back({vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"});
+ }
+ }
+ }
+
// VS2017
+ Optional<Toolset> vs2017_toolset;
for (const fs::path& instance : vs2017_installation_instances)
{
const fs::path vc_dir = instance / "VC";
@@ -303,41 +324,50 @@ namespace vcpkg
paths_examined.push_back(dumpbin_path);
if (fs.exists(dumpbin_path))
{
- return {dumpbin_path, vcvarsall_bat, L"v141"};
+ vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, L"v141"};
+ break;
}
}
+ if (auto value = vs2017_toolset.get())
+ {
+ found_toolsets.push_back(*value);
+ break;
+ }
}
- // VS2015
- const Optional<fs::path> vs_2015_installation_instance = get_VS2015_installation_instance();
- if (auto v = vs_2015_installation_instance.get())
+ if (found_toolsets.empty())
{
- const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat";
-
- paths_examined.push_back(vs2015_vcvarsall_bat);
- if (fs.exists(vs2015_vcvarsall_bat))
+ System::println(System::Color::error, "Could not locate a complete toolset.");
+ System::println("The following paths were examined:");
+ for (const fs::path& path : paths_examined)
{
- const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe";
- paths_examined.push_back(vs2015_dumpbin_exe);
- if (fs.exists(vs2015_dumpbin_exe))
- {
- return {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"};
- }
+ System::println(" %s", path.u8string());
}
+ Checks::exit_fail(VCPKG_LINE_INFO);
}
- System::println(System::Color::error, "Could not locate a complete toolset.");
- System::println("The following paths were examined:");
- for (const fs::path& path : paths_examined)
- {
- System::println(" %s", path.u8string());
- }
- Checks::exit_fail(VCPKG_LINE_INFO);
+ return found_toolsets;
}
- const Toolset& VcpkgPaths::get_toolset() const
+ const Toolset& VcpkgPaths::get_toolset(const std::string& toolset_version) const
{
- return this->toolset.get_lazy([this]() { return find_toolset_instance(*this); });
+ // Invariant: toolsets are non-empty and sorted with newest at back()
+ const auto& vs_toolsets = this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
+
+ if (toolset_version.empty())
+ {
+ return vs_toolsets.back();
+ }
+ else
+ {
+ const auto toolset = Util::find_if(vs_toolsets, [&](const Toolset& toolset) {
+ return toolset_version == Strings::to_utf8(toolset.version);
+ });
+ Checks::check_exit(
+ VCPKG_LINE_INFO, toolset != vs_toolsets.end(), "Could not find toolset '%s'", toolset_version);
+ return *toolset;
+ }
}
+
Files::Filesystem& VcpkgPaths::get_filesystem() const { return Files::get_real_filesystem(); }
}