aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/VcpkgPaths.cpp
diff options
context:
space:
mode:
authorjasjuang <jasjuang@gmail.com>2017-09-27 22:21:17 -0700
committerjasjuang <jasjuang@gmail.com>2017-09-27 22:21:17 -0700
commit7e6da0c9e7cd4cfea6c88ca661d509e6f15a1a8c (patch)
tree957a5d0b1130e64ac6428b06e8758237cbafe5f4 /toolsrc/src/VcpkgPaths.cpp
parent050a8bf6179ed046508b8a97e62894475a46dfbc (diff)
parent0ccea4f3677d92a20935e03c2cb301d8300b43d1 (diff)
downloadvcpkg-7e6da0c9e7cd4cfea6c88ca661d509e6f15a1a8c.tar.gz
vcpkg-7e6da0c9e7cd4cfea6c88ca661d509e6f15a1a8c.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'toolsrc/src/VcpkgPaths.cpp')
-rw-r--r--toolsrc/src/VcpkgPaths.cpp114
1 files changed, 79 insertions, 35 deletions
diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp
index 02e238b3f..8892207bd 100644
--- a/toolsrc/src/VcpkgPaths.cpp
+++ b/toolsrc/src/VcpkgPaths.cpp
@@ -10,6 +10,10 @@
namespace vcpkg
{
+ // Intentionally wstring so we can easily use operator== with CWStringView.
+ static const std::wstring V_140 = L"v140";
+ static const std::wstring V_141 = L"v141";
+
static bool exists_and_has_equal_or_greater_version(const std::wstring& version_cmd,
const std::array<int, 3>& expected_version)
{
@@ -269,13 +273,31 @@ namespace vcpkg
return nullopt;
}
- static std::vector<Toolset> find_toolset_instances(const VcpkgPaths& paths)
+ static std::vector<ToolsetArchOption> detect_supported_architectures(const Files::Filesystem& fs,
+ const fs::path& vcvarsall_dir)
{
using CPU = System::CPUArchitecture;
+ std::vector<ToolsetArchOption> supported_architectures;
+
+ if (fs.exists(vcvarsall_dir / "vcvars32.bat")) supported_architectures.push_back({L"x86", CPU::X86, CPU::X86});
+ if (fs.exists(vcvarsall_dir / "vcvars64.bat"))
+ supported_architectures.push_back({L"amd64", CPU::X64, CPU::X64});
+ if (fs.exists(vcvarsall_dir / "vcvarsx86_amd64.bat"))
+ supported_architectures.push_back({L"x86_amd64", CPU::X86, CPU::X64});
+ if (fs.exists(vcvarsall_dir / "vcvarsx86_arm.bat"))
+ supported_architectures.push_back({L"x86_arm", CPU::X86, CPU::ARM});
+ if (fs.exists(vcvarsall_dir / "vcvarsamd64_x86.bat"))
+ supported_architectures.push_back({L"amd64_x86", CPU::X64, CPU::X86});
+ if (fs.exists(vcvarsall_dir / "vcvarsamd64_arm.bat"))
+ supported_architectures.push_back({L"amd64_arm", CPU::X64, CPU::ARM});
+
+ return supported_architectures;
+ }
+ static std::vector<Toolset> find_toolset_instances(const VcpkgPaths& paths)
+ {
const auto& fs = paths.get_filesystem();
- const std::vector<std::string> vs2017_installation_instances = get_vs2017_installation_instances(paths);
// Note: this will contain a mix of vcvarsall.bat locations and dumpbin.exe locations.
std::vector<fs::path> paths_examined;
@@ -294,28 +316,19 @@ namespace vcpkg
paths_examined.push_back(vs2015_dumpbin_exe);
const fs::path vs2015_bin_dir = vs2015_vcvarsall_bat.parent_path() / "bin";
- std::vector<ToolsetArchOption> supported_architectures;
- if (fs.exists(vs2015_bin_dir / "vcvars32.bat"))
- supported_architectures.push_back({L"x86", CPU::X86, CPU::X86});
- if (fs.exists(vs2015_bin_dir / "amd64\\vcvars64.bat"))
- supported_architectures.push_back({L"x64", CPU::X64, CPU::X64});
- if (fs.exists(vs2015_bin_dir / "x86_amd64\\vcvarsx86_amd64.bat"))
- supported_architectures.push_back({L"x86_amd64", CPU::X86, CPU::X64});
- if (fs.exists(vs2015_bin_dir / "x86_arm\\vcvarsx86_arm.bat"))
- supported_architectures.push_back({L"x86_arm", CPU::X86, CPU::ARM});
- if (fs.exists(vs2015_bin_dir / "amd64_x86\\vcvarsamd64_x86.bat"))
- supported_architectures.push_back({L"amd64_x86", CPU::X64, CPU::X86});
- if (fs.exists(vs2015_bin_dir / "amd64_arm\\vcvarsamd64_arm.bat"))
- supported_architectures.push_back({L"amd64_arm", CPU::X64, CPU::ARM});
+ const std::vector<ToolsetArchOption> supported_architectures =
+ detect_supported_architectures(fs, vs2015_bin_dir);
if (fs.exists(vs2015_dumpbin_exe))
{
found_toolsets.push_back(
- {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140", supported_architectures});
+ {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, {}, V_140, supported_architectures});
}
}
}
+ const std::vector<std::string> vs2017_installation_instances = get_vs2017_installation_instances(paths);
+
// VS2017
Optional<Toolset> vs2017_toolset;
for (const std::string& instance : vs2017_installation_instances)
@@ -329,19 +342,8 @@ namespace vcpkg
if (!fs.exists(vcvarsall_bat)) continue;
// Get all supported architectures
- std::vector<ToolsetArchOption> supported_architectures;
- if (fs.exists(vcvarsall_dir / "vcvars32.bat"))
- supported_architectures.push_back({L"x86", CPU::X86, CPU::X86});
- if (fs.exists(vcvarsall_dir / "vcvars64.bat"))
- supported_architectures.push_back({L"amd64", CPU::X64, CPU::X64});
- if (fs.exists(vcvarsall_dir / "vcvarsx86_amd64.bat"))
- supported_architectures.push_back({L"x86_amd64", CPU::X86, CPU::X64});
- if (fs.exists(vcvarsall_dir / "vcvarsx86_arm.bat"))
- supported_architectures.push_back({L"x86_arm", CPU::X86, CPU::ARM});
- if (fs.exists(vcvarsall_dir / "vcvarsamd64_x86.bat"))
- supported_architectures.push_back({L"amd64_x86", CPU::X64, CPU::X86});
- if (fs.exists(vcvarsall_dir / "vcvarsamd64_arm.bat"))
- supported_architectures.push_back({L"amd64_arm", CPU::X64, CPU::ARM});
+ const std::vector<ToolsetArchOption> supported_architectures =
+ detect_supported_architectures(fs, vcvarsall_dir);
// Locate the "best" MSVC toolchain version
const fs::path msvc_path = vc_dir / "Tools" / "MSVC";
@@ -359,14 +361,13 @@ namespace vcpkg
paths_examined.push_back(dumpbin_path);
if (fs.exists(dumpbin_path))
{
- vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, L"v141", supported_architectures};
+ vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, {}, V_141, supported_architectures};
break;
}
}
if (const auto value = vs2017_toolset.get())
{
found_toolsets.push_back(*value);
- break;
}
}
@@ -384,20 +385,63 @@ namespace vcpkg
return found_toolsets;
}
+ static std::vector<Toolset> create_vs2017_v140_toolset_instances(const std::vector<Toolset>& vs_toolsets)
+ {
+ std::vector<Toolset> vs2017_v140_toolsets;
+
+ // In constrast to v141 and above, there can only be a single instance of v140 (VS2017 vs VS2015).
+ const auto it = Util::find_if(vs_toolsets, [&](const Toolset& t) { return t.version == V_140; });
+
+ // If v140 is not available, then VS2017 cant use them. Return empty.
+ if (it == vs_toolsets.cend())
+ {
+ return vs2017_v140_toolsets;
+ }
+
+ // If it does exist, then create a matching v140 toolset for each v141 toolset
+ const Toolset v140_toolset = *it;
+ for (const Toolset& toolset : vs_toolsets)
+ {
+ if (toolset.version != V_141)
+ {
+ continue;
+ }
+
+ Toolset t = Toolset{
+ toolset.dumpbin, toolset.vcvarsall, {L"-vcvars_ver=14.0"}, V_140, toolset.supported_architectures};
+ vs2017_v140_toolsets.push_back(std::move(t));
+ }
+
+ return vs2017_v140_toolsets;
+ }
+
const Toolset& VcpkgPaths::get_toolset(const std::string& toolset_version) const
{
+ const std::wstring& w_toolset_version = Strings::to_utf16(toolset_version);
+
// 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); });
+ const std::vector<Toolset>& vs_toolsets =
+ this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
- if (toolset_version.empty())
+ if (w_toolset_version.empty())
{
return vs_toolsets.back();
}
- const auto toolset = Util::find_if(
- vs_toolsets, [&](const Toolset& t) { return toolset_version == Strings::to_utf8(t.version); });
+ const auto toolset =
+ Util::find_if(vs_toolsets, [&](const Toolset& t) { return w_toolset_version == t.version; });
Checks::check_exit(
VCPKG_LINE_INFO, toolset != vs_toolsets.end(), "Could not find toolset '%s'", toolset_version);
+
+ // If v140 is the selected toolset and VS2017 is available, then use VS2017's vcvarsall with the
+ // -vcvars_ver=14.0 option
+ const std::vector<Toolset>& vs2017_v140_toolsets = this->toolsets_vs2017_v140.get_lazy(
+ [&vs_toolsets]() { return create_vs2017_v140_toolset_instances(vs_toolsets); });
+ if (w_toolset_version == V_140 && !vs2017_v140_toolsets.empty())
+ {
+ return vs2017_v140_toolsets.back();
+ }
+
return *toolset;
}