diff options
author | Raphael Cotty <raphael.cotty@gmail.com> | 2022-01-27 20:05:44 +0100 |
---|---|---|
committer | Raphaël Cotty <raphael.cotty@gmail.com> | 2022-02-01 06:37:44 +0000 |
commit | 54ec5e8851f0573beb466ddec2e20a1f3c2b7f7a (patch) | |
tree | 5d86286b45d7ccd23d40274554639c1690481328 | |
parent | aa2094761aec16001ac0d19bf85483fdc2c78611 (diff) |
Create Host service and update FileInfo
In order to use PathProbe and BinaryProbe in module providers, the qbs
properties used in the probes will be replaced by the Host and the
FileInfo services.
The new Host service implements these host related properties:
architecture,
os,
platform,
osVersion,
osBuildVersion,
osVersionParts,
osVersionMajor,
osVersionMinor,
osVersionPatch,
nullDevice
The FileInfo service implements these properties:
pathSeparator,
pathListSeparator
Task-number: QBS-1612
Change-Id: Icecde3d82a531a5b143ce150ffd544ee674e6f4d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
-rw-r--r-- | doc/reference/items/probe/path-probe.qdoc | 4 | ||||
-rw-r--r-- | doc/reference/jsextensions/jsextension-fileinfo.qdoc | 15 | ||||
-rw-r--r-- | doc/reference/jsextensions/jsextension-host.qdoc | 139 | ||||
-rw-r--r-- | doc/reference/modules/qbs-module.qdoc | 123 | ||||
-rw-r--r-- | src/lib/corelib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/lib/corelib/corelib.qbs | 1 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/fileinfoextension.cpp | 20 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/host.cpp | 193 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/jsextensions.cpp | 1 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/jsextensions.pri | 1 | ||||
-rw-r--r-- | src/lib/corelib/tools/hostosinfo.h | 22 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs | 2 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-host/host.qbs | 31 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 40 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.h | 1 |
15 files changed, 469 insertions, 125 deletions
diff --git a/doc/reference/items/probe/path-probe.qdoc b/doc/reference/items/probe/path-probe.qdoc index 422ebf520..729f11dde 100644 --- a/doc/reference/items/probe/path-probe.qdoc +++ b/doc/reference/items/probe/path-probe.qdoc @@ -148,7 +148,7 @@ The list of environment variables that contains paths where to search files. Paths in the environment variable should be separated using - \l{qbs::pathListSeparator}{qbs.pathListSeparator}. + \l{pathListSeparator}{FileInfo.pathListSeparator()}. \nodefaultvalue */ @@ -158,7 +158,7 @@ The list of platform environment variables that contains paths where to search files. Paths in the environment variable should be separated using - \l{qbs::pathListSeparator}{qbs.pathListSeparator}. + \l{pathListSeparator}{FileInfo.pathListSeparator()}. \nodefaultvalue */ diff --git a/doc/reference/jsextensions/jsextension-fileinfo.qdoc b/doc/reference/jsextensions/jsextension-fileinfo.qdoc index 021ef8359..cb0eb7c43 100644 --- a/doc/reference/jsextensions/jsextension-fileinfo.qdoc +++ b/doc/reference/jsextensions/jsextension-fileinfo.qdoc @@ -149,4 +149,19 @@ FileInfo.toWindowsSeparators(filePath: string): string \endcode Returns \c filePath with all '/' characters replaced by '\\'. + + \section2 pathListSeparator + \code + FileInfo.pathListSeparator(): string + \endcode + Returns the host operating system separator for a path list that is used in environment + variables or other contexts. + \funsince 1.22 + + \section2 pathSeparator + \code + FileInfo.pathSeparator(): string + \endcode + Returns the host operating system path separator. + \funsince 1.22 */ diff --git a/doc/reference/jsextensions/jsextension-host.qdoc b/doc/reference/jsextensions/jsextension-host.qdoc new file mode 100644 index 000000000..1dda85d17 --- /dev/null +++ b/doc/reference/jsextensions/jsextension-host.qdoc @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2022 Raphaël Cotty <raphael.cotty@gmail.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page jsextension-host.html + \ingroup list-of-builtin-services + + \title Host Service + \brief Provides host information. + + The \c Host service offers various information about the host environment, such as operating + system names, platform name. + + \section1 Available Operations + + \section2 architecture + \code + Host.architecture(): string + \endcode + Returns the host operating system architecture. + + See \l{qbs::architecture}{qbs.architecture} for the target-specific equivalent property. + architecture. + \funsince 1.22 + + \section2 os + \code + Host.os(): string[] + \endcode + Returns the host operating system names. + + See the \l{qbs::targetOS}{qbs.targetOS} for the target-specific equivalent property. + \funsince 1.22 + + \section2 platform + \code + Host.platform(): string[] + \endcode + Returns the host operating system platform. + + See the \l{qbs::targetPlatform}{qbs.targetPlatform} for the target-specific equivalent property. + \funsince 1.22 + + + \section2 osVersion + \code + Host.osVersion(): string + \endcode + Returns the host operating system version. Currently, only defined for Windows and Apple + platforms. + + Consists of two or three numbers separated by dots. For example, \c "10.9" or \c "6.3.9600". + \funsince 1.22 + + \section2 osBuildVersion + \code + Host.osBuildVersion(): string + \endcode + Returns the host operating system build version. Currently, only defined for Windows and Apple + platforms. + + On Windows, this is the 4 or 5 digit Windows build number and is equivalent + to \l{qbs::}{versionPatch}. On Apple platforms, this is a standard build number in the Apple + versioning scheme. For example, \c "13C64". + \funsince 1.22 + + \section2 osVersionParts + \code + Host.osVersionParts(): string[] + \endcode + Returns the host operating system version as a list. + + For example, Windows 8.1 (version 6.3.9600) would correspond to a value of \c[6, 3, 9600]. + \funsince 1.22 + + \section2 osVersionMajor + \code + Host.osVersionMajor(): string[] + \endcode + Returns the host operating system major version. + \funsince 1.22 + + \section2 osVersionMinor + \code + Host.osVersionMinor(): string[] + \endcode + Returns the host operating system minor version. + \funsince 1.22 + + \section2 osVersionPatch + \code + Host.osVersionPatch(): string[] + \endcode + Returns the host operating system patch level. + \funsince 1.22 + + \section2 nullDevice + \code + Host.nullDevice(): string[] + \endcode + Returns the platform-specific file path corresponding to the null device. + \funsince 1.22 +*/ diff --git a/doc/reference/modules/qbs-module.qdoc b/doc/reference/modules/qbs-module.qdoc index b785f101d..06f68cf5f 100644 --- a/doc/reference/modules/qbs-module.qdoc +++ b/doc/reference/modules/qbs-module.qdoc @@ -284,7 +284,7 @@ \sa {Target Platforms} - \defaultvalue \l{qbs::hostPlatform}{hostPlatform} + \defaultvalue \l{platform}{Host.platform()} */ /*! @@ -604,24 +604,6 @@ */ /*! - \qmlproperty string qbs::pathListSeparator - - The platform-specific separator for a path list that is used in environment - variables or other contexts. - - \defaultvalue \c{";"} on Windows, \c{":"} on Unix. -*/ - -/*! - \qmlproperty string qbs::nullDevice - \since Qbs 1.4.2 - - The platform-specific file path corresponding to the null device. - - \defaultvalue \c{"NUL"} on Windows, \c{"/dev/null"} on Unix. -*/ - -/*! \qmlproperty path qbs::shellPath \since Qbs 1.5 @@ -637,109 +619,6 @@ */ /*! - \qmlproperty string qbs::hostArchitecture - \since Qbs 1.16 - - Contains the host OS architecture. - - \defaultvalue Determined automatically. -*/ - -/*! - \qmlproperty stringList qbs::hostOS - - This property is set by \QBS internally and specifies the OS \QBS is running - on. - - The possible values for this property are the values of \l{qbs::}{targetOS}, - even though some of them may not be supported. - - \nodefaultvalue -*/ - -/*! - \qmlproperty string qbs::hostOSVersion - \readonly - \since Qbs 1.2 - - The host operating system version. Currently, only defined for Windows and - Apple platforms. - - Consists of two or three numbers separated by dots. For example, \c "10.9" - or \c "6.3.9600". - - \nodefaultvalue -*/ - -/*! - \qmlproperty string qbs::hostOSBuildVersion - \readonly - \since Qbs 1.2 - - The host operating system's build version. Currently, only defined for - Windows and Apple platforms. - - On Windows, this is the 4 or 5 digit Windows build number and is equivalent - to \l{qbs::}{versionPatch}. On Apple platforms, this is a standard build - number in the Apple versioning scheme. For example, \c "13C64". - - \nodefaultvalue -*/ - -/*! - \qmlproperty int qbs::hostOSVersionMajor - \readonly - \since Qbs 1.2 - - The host operating system major version. - - \defaultvalue \c{hostOSVersionParts[0]} -*/ - -/*! - \qmlproperty int qbs::hostOSVersionMinor - \since Qbs 1.2 - - The host operating system minor version. - - \defaultvalue \c{hostOSVersionParts[1]} -*/ - -/*! - \qmlproperty list qbs::hostOSVersionParts - \readonly - \since Qbs 1.2 - - The host operating system version as a list. - - For example, Windows 8.1 (version 6.3.9600) would correspond to a value of - \c[6, 3, 9600]. - - \defaultvalue \c [] -*/ - -/*! - \qmlproperty int qbs::hostOSVersionPatch - \readonly - \since Qbs 1.2 - - The host operating system patch level. - - \defaultvalue \c{hostOSVersionParts[2]} -*/ - -/*! - \qmlproperty string qbs::hostPlatform - \since Qbs 1.11 - - Contains the host OS platform. - - \sa {qbs::hostArchitecture}{hostArchitecture} - - \defaultvalue Determined automatically. -*/ - -/*! \qmlproperty stringList qbs::targetOS \readonly diff --git a/src/lib/corelib/CMakeLists.txt b/src/lib/corelib/CMakeLists.txt index 28f4f4fdf..a6efd0ff3 100644 --- a/src/lib/corelib/CMakeLists.txt +++ b/src/lib/corelib/CMakeLists.txt @@ -154,6 +154,7 @@ set(JS_EXTENSIONS_SOURCES environmentextension.cpp file.cpp fileinfoextension.cpp + host.cpp jsextensions.cpp jsextensions.h moduleproperties.cpp diff --git a/src/lib/corelib/corelib.qbs b/src/lib/corelib/corelib.qbs index 89e8fb40b..cf3c45cda 100644 --- a/src/lib/corelib/corelib.qbs +++ b/src/lib/corelib/corelib.qbs @@ -232,6 +232,7 @@ QbsLibrary { "environmentextension.cpp", "file.cpp", "fileinfoextension.cpp", + "host.cpp", "jsextensions.cpp", "jsextensions.h", "moduleproperties.cpp", diff --git a/src/lib/corelib/jsextensions/fileinfoextension.cpp b/src/lib/corelib/jsextensions/fileinfoextension.cpp index 038f3db41..a69dbc621 100644 --- a/src/lib/corelib/jsextensions/fileinfoextension.cpp +++ b/src/lib/corelib/jsextensions/fileinfoextension.cpp @@ -84,6 +84,8 @@ public: static QScriptValue js_toNativeSeparators(QScriptContext *context, QScriptEngine *engine); static QScriptValue js_fromNativeSeparators(QScriptContext *context, QScriptEngine *engine); static QScriptValue js_joinPaths(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_pathListSeparator(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_pathSeparator(QScriptContext *context, QScriptEngine *engine); }; QScriptValue FileInfoExtension::js_ctor(QScriptContext *context, QScriptEngine *engine) @@ -281,6 +283,20 @@ QScriptValue FileInfoExtension::js_joinPaths(QScriptContext *context, QScriptEng return engine->toScriptValue(uniqueSeparators(paths.join(QLatin1Char('/')))); } +QScriptValue FileInfoExtension::js_pathListSeparator(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + return QString(HostOsInfo::pathListSeparator()); +} + +QScriptValue FileInfoExtension::js_pathSeparator(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + return QString(HostOsInfo::pathSeparator()); +} + } // namespace Internal } // namespace qbs @@ -322,6 +338,10 @@ void initializeJsExtensionFileInfo(QScriptValue extensionObject) engine->newFunction(FileInfoExtension::js_fromNativeSeparators)); fileInfoObj.setProperty(QStringLiteral("joinPaths"), engine->newFunction(FileInfoExtension::js_joinPaths)); + fileInfoObj.setProperty(QStringLiteral("pathListSeparator"), + engine->newFunction(FileInfoExtension::js_pathListSeparator)); + fileInfoObj.setProperty(QStringLiteral("pathSeparator"), + engine->newFunction(FileInfoExtension::js_pathSeparator)); extensionObject.setProperty(QStringLiteral("FileInfo"), fileInfoObj); } diff --git a/src/lib/corelib/jsextensions/host.cpp b/src/lib/corelib/jsextensions/host.cpp new file mode 100644 index 000000000..dae786383 --- /dev/null +++ b/src/lib/corelib/jsextensions/host.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2022 Raphaël Cotty <raphael.cotty@gmail.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <language/scriptengine.h> +#include <logging/translator.h> +#include <tools/fileinfo.h> + +#include <QtCore/qdir.h> +#include <QtCore/qfileinfo.h> + +#include <QtScript/qscriptable.h> +#include <QtScript/qscriptengine.h> + +namespace qbs { +namespace Internal { + +class Host : public QObject, QScriptable +{ + Q_OBJECT +public: + static QScriptValue js_ctor(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_architecture(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_os(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_platform(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_osVersion(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_osBuildVersion(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_osVersionParts(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_osVersionMajor(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_osVersionMinor(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_osVersionPatch(QScriptContext *context, QScriptEngine *engine); + static QScriptValue js_nullDevice(QScriptContext *context, QScriptEngine *engine); +}; + +static QStringList osList() +{ + QStringList list; + for (const auto &s : HostOsInfo::canonicalOSIdentifiers(HostOsInfo::hostOSIdentifier())) + list.push_back(QString::fromStdString(s)); + return list; +} + +QScriptValue Host::js_ctor(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(engine); + return context->throwError(Tr::tr("'Host' cannot be instantiated.")); +} + +QScriptValue Host::js_architecture(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + + return QString::fromStdString(HostOsInfo::hostOSArchitecture()); +} + +QScriptValue Host::js_os(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + static QStringList host = osList(); + return engine->toScriptValue(host); +} + +QScriptValue Host::js_platform(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + return QString::fromStdString(HostOsInfo::hostOSIdentifier()); +} + +QScriptValue Host::js_osVersion(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static QString osVersion = HostOsInfo::hostOsVersion().toString(); + return osVersion.isNull() ? engine->undefinedValue() : osVersion; +} + +QScriptValue Host::js_osBuildVersion(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static QString osBuildVersion = HostOsInfo::hostOsBuildVersion(); + return osBuildVersion.isNull() ? engine->undefinedValue() : osBuildVersion; +} + +QScriptValue Host::js_osVersionParts(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static QStringList osVersionParts = HostOsInfo::hostOsVersion().toString().split( + QStringLiteral(".")); + return qScriptValueFromSequence(engine, osVersionParts); +} + +QScriptValue Host::js_osVersionMajor(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static int osVersionMajor = HostOsInfo::hostOsVersion().majorVersion(); + return osVersionMajor; +} + +QScriptValue Host::js_osVersionMinor(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static int osVersionMinor = HostOsInfo::hostOsVersion().minorVersion(); + return osVersionMinor; +} + +QScriptValue Host::js_osVersionPatch(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static int osVersionPatch = HostOsInfo::hostOsVersion().patchLevel(); + return osVersionPatch; +} + +QScriptValue Host::js_nullDevice(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(context); + Q_UNUSED(engine); + static QString nullDevice = HostOsInfo::isWindowsHost() ? QStringLiteral("NUL") : + QStringLiteral("/dev/null"); + return nullDevice; +} + +} // namespace Internal +} // namespace qbs + +void initializeJsExtensionHost(QScriptValue extensionObject) +{ + using namespace qbs::Internal; + QScriptEngine *engine = extensionObject.engine(); + QScriptValue hostObj = engine->newQMetaObject(&Host::staticMetaObject, + engine->newFunction(&Host::js_ctor)); + hostObj.setProperty(QStringLiteral("architecture"), engine->newFunction(Host::js_architecture)); + hostObj.setProperty(QStringLiteral("os"), engine->newFunction(Host::js_os)); + hostObj.setProperty(QStringLiteral("platform"), engine->newFunction(Host::js_platform)); + hostObj.setProperty(QStringLiteral("osVersion"), engine->newFunction(Host::js_osVersion)); + hostObj.setProperty(QStringLiteral("osBuildVersion"), engine->newFunction( + Host::js_osBuildVersion)); + hostObj.setProperty(QStringLiteral("osVersionParts"), engine->newFunction( + Host::js_osVersionParts)); + hostObj.setProperty(QStringLiteral("osVersionMajor"), engine->newFunction( + Host::js_osVersionMajor)); + hostObj.setProperty(QStringLiteral("osVersionMinor"), engine->newFunction( + Host::js_osVersionMinor)); + hostObj.setProperty(QStringLiteral("osVersionPatch"), engine->newFunction( + Host::js_osVersionPatch)); + hostObj.setProperty(QStringLiteral("nullDevice"), engine->newFunction(Host::js_nullDevice)); + extensionObject.setProperty(QStringLiteral("Host"), hostObj); +} + +Q_DECLARE_METATYPE(qbs::Internal::Host *) + +#include "host.moc" diff --git a/src/lib/corelib/jsextensions/jsextensions.cpp b/src/lib/corelib/jsextensions/jsextensions.cpp index fc464b44d..30dac8e8b 100644 --- a/src/lib/corelib/jsextensions/jsextensions.cpp +++ b/src/lib/corelib/jsextensions/jsextensions.cpp @@ -57,6 +57,7 @@ static InitializerMap setupMap() ADD_JS_EXTENSION(Environment); ADD_JS_EXTENSION(File); ADD_JS_EXTENSION(FileInfo); + ADD_JS_EXTENSION(Host); ADD_JS_EXTENSION(PkgConfig); ADD_JS_EXTENSION(Process); ADD_JS_EXTENSION(PropertyList); diff --git a/src/lib/corelib/jsextensions/jsextensions.pri b/src/lib/corelib/jsextensions/jsextensions.pri index d77f5a687..0d6ec25b0 100644 --- a/src/lib/corelib/jsextensions/jsextensions.pri +++ b/src/lib/corelib/jsextensions/jsextensions.pri @@ -9,6 +9,7 @@ SOURCES += \ $$PWD/environmentextension.cpp \ $$PWD/file.cpp \ $$PWD/fileinfoextension.cpp \ + $$PWD/host.cpp \ $$PWD/temporarydir.cpp \ $$PWD/textfile.cpp \ $$PWD/binaryfile.cpp \ diff --git a/src/lib/corelib/tools/hostosinfo.h b/src/lib/corelib/tools/hostosinfo.h index 4bfc3e00a..cbb4f8a45 100644 --- a/src/lib/corelib/tools/hostosinfo.h +++ b/src/lib/corelib/tools/hostosinfo.h @@ -98,6 +98,28 @@ public: return v; } + static QString hostOsBuildVersion() { + QString v; + if (HostOsInfo::isWindowsHost()) { + QSettings settings(QStringLiteral("HKEY_LOCAL_MACHINE\\Software\\" + "Microsoft\\Windows NT\\CurrentVersion"), + QSettings::NativeFormat); + v = settings.value(QStringLiteral("CurrentBuildNumber")).toString(); + } else if (HostOsInfo::isMacosHost()) { + QSettings serverSettings(QStringLiteral( + "/System/Library/CoreServices/ServerVersion.plist"), + QSettings::NativeFormat); + v = serverSettings.value(QStringLiteral("ProductBuildVersion")).toString(); + if (v.isNull()) { + QSettings systemSettings(QStringLiteral( + "/System/Library/CoreServices/SystemVersion.plist"), + QSettings::NativeFormat); + v = systemSettings.value(QStringLiteral("ProductBuildVersion")).toString(); + } + } + return v; + } + static bool isWindowsHost() { return hostOs() == HostOsWindows; } static bool isLinuxHost() { return hostOs() == HostOsLinux; } static bool isMacosHost() { return hostOs() == HostOsMacos; } diff --git a/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs b/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs index d63ba2962..0e727d04b 100644 --- a/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs +++ b/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs @@ -39,6 +39,8 @@ Product { output.writeLine(FileInfo.relativePath("/tmp", "/blubb.tar.gz")); output.writeLine(FileInfo.toWindowsSeparators("/tmp/blubb.tar.gz")); output.writeLine(FileInfo.toWindowsSeparators("c:\\tmp\\blubb.tar.gz")); + output.writeLine(FileInfo.pathListSeparator()); + output.writeLine(FileInfo.pathSeparator()); output.close(); }; return [cmd]; diff --git a/tests/auto/blackbox/testdata/jsextensions-host/host.qbs b/tests/auto/blackbox/testdata/jsextensions-host/host.qbs new file mode 100644 index 000000000..08d13b25d --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-host/host.qbs @@ -0,0 +1,31 @@ +import qbs.FileInfo +import qbs.Host +import qbs.TextFile + +Product { + type: ["dummy"] + Rule { + multiplex: true + outputFileTags: "dummy" + prepare: { + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + var output = new TextFile(FileInfo.joinPaths(product.sourceDirectory, "output.txt"), + TextFile.WriteOnly); + output.writeLine("architecture: " +Host.architecture()); + output.writeLine("os: " + Host.os()); + output.writeLine("platform: " + Host.platform()); + output.writeLine("osVersion: " + Host.osVersion()); + output.writeLine("osBuildVersion: " + Host.osBuildVersion()); + output.writeLine("osVersionParts: " + Host.osVersionParts()); + output.writeLine("osVersionMajor: " + Host.osVersionMajor()); + output.writeLine("osVersionMinor: " + Host.osVersionMinor()); + output.writeLine("osVersionPatch: " + Host.osVersionPatch()); + output.writeLine("nullDevice: " + Host.nullDevice()); + output.close(); + }; + return [cmd]; + } + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index bb292ffae..2846dd40b 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -4551,7 +4551,7 @@ void TestBlackbox::jsExtensionsFileInfo() QVERIFY(output.exists()); QVERIFY(output.open(QIODevice::ReadOnly)); const QList<QByteArray> lines = output.readAll().trimmed().split('\n'); - QCOMPARE(lines.size(), 26); + QCOMPARE(lines.size(), 28); int i = 0; QCOMPARE(lines.at(i++).trimmed().constData(), "blubb"); QCOMPARE(lines.at(i++).trimmed().constData(), qUtf8Printable( @@ -4580,6 +4580,44 @@ void TestBlackbox::jsExtensionsFileInfo() QCOMPARE(lines.at(i++).trimmed().constData(), "../blubb.tar.gz"); QCOMPARE(lines.at(i++).trimmed().constData(), "\\tmp\\blubb.tar.gz"); QCOMPARE(lines.at(i++).trimmed().constData(), "c:\\tmp\\blubb.tar.gz"); + QCOMPARE(lines.at(i++).trimmed().constData(), qUtf8Printable(HostOsInfo::pathListSeparator())); + QCOMPARE(lines.at(i++).trimmed().constData(), qUtf8Printable(HostOsInfo::pathSeparator())); +} + +void TestBlackbox::jsExtensionsHost() +{ + QDir::setCurrent(testDataDir + "//jsextensions-host"); + QbsRunParameters params(QStringList { "-f", "host.qbs" }); + QCOMPARE(runQbs(params), 0); + QFile output("output.txt"); + QVERIFY(output.exists()); + QVERIFY(output.open(QIODevice::ReadOnly)); + const QList<QByteArray> lines = output.readAll().trimmed().split('\n'); + QCOMPARE(lines.size(), 10); + int i = 0; + QCOMPARE(lines.at(i++).trimmed().constData(), "architecture: " + + HostOsInfo::hostOSArchitecture()); + QStringList list; + for (const auto &s : HostOsInfo::canonicalOSIdentifiers(HostOsInfo::hostOSIdentifier())) + list.push_back(QString::fromStdString(s)); + QCOMPARE(lines.at(i++).trimmed().constData(), "os: " + list.join(',')); + QCOMPARE(lines.at(i++).trimmed().constData(), "platform: " + HostOsInfo::hostOSIdentifier()); + QCOMPARE(lines.at(i++).trimmed().constData(), "osVersion: " + + HostOsInfo::hostOsVersion().toString()); + QCOMPARE(lines.at(i++).trimmed().constData(), "osBuildVersion: " + + (HostOsInfo::hostOsBuildVersion().isNull() ? "undefined" : + HostOsInfo::hostOsBuildVersion())); + QCOMPARE(lines.at(i++).trimmed().constData(), "osVersionParts: " + + HostOsInfo::hostOsVersion().toString(',')); + QCOMPARE(lines.at(i++).trimmed().constData(), "osVersionMajor: " + QString::number( + HostOsInfo::hostOsVersion().majorVersion())); + QCOMPARE(lines.at(i++).trimmed().constData(), "osVersionMinor: " + QString::number( + HostOsInfo::hostOsVersion().minorVersion())); + QCOMPARE(lines.at(i++).trimmed().constData(), "osVersionPatch: " + QString::number( + HostOsInfo::hostOsVersion().patchLevel())); + QString nullDevice = HostOsInfo::isWindowsHost() ? QStringLiteral("NUL") : + QStringLiteral("/dev/null"); + QCOMPARE(lines.at(i++).trimmed().constData(), "nullDevice: " + nullDevice); } void TestBlackbox::jsExtensionsProcess() diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 987c87d6a..87761c09b 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -168,6 +168,7 @@ private slots: void invalidLibraryNames_data(); void jsExtensionsFile(); void jsExtensionsFileInfo(); + void jsExtensionsHost(); void jsExtensionsProcess(); void jsExtensionsPropertyList(); void jsExtensionsTemporaryDir(); |