QtSupport: Pimpl BaseQtVersion

Too much for a public header.

Also, lump the implementations of BaseQtVersion and QtVersionFactory
into a common .cpp. The classes are tightly coupled, having them
in one place allows to get rid of several accessors in their
interfaces.

At least ProString vanishes from the .h, and thanks to C++'s
peculiar idea of object constness, we can lie less obviously
in the implementation about effectively mutable data members.

Change-Id: Ibf594d71dcba163d6f09ba65e3ecb76174295099
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-08-15 09:43:37 +02:00
parent f29756b069
commit d0bdfad932
6 changed files with 459 additions and 488 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -37,47 +37,26 @@
#include <QStringList>
#include <QVariantMap>
QT_BEGIN_NAMESPACE
class ProFileEvaluator;
class QMakeGlobals;
QT_END_NAMESPACE
namespace Utils {
class Environment;
class FileInProjectFinder;
}
namespace Core { class Id; }
} // Utils
namespace ProjectExplorer {
class IOutputParser;
class Kit;
class ToolChain;
class HeaderPath;
class Target;
} // namespace ProjectExplorer
} // ProjectExplorer
QT_BEGIN_NAMESPACE
class ProKey;
class ProString;
class ProFileEvaluator;
class QMakeGlobals;
class QSettings;
QT_END_NAMESPACE
namespace QtSupport {
namespace QtSupport
{
class QtConfigWidget;
class BaseQtVersion;
class QtVersionFactory;
// Wrapper to make the std::unique_ptr<Utils::MacroExpander> "copyable":
class MacroExpanderWrapper
{
public:
MacroExpanderWrapper() = default;
MacroExpanderWrapper(const MacroExpanderWrapper &other) { Q_UNUSED(other) }
MacroExpanderWrapper(MacroExpanderWrapper &&other) = default;
Utils::MacroExpander *macroExpander(const BaseQtVersion *qtversion) const;
private:
mutable std::unique_ptr<Utils::MacroExpander> m_expander;
};
class QTSUPPORT_EXPORT QtVersionNumber
{
@@ -101,13 +80,13 @@ public:
bool operator ==(const QtVersionNumber &b) const;
};
namespace Internal { class QtOptionsPageWidget; }
namespace Internal {
class QtOptionsPageWidget;
class BaseQtVersionPrivate;
}
class QTSUPPORT_EXPORT BaseQtVersion
{
friend class QtVersionFactory;
friend class QtVersionManager;
friend class QtSupport::Internal::QtOptionsPageWidget;
public:
using Predicate = std::function<bool(const BaseQtVersion *)>;
@@ -254,90 +233,33 @@ public:
const ProjectExplorer::Target *target);
QSet<Core::Id> features() const;
void setIsAutodetected(bool isAutodetected);
protected:
virtual QSet<Core::Id> availableFeatures() const;
BaseQtVersion();
BaseQtVersion(const BaseQtVersion &other) = delete;
virtual QSet<Core::Id> availableFeatures() const;
virtual ProjectExplorer::Tasks reportIssuesImpl(const QString &proFile, const QString &buildDir) const;
// helper function for desktop and simulator to figure out the supported abis based on the libraries
Utils::FilePathList qtCorePaths() const;
static ProjectExplorer::Abis qtAbisFromLibrary(const Utils::FilePathList &coreLibraries);
void ensureMkSpecParsed() const;
virtual void parseMkSpec(ProFileEvaluator *) const;
private:
void setupQmakePathAndId(const Utils::FilePath &path);
void setAutoDetectionSource(const QString &autodetectionSource);
void updateVersionInfo() const;
enum HostBinaries { Designer, Linguist, Uic, QScxmlc };
QString findHostBinary(HostBinaries binary) const;
void updateMkspec() const;
QHash<ProKey, ProString> versionInfo() const;
static bool queryQMakeVariables(const Utils::FilePath &binary,
const Utils::Environment &env,
QHash<ProKey, ProString> *versionInfo,
QString *error = nullptr);
static QString qmakeProperty(const QHash<ProKey, ProString> &versionInfo,
const QByteArray &name,
PropertyVariant variant = PropertyVariantGet);
static Utils::FilePath mkspecDirectoryFromVersionInfo(const QHash<ProKey,ProString> &versionInfo);
static Utils::FilePath mkspecFromVersionInfo(const QHash<ProKey,ProString> &versionInfo);
static Utils::FilePath sourcePath(const QHash<ProKey,ProString> &versionInfo);
void setId(int id); // used by the qtversionmanager for legacy restore
// and by the qtoptionspage to replace Qt versions
friend class QtVersionFactory;
friend class QtVersionManager;
friend class Internal::BaseQtVersionPrivate;
friend class Internal::QtOptionsPageWidget;
int m_id = -1;
const QtVersionFactory *m_factory = nullptr; // The factory that created us.
void setId(int id);
BaseQtVersion *clone() const;
bool m_isAutodetected = false;
mutable bool m_hasQmlDump = false; // controlled by m_versionInfoUpToDate
mutable bool m_mkspecUpToDate = false;
mutable bool m_mkspecReadUpToDate = false;
mutable bool m_defaultConfigIsDebug = true;
mutable bool m_defaultConfigIsDebugAndRelease = true;
mutable bool m_frameworkBuild = false;
mutable bool m_versionInfoUpToDate = false;
mutable bool m_installed = true;
mutable bool m_hasExamples = false;
mutable bool m_hasDemos = false;
mutable bool m_hasDocumentation = false;
mutable bool m_qmakeIsExecutable = true;
mutable bool m_hasQtAbis = false;
mutable QStringList m_configValues;
mutable QStringList m_qtConfigValues;
QString m_unexpandedDisplayName;
QString m_autodetectionSource;
QSet<Core::Id> m_overrideFeatures;
mutable Utils::FilePath m_sourcePath;
mutable Utils::FilePath m_qtSources;
mutable Utils::FilePath m_mkspec;
mutable Utils::FilePath m_mkspecFullPath;
mutable QHash<QString, QString> m_mkspecValues;
mutable QHash<ProKey, ProString> m_versionInfo;
Utils::FilePath m_qmakeCommand;
mutable QString m_qtVersionString;
mutable QString m_uicCommand;
mutable QString m_designerCommand;
mutable QString m_linguistCommand;
mutable QString m_qscxmlcCommand;
mutable QString m_qmlsceneCommand;
mutable ProjectExplorer::Abis m_qtAbis;
MacroExpanderWrapper m_expander;
Internal::BaseQtVersionPrivate *d = nullptr;
};
}
} // QtSupport
Q_DECLARE_OPERATORS_FOR_FLAGS(QtSupport::BaseQtVersion::QmakeBuildConfigs)

View File

@@ -522,7 +522,7 @@ void QtOptionsPageWidget::updateQtVersions(const QList<int> &additions, const QL
// Add changed/added items:
foreach (int a, toAdd) {
BaseQtVersion *version = QtVersionFactory::cloneQtVersion(QtVersionManager::version(a));
BaseQtVersion *version = QtVersionManager::version(a)->clone();
auto *item = new QtVersionItem(version);
// Insert in the right place:
@@ -753,7 +753,7 @@ void QtOptionsPageWidget::apply()
m_model->forItemsAtLevel<2>([&versions](QtVersionItem *item) {
item->setChanged(false);
versions.append(QtVersionFactory::cloneQtVersion(item->version()));
versions.append(item->version()->clone());
});
QtVersionManager::setNewQtVersions(versions);

View File

@@ -1,171 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** 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-3.0.html.
**
****************************************************************************/
#include "qtversionfactory.h"
#include "profilereader.h"
#include "baseqtversion.h"
#include <proparser/qmakevfs.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
using namespace QtSupport;
using namespace QtSupport::Internal;
static QList<QtVersionFactory *> g_qtVersionFactories;
QtVersionFactory::QtVersionFactory()
{
g_qtVersionFactories.append(this);
}
QtVersionFactory::~QtVersionFactory()
{
g_qtVersionFactories.removeOne(this);
}
const QList<QtVersionFactory *> QtVersionFactory::allQtVersionFactories()
{
return g_qtVersionFactories;
}
bool QtVersionFactory::canRestore(const QString &type)
{
return type == m_supportedType;
}
BaseQtVersion *QtVersionFactory::restore(const QString &type, const QVariantMap &data)
{
QTC_ASSERT(canRestore(type), return nullptr);
QTC_ASSERT(m_creator, return nullptr);
BaseQtVersion *version = create();
version->fromMap(data);
return version;
}
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FilePath &qmakePath, bool isAutoDetected, const QString &autoDetectionSource, QString *error)
{
QHash<ProKey, ProString> versionInfo;
if (!BaseQtVersion::queryQMakeVariables(qmakePath, Utils::Environment::systemEnvironment(),
&versionInfo, error))
return nullptr;
Utils::FilePath mkspec = BaseQtVersion::mkspecFromVersionInfo(versionInfo);
QMakeVfs vfs;
QMakeGlobals globals;
globals.setProperties(versionInfo);
ProMessageHandler msgHandler(false);
ProFileCacheManager::instance()->incRefCount();
QMakeParser parser(ProFileCacheManager::instance()->cache(), &vfs, &msgHandler);
ProFileEvaluator evaluator(&globals, &parser, &vfs, &msgHandler);
evaluator.loadNamedSpec(mkspec.toString(), false);
QList<QtVersionFactory *> factories = g_qtVersionFactories;
Utils::sort(factories, [](const QtVersionFactory *l, const QtVersionFactory *r) {
return l->priority() > r->priority();
});
QFileInfo fi = qmakePath.toFileInfo();
if (!fi.exists() || !fi.isExecutable() || !fi.isFile())
return nullptr;
SetupData setup;
setup.config = evaluator.values("CONFIG");
setup.platforms = evaluator.values("QMAKE_PLATFORM"); // It's a list in general.
setup.isQnx = !evaluator.value("QNX_CPUDIR").isEmpty();
foreach (QtVersionFactory *factory, factories) {
if (!factory->m_restrictionChecker || factory->m_restrictionChecker(setup)) {
BaseQtVersion *ver = factory->create();
QTC_ASSERT(ver, continue);
ver->setupQmakePathAndId(qmakePath);
ver->setAutoDetectionSource(autoDetectionSource);
ver->setIsAutodetected(isAutoDetected);
ProFileCacheManager::instance()->decRefCount();
return ver;
}
}
ProFileCacheManager::instance()->decRefCount();
if (error) {
*error = QCoreApplication::translate("QtSupport::QtVersionFactory",
"No factory found for qmake: \"%1\"").arg(qmakePath.toUserOutput());
}
return nullptr;
}
BaseQtVersion *QtVersionFactory::create() const
{
QTC_ASSERT(m_creator, return nullptr);
BaseQtVersion *version = m_creator();
version->m_factory = this;
return version;
}
QString QtVersionFactory::supportedType() const
{
return m_supportedType;
}
BaseQtVersion *QtVersionFactory::cloneQtVersion(const BaseQtVersion *source)
{
QTC_ASSERT(source, return nullptr);
const QString sourceType = source->type();
for (QtVersionFactory *factory : g_qtVersionFactories) {
if (factory->m_supportedType == sourceType) {
BaseQtVersion *version = factory->create();
QTC_ASSERT(version, return nullptr);
version->fromMap(source->toMap());
return version;
}
}
QTC_CHECK(false);
return nullptr;
}
void QtVersionFactory::setQtVersionCreator(const std::function<BaseQtVersion *()> &creator)
{
m_creator = creator;
}
void QtVersionFactory::setRestrictionChecker(const std::function<bool(const SetupData &)> &checker)
{
m_restrictionChecker = checker;
}
void QtVersionFactory::setSupportedType(const QString &type)
{
m_supportedType = type;
}
void QtVersionFactory::setPriority(int priority)
{
m_priority = priority;
}

View File

@@ -51,14 +51,10 @@ public:
/// the desktop factory claims to handle all paths
int priority() const { return m_priority; }
QString supportedType() const;
static BaseQtVersion *createQtVersionFromQMakePath(
const Utils::FilePath &qmakePath, bool isAutoDetected = false,
const QString &autoDetectionSource = QString(), QString *error = nullptr);
static BaseQtVersion *cloneQtVersion(const BaseQtVersion *source);
protected:
struct SetupData
{
@@ -73,6 +69,7 @@ protected:
void setPriority(int priority);
private:
friend class BaseQtVersion;
BaseQtVersion *create() const;
std::function<BaseQtVersion *()> m_creator;

View File

@@ -35,6 +35,7 @@ class QTSUPPORT_EXPORT QtVersionManager : public QObject
Q_OBJECT
// for getUniqueId();
friend class BaseQtVersion;
friend class Internal::BaseQtVersionPrivate;
friend class Internal::QtOptionsPageWidget;
public:
static QtVersionManager *instance();