From 56ec3aa56aa20670a018d97304d5cd153c474548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Matysiak?= Date: Mon, 17 Jun 2024 17:20:04 +0200 Subject: [PATCH] Handle VxWorks in QSysInfo Right now VxWorks is not recognized as a known platform in QSysInfo. This leads to issues with classes that depend on it to properly handle the OS specific functionality (like QFileSelector). Solve the issue by adding vxworks-specific implementation of kernelVersion, productType and productVersion. Task-number: QTBUG-115777 Pick-to: 6.7 Change-Id: Ib544d19f604f3f2d1f088f6160dd210cd6743717 Reviewed-by: Thiago Macieira (cherry picked from commit 65b5debe3a22ff47cf77dd25cf1ec85582ca0f6c) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qsysinfo.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/corelib/global/qsysinfo.cpp b/src/corelib/global/qsysinfo.cpp index 79cb76b2366..0ca04154e65 100644 --- a/src/corelib/global/qsysinfo.cpp +++ b/src/corelib/global/qsysinfo.cpp @@ -709,7 +709,8 @@ QString QSysInfo::kernelType() Returns the release version of the operating system kernel. On Windows, it returns the version of the NT kernel. On Unix systems, including Android and \macos, it returns the same as the \c{uname -r} - command would return. + command would return. On VxWorks, it returns the numeric part of the string + reported by kernelVersion(). If the version could not be determined, this function may return an empty string. @@ -724,8 +725,17 @@ QString QSysInfo::kernelVersion() osver.majorVersion(), osver.minorVersion(), osver.microVersion()); #else struct utsname u; - if (uname(&u) == 0) + if (uname(&u) == 0) { +# ifdef Q_OS_VXWORKS + // The string follows the pattern "Core Kernel version: w.x.y.z" + auto versionStr = QByteArrayView(u.kernelversion); + if (auto lastSpace = versionStr.lastIndexOf(' '); lastSpace != -1) { + return QString::fromLatin1(versionStr.sliced(lastSpace + 1)); + } +# else return QString::fromLatin1(u.release); +# endif + } return QString(); #endif } @@ -762,6 +772,8 @@ QString QSysInfo::kernelVersion() \b{Windows note}: this function return "windows" + \b{VxWorks note}: this function return "vxworks" + For other Unix-type systems, this function usually returns "unknown". \sa QFileSelector, kernelType(), kernelVersion(), productVersion(), prettyProductName() @@ -792,6 +804,8 @@ QString QSysInfo::productType() return QStringLiteral("darwin"); #elif defined(Q_OS_WASM) return QStringLiteral("wasm"); +#elif defined(Q_OS_VXWORKS) + return QStringLiteral("vxworks"); #elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX QUnixOSVersion unixOsVersion; @@ -808,7 +822,7 @@ QString QSysInfo::productType() Returns the product version of the operating system in string form. If the version could not be determined, this function returns "unknown". - It will return the Android, iOS, \macos, Windows full-product + It will return the Android, iOS, \macos, VxWorks, Windows full-product versions on those systems. Typical returned values are (note: list not exhaustive): @@ -821,6 +835,7 @@ QString QSysInfo::productType() \li "8.6" (watchOS 8.6) \li "11" (Windows 11) \li "Server 2022" (Windows Server 2022) + \li "24.03" (VxWorks 7 - 24.03) \endlist On Linux systems, it will try to determine the distribution version and will @@ -849,6 +864,12 @@ QString QSysInfo::productVersion() } // fall through +#elif defined(Q_OS_VXWORKS) + utsname u; + if (uname(&u) == 0) + return QString::fromLatin1(u.releaseversion); + // fall through + #elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX QUnixOSVersion unixOsVersion; findUnixOsVersion(unixOsVersion);