mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-28 08:59:07 +08:00
Add checks for outdated crts
This commit is contained in:
parent
22f681c82d
commit
eb7ca47d48
@ -36,11 +36,6 @@ namespace vcpkg
|
||||
static const BuildType RELEASE_STATIC;
|
||||
static const BuildType RELEASE_DYNAMIC;
|
||||
|
||||
static constexpr int length()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
static const std::vector<BuildType>& values()
|
||||
{
|
||||
static const std::vector<BuildType> v = {DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC};
|
||||
@ -69,6 +64,43 @@ namespace vcpkg
|
||||
|
||||
bool operator !=(const BuildType& lhs, const BuildType& rhs);
|
||||
|
||||
struct OutdatedDynamicCrt
|
||||
{
|
||||
static const OutdatedDynamicCrt MSVCP100_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP100D_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP110_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP110_WIN_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP120_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP120_CLR0400_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP60_DLL;
|
||||
static const OutdatedDynamicCrt MSVCP_WIN_DLL;
|
||||
|
||||
static const std::vector<OutdatedDynamicCrt>& values()
|
||||
{
|
||||
static const std::vector<OutdatedDynamicCrt> v = {
|
||||
MSVCP100_DLL, MSVCP100D_DLL,
|
||||
MSVCP110_DLL,MSVCP110_WIN_DLL,
|
||||
MSVCP120_DLL, MSVCP120_CLR0400_DLL,
|
||||
MSVCP60_DLL, MSVCP_WIN_DLL
|
||||
};
|
||||
return v;
|
||||
}
|
||||
|
||||
OutdatedDynamicCrt() = delete;
|
||||
|
||||
const std::regex& crt_regex() const;
|
||||
const std::string& toString() const;
|
||||
|
||||
private:
|
||||
explicit OutdatedDynamicCrt(const std::string& dll_name, const std::string& crt_regex_as_string)
|
||||
: m_dll_name(dll_name), m_crt_regex_as_string(crt_regex_as_string)
|
||||
{
|
||||
}
|
||||
|
||||
std::string m_dll_name;
|
||||
std::string m_crt_regex_as_string;
|
||||
};
|
||||
|
||||
struct BuildInfo
|
||||
{
|
||||
static BuildInfo create(const std::unordered_map<std::string, std::string>& pgh);
|
||||
|
@ -87,7 +87,6 @@ namespace vcpkg
|
||||
}
|
||||
|
||||
std::string to_string(const ConfigurationType& conf)
|
||||
|
||||
{
|
||||
switch (conf)
|
||||
{
|
||||
@ -132,4 +131,24 @@ namespace vcpkg
|
||||
|
||||
return BuildInfo::create(pghs[0]);
|
||||
}
|
||||
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");
|
||||
const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");;
|
||||
|
||||
const std::regex& OutdatedDynamicCrt::crt_regex() const
|
||||
{
|
||||
static const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase);
|
||||
return r;
|
||||
}
|
||||
|
||||
const std::string& OutdatedDynamicCrt::toString() const
|
||||
{
|
||||
return this->m_dll_name;
|
||||
}
|
||||
}
|
||||
|
@ -535,6 +535,51 @@ namespace vcpkg
|
||||
return lint_status::SUCCESS;
|
||||
}
|
||||
|
||||
struct OutdatedDynamicCrt_and_file
|
||||
{
|
||||
fs::path file;
|
||||
OutdatedDynamicCrt outdated_crt;
|
||||
};
|
||||
|
||||
static lint_status check_outdated_crt_linkage_of_dlls(const std::vector<fs::path>& dlls)
|
||||
{
|
||||
const std::vector<OutdatedDynamicCrt> outdated_crts = OutdatedDynamicCrt::values();
|
||||
|
||||
std::vector<OutdatedDynamicCrt_and_file> dlls_with_outdated_crt;
|
||||
|
||||
for (const fs::path& dll : dlls)
|
||||
{
|
||||
const std::wstring cmd_line = Strings::wformat(LR"("%s" /dependents "%s")", DUMPBIN_EXE.native(), dll.native());
|
||||
System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line);
|
||||
Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line));
|
||||
|
||||
for (const OutdatedDynamicCrt& outdated_crt : outdated_crts)
|
||||
{
|
||||
if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.crt_regex()))
|
||||
{
|
||||
dlls_with_outdated_crt.push_back({dll, outdated_crt});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!dlls_with_outdated_crt.empty())
|
||||
{
|
||||
System::println(System::color::warning, "Detected outdated dynamic CRT in the following files:");
|
||||
System::println("");
|
||||
for (const OutdatedDynamicCrt_and_file btf : dlls_with_outdated_crt)
|
||||
{
|
||||
System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.toString());
|
||||
}
|
||||
System::println("");
|
||||
|
||||
System::println(System::color::warning, "To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll");
|
||||
return lint_status::ERROR_DETECTED;
|
||||
}
|
||||
|
||||
return lint_status::SUCCESS;
|
||||
}
|
||||
|
||||
static void operator +=(size_t& left, const lint_status& right)
|
||||
{
|
||||
left += static_cast<size_t>(right);
|
||||
@ -584,6 +629,8 @@ namespace vcpkg
|
||||
error_count += check_exports_of_dlls(dlls);
|
||||
error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls);
|
||||
error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls);
|
||||
|
||||
error_count += check_outdated_crt_linkage_of_dlls(dlls);
|
||||
break;
|
||||
}
|
||||
case LinkageType::STATIC:
|
||||
|
Loading…
Reference in New Issue
Block a user