[vcpkg] Merge search for dumpbin and toolchain (they are the same).
MODIFY
include/cstring_view.h
include/cstring_view.h
@@ -6,6 +6,7 @@ namespace vcpkg
template<class CharType>
struct basic_cstring_view
{
+ constexpr basic_cstring_view() : cstr(nullptr) {}
constexpr basic_cstring_view(const CharType* cstr) : cstr(cstr) {}
basic_cstring_view(const std::basic_string<CharType>& str) : cstr(str.c_str()) {}

MODIFY
include/vcpkg_paths.h
include/vcpkg_paths.h
namespace vcpkg
{
- struct vcvarsall_and_platform_toolset
+ struct toolset_t
{
- fs::path path;
- std::wstring platform_toolset;
+ fs::path dumpbin;
+ fs::path vcvarsall;
+ cwstring_view version;
};
struct vcpkg_paths
@@ -46,12 +47,12 @@ namespace vcpkg
const fs::path& get_cmake_exe() const;
const fs::path& get_git_exe() const;
const fs::path& get_nuget_exe() const;
- const fs::path& get_dumpbin_exe() const;
- const vcvarsall_and_platform_toolset& get_vcvarsall_bat() const;
+ const toolset_t& get_toolset() const;
private:
lazy<fs::path> cmake_exe;
lazy<fs::path> git_exe;
lazy<fs::path> nuget_exe;
+ lazy<toolset_t> toolset;
};
}

MODIFY
src/PostBuildLint.cpp
src/PostBuildLint.cpp
@@ -621,7 +621,8 @@ namespace vcpkg::PostBuildLint
static size_t perform_all_checks_and_return_error_count(const package_spec& spec, const vcpkg_paths& paths)
{
- const fs::path dumpbin_exe = paths.get_dumpbin_exe();
+ // for dumpbin
+ const toolset_t& toolset = paths.get_toolset();
BuildInfo build_info = read_build_info(paths.build_info_file_path(spec));
const fs::path package_dir = paths.package_dir(spec);
@@ -675,11 +676,11 @@ namespace vcpkg::PostBuildLint
dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend());
dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend());
- error_count += check_exports_of_dlls(dlls, dumpbin_exe);
- error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe);
+ error_count += check_exports_of_dlls(dlls, toolset.dumpbin);
+ error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, toolset.dumpbin);
error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls);
- error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe);
+ error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin);
break;
}
case LinkageType::backing_enum_t::STATIC:
@@ -692,9 +693,9 @@ namespace vcpkg::PostBuildLint
if (!contains_and_enabled(build_info.policies, BuildPolicies::ONLY_RELEASE_CRT))
{
- error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage), debug_libs, dumpbin_exe);
+ error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage), debug_libs, toolset.dumpbin);
}
- error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage), release_libs, dumpbin_exe);
+ error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage), release_libs, toolset.dumpbin);
break;
}
case LinkageType::backing_enum_t::NULLVALUE:

MODIFY
src/commands_build.cpp
src/commands_build.cpp
@@ -42,8 +42,8 @@ namespace vcpkg::Commands::Build
const fs::path& git_exe_path = paths.get_git_exe();
const fs::path ports_cmake_script_path = paths.ports_cmake;
- const vcvarsall_and_platform_toolset vcvarsall_bat = paths.get_vcvarsall_bat();
- const std::wstring cmd_set_environment = Strings::wformat(LR"("%s" %s >nul 2>&1)", vcvarsall_bat.path.native(), Strings::utf8_to_utf16(target_triplet.architecture()));
+ const toolset_t& toolset = paths.get_toolset();
+ const std::wstring cmd_set_environment = Strings::wformat(LR"("%s" %s >nul 2>&1)", toolset.vcvarsall.native(), Strings::utf8_to_utf16(target_triplet.architecture()));
const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path, ports_cmake_script_path,
{
@@ -51,7 +51,7 @@ namespace vcpkg::Commands::Build
{ L"PORT", source_paragraph.name },
{ L"CURRENT_PORT_DIR", port_dir / "/." },
{ L"TARGET_TRIPLET", target_triplet.canonical_name() },
- { L"VCPKG_PLATFORM_TOOLSET", vcvarsall_bat.platform_toolset },
+ { L"VCPKG_PLATFORM_TOOLSET", toolset.version },
{ L"GIT", git_exe_path }
});

MODIFY
src/vcpkg_paths.cpp
src/vcpkg_paths.cpp
@@ -269,23 +269,33 @@ namespace vcpkg
return vs2015_path;
}
- static fs::path find_dumpbin_exe(const vcpkg_paths& paths)
+ static toolset_t find_toolset_instance(const vcpkg_paths& paths)
{
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;
// VS2017
- for (const std::string& instance : vs2017_installation_instances)
+ for (const fs::path& instance : vs2017_installation_instances)
{
- const fs::path msvc_path = Strings::format(R"(%s\VC\Tools\MSVC)", instance);
+ const fs::path vc_dir = instance / "VC";
+
+ // Skip any instances that do not have vcvarsall.
+ const fs::path vcvarsall_bat = vc_dir / "Auxiliary" / "Build" / "vcvarsall.bat";
+ paths_examined.push_back(vcvarsall_bat);
+ if (!fs::exists(vcvarsall_bat))
+ continue;
+
+ // Locate the "best" MSVC toolchain version
+ const fs::path msvc_path = vc_dir / "Tools" / "MSVC";
std::vector<fs::path> msvc_subdirectories;
- Files::non_recursive_find_matching_paths_in_dir(msvc_path, [&](const fs::path& current)
+ Files::non_recursive_find_matching_paths_in_dir(msvc_path, [](const fs::path& current)
{
return fs::is_directory(current);
}, &msvc_subdirectories);
// Sort them so that latest comes first
- std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [&](const fs::path& left, const fs::path& right)
+ std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [](const fs::path& left, const fs::path& right)
{
return left.filename() > right.filename();
});
@@ -296,51 +306,8 @@ namespace vcpkg
paths_examined.push_back(dumpbin_path);
if (fs::exists(dumpbin_path))
{
- return dumpbin_path;
- }
- }
- }
-
- // 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_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe";
- paths_examined.push_back(vs2015_dumpbin_exe);
- if (fs::exists(vs2015_dumpbin_exe))
- {
- return vs2015_dumpbin_exe;
- }
- }
-
- System::println(System::color::error, "Could not detect dumpbin.exe.");
- System::println("The following paths were examined:");
- for (const fs::path& path : paths_examined)
- {
- System::println(" %s", path.generic_string());
+ return { dumpbin_path, vcvarsall_bat , L"v141" };
}
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
-
- const fs::path& vcpkg_paths::get_dumpbin_exe() const
- {
- static const fs::path dumpbin_exe = find_dumpbin_exe(*this);
- return dumpbin_exe;
- }
-
- static vcvarsall_and_platform_toolset find_vcvarsall_bat(const vcpkg_paths& paths)
- {
- const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths);
- std::vector<fs::path> paths_examined;
-
- // VS2017
- for (const fs::path& instance : vs2017_installation_instances)
- {
- const fs::path vcvarsall_bat = instance / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat";
- paths_examined.push_back(vcvarsall_bat);
- if (fs::exists(vcvarsall_bat))
- {
- return { vcvarsall_bat , L"v141" };
}
}
@@ -353,22 +320,26 @@ namespace vcpkg
paths_examined.push_back(vs2015_vcvarsall_bat);
if (fs::exists(vs2015_vcvarsall_bat))
{
- return { vs2015_vcvarsall_bat, L"v140" };
+ 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(System::color::error, "Could not detect 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)
{
- System::println(" %s", path.generic_string());
+ System::println(" %s", path.u8string());
}
Checks::exit_fail(VCPKG_LINE_INFO);
}
- const vcvarsall_and_platform_toolset& vcpkg_paths::get_vcvarsall_bat() const
+ const toolset_t& vcpkg_paths::get_toolset() const
{
- static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(*this);
- return vcvarsall_bat;
+ return this->toolset.get_lazy([this]() { return find_toolset_instance(*this); });
}
}

[vcpkg] Merge search for dumpbin and toolchain (they are the same).