diff options
author | Alexey Edelev <[email protected]> | 2021-03-15 14:25:34 +0100 |
---|---|---|
committer | Alexey Edelev <[email protected]> | 2021-03-17 11:57:11 +0100 |
commit | 6fb569af9512f63d503720ed7f62e9c70b16f969 (patch) | |
tree | 7a49c1fa32c064aeaefaa9ebec2c695c2fa275ad | |
parent | a423c0d21174fc88a02277d9cd909b0d6e11018b (diff) |
Unify QLibraryInfo settings
Exporting QLibraryInfo internals allows to reuse settings in
qmake/qtpath without having to keep its own instance.
Also there is no need to check setting groups in QLibraryInfo
except the 'Paths' group, since this logic belongs to qmake/qtpaths
only.
Change-Id: If762defba025ad7f7489f8a86ef5768a8628bd2f
Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r-- | qmake/main.cpp | 3 | ||||
-rw-r--r-- | qmake/option.cpp | 7 | ||||
-rw-r--r-- | qmake/qmakelibraryinfo.cpp | 87 | ||||
-rw-r--r-- | qmake/qmakelibraryinfo.h | 9 | ||||
-rw-r--r-- | src/corelib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/corelib/global/qlibraryinfo.cpp | 80 | ||||
-rw-r--r-- | src/corelib/global/qlibraryinfo_p.h | 78 |
7 files changed, 157 insertions, 109 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp index b00d1108275..d435ecaed84 100644 --- a/qmake/main.cpp +++ b/qmake/main.cpp @@ -32,6 +32,7 @@ #include "option.h" #include "cachekeys.h" #include "metamakefile.h" +#include <qcoreapplication.h> #include <qnamespace.h> #include <qdebug.h> #include <qregularexpression.h> @@ -598,5 +599,7 @@ QT_END_NAMESPACE int main(int argc, char **argv) { + // Set name of the qmake application in QCoreApplication instance + QT_PREPEND_NAMESPACE(QCoreApplication) app(argc, argv); return QT_PREPEND_NAMESPACE(runQMake)(argc, argv); } diff --git a/qmake/option.cpp b/qmake/option.cpp index 1f9d60d7a80..9917447f911 100644 --- a/qmake/option.cpp +++ b/qmake/option.cpp @@ -33,10 +33,12 @@ #include <qregularexpression.h> #include <qhash.h> #include <qdebug.h> -#include <qmakelibraryinfo.h> #include <stdlib.h> #include <stdarg.h> +#include <qmakelibraryinfo.h> +#include <private/qlibraryinfo_p.h> + QT_BEGIN_NAMESPACE using namespace QMakeInternal; @@ -203,7 +205,7 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state) default: QMakeGlobals::ArgumentReturn cmdRet = globals->addCommandLineArguments(state, args, &x); if (cmdRet == QMakeGlobals::ArgumentsOk) { - QMakeLibraryInfo::qtconfManualPath = globals->qtconf; + QLibraryInfoPrivate::qtconfManualPath = globals->qtconf; break; } if (cmdRet == QMakeGlobals::ArgumentMalformed) { @@ -340,7 +342,6 @@ Option::init(int argc, char **argv) #endif ; } - QMakeLibraryInfo::binaryAbsLocation = globals->qmake_abslocation; } else { Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE; } diff --git a/qmake/qmakelibraryinfo.cpp b/qmake/qmakelibraryinfo.cpp index 4398e911f1b..0d083e17d57 100644 --- a/qmake/qmakelibraryinfo.cpp +++ b/qmake/qmakelibraryinfo.cpp @@ -46,62 +46,27 @@ #include <qsettings.h> #include <qscopedpointer.h> #include <qstringlist.h> +#include <private/qlibraryinfo_p.h> #include <utility> QT_BEGIN_NAMESPACE -QString QMakeLibraryInfo::binaryAbsLocation; -QString QMakeLibraryInfo::qtconfManualPath; - struct QMakeLibrarySettings { QMakeLibrarySettings() { load(); } - void load(); - QScopedPointer<QSettings> settings; bool haveDevicePaths; bool haveEffectiveSourcePaths; bool haveEffectivePaths; bool havePaths; - bool reloadOnQAppAvailable; }; Q_GLOBAL_STATIC(QMakeLibrarySettings, qmake_library_settings) -QSettings *QMakeLibraryInfo::findConfiguration() -{ - QString qtconfig = libraryInfoFile(); - if (!qtconfig.isEmpty()) - return new QSettings(qtconfig, QSettings::IniFormat); - return nullptr; // no luck -} - -QSettings *QMakeLibraryInfo::configuration() -{ - QMakeLibrarySettings *ls = qmake_library_settings(); - return ls ? ls->settings.data() : nullptr; -} - -void QMakeLibraryInfo::reload() -{ - if (qmake_library_settings.exists()) - qmake_library_settings->load(); -} - -bool QMakeLibraryInfo::haveGroup(PathGroup group) -{ - QMakeLibrarySettings *ls = qmake_library_settings(); - return ls - && (group == EffectiveSourcePaths ? ls->haveEffectiveSourcePaths - : group == EffectivePaths ? ls->haveEffectivePaths - : group == DevicePaths ? ls->haveDevicePaths - : ls->havePaths); -} - void QMakeLibrarySettings::load() { - settings.reset(QMakeLibraryInfo::findConfiguration()); + QSettings *settings = QLibraryInfoPrivate::configuration(); if (settings) { QStringList children = settings->childGroups(); haveDevicePaths = children.contains(QLatin1String("DevicePaths")); @@ -120,6 +85,23 @@ void QMakeLibrarySettings::load() } } +void QMakeLibraryInfo::reload() +{ + QLibraryInfoPrivate::reload(); + if (qmake_library_settings.exists()) + qmake_library_settings->load(); +} + +bool QMakeLibraryInfo::haveGroup(PathGroup group) +{ + QMakeLibrarySettings *ls = qmake_library_settings(); + return ls + && (group == EffectiveSourcePaths ? ls->haveEffectiveSourcePaths + : group == EffectivePaths ? ls->haveEffectivePaths + : group == DevicePaths ? ls->haveDevicePaths + : ls->havePaths); +} + void QMakeLibraryInfo::sysrootify(QString &path) { // Acceptable values for SysrootifyPrefixPath are "true" and "false" @@ -165,9 +147,6 @@ static QLibraryInfo::LibraryPath hostToTargetPathEnum(int loc) qFatal("Unhandled host path %d in hostToTargetPathEnum.", loc); } -// from qlibraryinfo.cpp: -void qlibraryinfo_keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key, QString *value); - struct LocationInfo { QString key; @@ -179,10 +158,10 @@ static LocationInfo defaultLocationInfo(int loc) LocationInfo result; if (loc < QMakeLibraryInfo::FirstHostPath) { - qlibraryinfo_keyAndDefault(static_cast<QLibraryInfo::LibraryPath>(loc), + QLibraryInfoPrivate::keyAndDefault(static_cast<QLibraryInfo::LibraryPath>(loc), &result.key, &result.defaultValue); } else if (loc <= QMakeLibraryInfo::LastHostPath) { - qlibraryinfo_keyAndDefault(hostToTargetPathEnum(loc), &result.key, &result.defaultValue); + QLibraryInfoPrivate::keyAndDefault(hostToTargetPathEnum(loc), &result.key, &result.defaultValue); result.key.prepend(QStringLiteral("Host")); } else if (loc == QMakeLibraryInfo::SysrootPath) { result.key = QStringLiteral("Sysroot"); @@ -236,7 +215,8 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group LocationInfo locinfo = defaultLocationInfo(loc); if (!locinfo.key.isNull()) { - QSettings *config = QMakeLibraryInfo::configuration(); + QSettings *config = QLibraryInfoPrivate::configuration(); + Q_ASSERT(config != nullptr); config->beginGroup(QLatin1String(group == DevicePaths ? "DevicePaths" : group == EffectiveSourcePaths ? "EffectiveSourcePaths" @@ -298,7 +278,10 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group // We make the prefix/sysroot path absolute to the executable's directory. // loc == PrefixPath while a sysroot is set would make no sense here. // loc == SysrootPath only makes sense if qmake lives inside the sysroot itself. - baseDir = QFileInfo(libraryInfoFile()).absolutePath(); + QSettings *config = QLibraryInfoPrivate::configuration(); + if (config != nullptr) { + baseDir = QFileInfo(config->fileName()).absolutePath(); + } } else if (loc >= FirstHostPath && loc <= LastHostPath) { // We make any other host path absolute to the host prefix directory. baseDir = rawLocation(HostPrefixPath, group); @@ -313,20 +296,4 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group return ret; } -QString QMakeLibraryInfo::libraryInfoFile() -{ - if (!qtconfManualPath.isEmpty()) - return qtconfManualPath; - if (!binaryAbsLocation.isEmpty()) { - QDir dir(QFileInfo(binaryAbsLocation).absolutePath()); - QString qtconfig = dir.filePath("qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf"); - if (QFile::exists(qtconfig)) - return qtconfig; - qtconfig = dir.filePath("qt.conf"); - if (QFile::exists(qtconfig)) - return qtconfig; - } - return QString(); -} - QT_END_NAMESPACE diff --git a/qmake/qmakelibraryinfo.h b/qmake/qmakelibraryinfo.h index 896181493c2..71cc3fc78a8 100644 --- a/qmake/qmakelibraryinfo.h +++ b/qmake/qmakelibraryinfo.h @@ -50,10 +50,7 @@ class QSettings; struct QMakeLibraryInfo { - static QSettings *findConfiguration(); - static QSettings *configuration(); static QString path(int loc); - static QStringList platformPluginArguments(const QString &platformName); /* This enum has to start after the last value in QLibraryInfo::LibraryPath(NOT SettingsPath!). * See qconfig.cpp.in and QLibraryInfo for details. @@ -78,12 +75,6 @@ struct QMakeLibraryInfo static void reload(); static bool haveGroup(PathGroup group); static void sysrootify(QString &path); - - static QString binaryAbsLocation; - static QString qtconfManualPath; - -private: - static QString libraryInfoFile(); }; QT_END_NAMESPACE diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 09ef97f47f2..04c2cc1881b 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -41,7 +41,7 @@ qt_internal_add_module(Core global/qglobal.cpp global/qglobal.h global/qglobalstatic.h global/qhooks.cpp global/qhooks_p.h - global/qlibraryinfo.cpp global/qlibraryinfo.h + global/qlibraryinfo.cpp global/qlibraryinfo.h global/qlibraryinfo_p.h global/qlogging.cpp global/qlogging.h global/qmalloc.cpp # global/qnamespace.h # special case diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 4d06ec6e3f1..fccefa80082 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -45,6 +45,7 @@ #include "qsettings.h" #endif #include "qlibraryinfo.h" +#include "qlibraryinfo_p.h" #include "qscopedpointer.h" #include "qcoreapplication.h" @@ -72,65 +73,53 @@ extern void qDumpCPUFeatures(); // in qsimd.cpp #if QT_CONFIG(settings) +static QSettings *findConfiguration(); + struct QLibrarySettings { QLibrarySettings(); void load(); + QSettings *configuration(); QScopedPointer<QSettings> settings; + bool havePaths; bool reloadOnQAppAvailable; }; Q_GLOBAL_STATIC(QLibrarySettings, qt_library_settings) -class QLibraryInfoPrivate +QLibrarySettings::QLibrarySettings() : havePaths(false) + , reloadOnQAppAvailable(false) { -public: - static QSettings *findConfiguration(); - static QSettings *configuration() - { - QLibrarySettings *ls = qt_library_settings(); - if (ls) { - if (ls->reloadOnQAppAvailable && QCoreApplication::instance() != nullptr) - ls->load(); - return ls->settings.data(); - } else { - return nullptr; - } - } -}; + load(); +} -QLibrarySettings::QLibrarySettings() +QSettings *QLibrarySettings::configuration() { - load(); + if (reloadOnQAppAvailable && QCoreApplication::instance() != nullptr) + load(); + return settings.data(); } void QLibrarySettings::load() { // If we get any settings here, those won't change when the application shows up. - settings.reset(QLibraryInfoPrivate::findConfiguration()); + settings.reset(findConfiguration()); reloadOnQAppAvailable = (settings.data() == nullptr && QCoreApplication::instance() == nullptr); - bool haveDevicePaths; - bool haveEffectivePaths; - bool havePaths; + if (settings) { // This code needs to be in the regular library, as otherwise a qt.conf that // works for qmake would break things for dynamically built Qt tools. QStringList children = settings->childGroups(); - haveDevicePaths = children.contains(QLatin1String("DevicePaths")); - // EffectiveSourcePaths is for the Qt build only, so needs no backwards compat trickery. - bool haveEffectiveSourcePaths = false; - haveEffectivePaths = haveEffectiveSourcePaths || children.contains(QLatin1String("EffectivePaths")); - // Backwards compat: an existing but empty file is claimed to contain the Paths section. - havePaths = (!haveDevicePaths && !haveEffectivePaths - && !children.contains(QLatin1String("Platforms"))) + havePaths = !children.contains(QLatin1String("Platforms")) || children.contains(QLatin1String("Paths")); - if (!havePaths) - settings.reset(nullptr); } } -QSettings *QLibraryInfoPrivate::findConfiguration() +static QSettings *findConfiguration() { + if (!QLibraryInfoPrivate::qtconfManualPath.isEmpty()) + return new QSettings(QLibraryInfoPrivate::qtconfManualPath, QSettings::IniFormat); + QString qtconfig = QStringLiteral(":/qt/etc/qt.conf"); if (QFile::exists(qtconfig)) return new QSettings(qtconfig, QSettings::IniFormat); @@ -161,6 +150,25 @@ QSettings *QLibraryInfoPrivate::findConfiguration() return nullptr; //no luck } +QString QLibraryInfoPrivate::qtconfManualPath; + +QSettings *QLibraryInfoPrivate::configuration() +{ + QLibrarySettings *ls = qt_library_settings(); + return ls ? ls->configuration() : nullptr; +} + +void QLibraryInfoPrivate::reload() +{ + if (qt_library_settings.exists()) + qt_library_settings->load(); +} + +static bool havePaths() { + QLibrarySettings *ls = qt_library_settings(); + return ls && ls->havePaths; +} + #endif // settings /*! @@ -503,7 +511,7 @@ static QString getPrefix() #endif } -Q_CORE_EXPORT void qlibraryinfo_keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key, +void QLibraryInfoPrivate::keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key, QString *value) { if (unsigned(loc) < sizeof(qtConfEntries)/sizeof(qtConfEntries[0])) { @@ -539,15 +547,15 @@ QString QLibraryInfo::path(LibraryPath p) QString ret; bool fromConf = false; #if QT_CONFIG(settings) - if (QLibraryInfoPrivate::configuration()) - { + if (havePaths()) { fromConf = true; QString key; QString defaultValue; - qlibraryinfo_keyAndDefault(loc, &key, &defaultValue); + QLibraryInfoPrivate::keyAndDefault(loc, &key, &defaultValue); if (!key.isNull()) { QSettings *config = QLibraryInfoPrivate::configuration(); + Q_ASSERT(config != nullptr); config->beginGroup(QLatin1String("Paths")); ret = config->value(key, defaultValue).toString(); @@ -628,7 +636,7 @@ QString QLibraryInfo::path(LibraryPath p) QStringList QLibraryInfo::platformPluginArguments(const QString &platformName) { #if QT_CONFIG(settings) - QScopedPointer<const QSettings> settings(QLibraryInfoPrivate::findConfiguration()); + QScopedPointer<const QSettings> settings(findConfiguration()); if (!settings.isNull()) { const QString key = QLatin1String("Platforms") + QLatin1Char('/') diff --git a/src/corelib/global/qlibraryinfo_p.h b/src/corelib/global/qlibraryinfo_p.h new file mode 100644 index 00000000000..a0900f010bf --- /dev/null +++ b/src/corelib/global/qlibraryinfo_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $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$ +** +****************************************************************************/ + +#ifndef QLIBRARYINFO_P_H +#define QLIBRARYINFO_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of a number of Qt sources files. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qlibraryinfo.h" + +#if QT_CONFIG(settings) +# include "QtCore/qsettings.h" +#endif +#include "QtCore/qstring.h" + +QT_BEGIN_NAMESPACE + +class Q_CORE_EXPORT QLibraryInfoPrivate final +{ +public: +#if QT_CONFIG(settings) + static QSettings *configuration(); + static void reload(); + static QString qtconfManualPath; +#endif + static void keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key, + QString *value); +}; + +QT_END_NAMESPACE + +#endif // QLIBRARYINFO_P_H |