windeployqt: improve MSVC runtime detection

MSVC runtime dlls also include vccorelibXXX.dll, concrtXXX.dll,
beside these traditional dlls, it's also possible to link against
the new UCRT runtime, the ucrtbase.dll (and possibly including
the API Set dlls), so we need to add some more checks to make
windeployqt more robust. I've tested a custom Qt build locally,
which I managed to make it link to ucrtbase.dll only, and this
code works fine.

Pick-to: 6.6
Change-Id: I00bc8666d8850aac279b8747465879e39348ba02
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Timothée Keller <timothee.keller@qt.io>
This commit is contained in:
Yuhang Zhao 2023-10-23 13:10:44 +08:00
parent c5b3fd134b
commit 8842391e5c

View File

@ -673,13 +673,23 @@ static inline MsvcDebugRuntimeResult checkMsvcDebugRuntime(const QStringList &de
qsizetype pos = 0;
if (lib.startsWith("MSVCR"_L1, Qt::CaseInsensitive)
|| lib.startsWith("MSVCP"_L1, Qt::CaseInsensitive)
|| lib.startsWith("VCRUNTIME"_L1, Qt::CaseInsensitive)) {
|| lib.startsWith("VCRUNTIME"_L1, Qt::CaseInsensitive)
|| lib.startsWith("VCCORLIB"_L1, Qt::CaseInsensitive)
|| lib.startsWith("CONCRT"_L1, Qt::CaseInsensitive)
|| lib.startsWith("UCRTBASE"_L1, Qt::CaseInsensitive)) {
qsizetype lastDotPos = lib.lastIndexOf(u'.');
pos = -1 == lastDotPos ? 0 : lastDotPos - 1;
}
if (pos > 0 && lib.contains("_app"_L1, Qt::CaseInsensitive))
pos -= 4;
if (pos > 0) {
const auto removeExtraSuffix = [&lib, &pos](const QString &suffix) -> void {
if (lib.contains(suffix, Qt::CaseInsensitive))
pos -= suffix.size();
};
removeExtraSuffix("_app"_L1);
removeExtraSuffix("_atomic_wait"_L1);
removeExtraSuffix("_codecvt_ids"_L1);
}
if (pos)
return lib.at(pos).toLower() == u'd' ? MsvcDebugRuntime : MsvcReleaseRuntime;