From 4e74bb48234f41c9d6306c7a3cd6835c2cd42348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 3 Aug 2020 18:03:12 +0200 Subject: [PATCH] Resolve SDK and deployment target OS from load command Pick-to: 5.15 Pick-to: 5.12 Change-Id: Icce79186645f173b7f9be8ee6da0abed25cf3da0 Reviewed-by: Alexandru Croitor --- src/corelib/kernel/qcore_mac.mm | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index b94b06adb4..692c9fa6b5 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -566,12 +566,30 @@ QOperatingSystemVersion QMacVersion::currentRuntime() QMacVersion::VersionTuple QMacVersion::versionsForImage(const mach_header *machHeader) { - static auto makeVersionTuple = [](uint32_t dt, uint32_t sdk) { + static auto osForLoadCommand = [](uint32_t cmd) { + switch (cmd) { + case LC_VERSION_MIN_MACOSX: return QOperatingSystemVersion::MacOS; + case LC_VERSION_MIN_IPHONEOS: return QOperatingSystemVersion::IOS; + case LC_VERSION_MIN_TVOS: return QOperatingSystemVersion::TvOS; + case LC_VERSION_MIN_WATCHOS: return QOperatingSystemVersion::WatchOS; + default: return QOperatingSystemVersion::Unknown; + } + }; + + static auto osForPlatform = [](uint32_t platform) { + switch (platform) { + case 1: return QOperatingSystemVersion::MacOS; + case 2: return QOperatingSystemVersion::IOS; + case 3: return QOperatingSystemVersion::TvOS; + case 4: return QOperatingSystemVersion::WatchOS; + default: return QOperatingSystemVersion::Unknown; + } + }; + + static auto makeVersionTuple = [](uint32_t dt, uint32_t sdk, QOperatingSystemVersion::OSType osType) { return qMakePair( - QOperatingSystemVersion(QOperatingSystemVersion::currentType(), - dt >> 16 & 0xffff, dt >> 8 & 0xff, dt & 0xff), - QOperatingSystemVersion(QOperatingSystemVersion::currentType(), - sdk >> 16 & 0xffff, sdk >> 8 & 0xff, sdk & 0xff) + QOperatingSystemVersion(osType, dt >> 16 & 0xffff, dt >> 8 & 0xff, dt & 0xff), + QOperatingSystemVersion(osType, sdk >> 16 & 0xffff, sdk >> 8 & 0xff, sdk & 0xff) ); }; @@ -581,11 +599,11 @@ QMacVersion::VersionTuple QMacVersion::versionsForImage(const mach_header *machH if (loadCommand->cmd == LC_VERSION_MIN_MACOSX || loadCommand->cmd == LC_VERSION_MIN_IPHONEOS || loadCommand->cmd == LC_VERSION_MIN_TVOS || loadCommand->cmd == LC_VERSION_MIN_WATCHOS) { auto versionCommand = reinterpret_cast(loadCommand); - return makeVersionTuple(versionCommand->version, versionCommand->sdk); + return makeVersionTuple(versionCommand->version, versionCommand->sdk, osForLoadCommand(loadCommand->cmd)); #if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13, __IPHONE_11_0, __TVOS_11_0, __WATCHOS_4_0) } else if (loadCommand->cmd == LC_BUILD_VERSION) { auto versionCommand = reinterpret_cast(loadCommand); - return makeVersionTuple(versionCommand->minos, versionCommand->sdk); + return makeVersionTuple(versionCommand->minos, versionCommand->sdk, osForPlatform(versionCommand->platform)); #endif } commandCursor += loadCommand->cmdsize;