From 1253b875195590e528d8a28e12a798264603ba43 Mon Sep 17 00:00:00 2001 From: Albert Ziegenhagel Date: Fri, 2 Jun 2017 18:13:12 +0200 Subject: Implement support to request a specific toolset version via the variable `VCPKG_PLATFORM_TOOLSET` in the triplet file --- toolsrc/src/VcpkgPaths.cpp | 63 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'toolsrc/src/VcpkgPaths.cpp') diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp index 3dd32de01..acd847b5f 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 find_toolset_instances(const VcpkgPaths& paths) { const auto& fs = paths.get_filesystem(); @@ -277,7 +277,10 @@ namespace vcpkg // Note: this will contain a mix of vcvarsall.bat locations and dumpbin.exe locations. std::vector paths_examined; + std::vector found_toolsets; + // VS2017 + Optional vs2017_toolset; for (const fs::path& instance : vs2017_installation_instances) { const fs::path vc_dir = instance / "VC"; @@ -303,9 +306,15 @@ 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(vs2017_toolset) break; + } + if(auto value = vs2017_toolset.get()) + { + found_toolsets.push_back(*value); } // VS2015 @@ -321,23 +330,57 @@ namespace vcpkg paths_examined.push_back(vs2015_dumpbin_exe); if (fs.exists(vs2015_dumpbin_exe)) { - return {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"}; + found_toolsets.push_back({vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"}); } } } - 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) + std::sort(found_toolsets.begin(), + found_toolsets.end(), + [](const Toolset& left, const Toolset& right) { return left.version > right.version; }); + + if(found_toolsets.empty()) { - System::println(" %s", path.u8string()); + 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); } - Checks::exit_fail(VCPKG_LINE_INFO); + + return found_toolsets; + } + + const std::vector& VcpkgPaths::get_toolsets() const + { + return this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); }); } - const Toolset& VcpkgPaths::get_toolset() const + const Toolset& VcpkgPaths::get_latest_toolset() const { - return this->toolset.get_lazy([this]() { return find_toolset_instance(*this); }); + // Invariant: toolsets are non-empty and sorted + return get_toolsets().back(); } + const Toolset& VcpkgPaths::get_toolset(const std::string& toolset_version) const + { + if(toolset_version.empty()) + { + return this->get_latest_toolset(); + } + else + { + const auto& vs_toolsets = this->get_toolsets(); + + const auto toolset = Util::find_if(vs_toolsets, [&](const Toolset& toolset) { return toolset_version == Strings::to_utf8(toolset.version); }); + if(toolset == vs_toolsets.end()) + { + Checks::exit_with_message(VCPKG_LINE_INFO, Strings::format("Could not find toolset %s", toolset_version)); + } + return *toolset; + } + } + Files::Filesystem& VcpkgPaths::get_filesystem() const { return Files::get_real_filesystem(); } } -- cgit v1.2.3 From 60825eed0e8b8c7646d0e66bc2743b4a1e8e4a96 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Mon, 5 Jun 2017 22:01:41 -0700 Subject: [vcpkg] Formatting and simplification of VcpkgPaths::get_toolset() --- toolsrc/src/VcpkgPaths.cpp | 79 +++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 46 deletions(-) (limited to 'toolsrc/src/VcpkgPaths.cpp') diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp index acd847b5f..9068e3903 100644 --- a/toolsrc/src/VcpkgPaths.cpp +++ b/toolsrc/src/VcpkgPaths.cpp @@ -279,6 +279,24 @@ namespace vcpkg std::vector found_toolsets; + // VS2015 + const Optional 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 vs2017_toolset; for (const fs::path& instance : vs2017_installation_instances) @@ -310,40 +328,18 @@ namespace vcpkg break; } } - if(vs2017_toolset) break; - } - if(auto value = vs2017_toolset.get()) - { - found_toolsets.push_back(*value); - } - - // VS2015 - const Optional 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)) + if (auto value = vs2017_toolset.get()) { - 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"}); - } + found_toolsets.push_back(*value); + break; } } - std::sort(found_toolsets.begin(), - found_toolsets.end(), - [](const Toolset& left, const Toolset& right) { return left.version > right.version; }); - - if(found_toolsets.empty()) + if (found_toolsets.empty()) { 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) + for (const fs::path& path : paths_examined) { System::println(" %s", path.u8string()); } @@ -353,31 +349,22 @@ namespace vcpkg return found_toolsets; } - const std::vector& VcpkgPaths::get_toolsets() const - { - return this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); }); - } - - const Toolset& VcpkgPaths::get_latest_toolset() const - { - // Invariant: toolsets are non-empty and sorted - return get_toolsets().back(); - } const Toolset& VcpkgPaths::get_toolset(const std::string& toolset_version) const { - if(toolset_version.empty()) + // 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 this->get_latest_toolset(); + return vs_toolsets.back(); } else { - const auto& vs_toolsets = this->get_toolsets(); - - const auto toolset = Util::find_if(vs_toolsets, [&](const Toolset& toolset) { return toolset_version == Strings::to_utf8(toolset.version); }); - if(toolset == vs_toolsets.end()) - { - Checks::exit_with_message(VCPKG_LINE_INFO, Strings::format("Could not find toolset %s", toolset_version)); - } + 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; } } -- cgit v1.2.3