QtSupport: Split QtVersionFactory::create()

... into a 'canCreate()' and the actual creation, which can be
done by the already registered m_creator.

Simpler interface, with the (temporary) regression that the
EmbeddedLinuxQtVersion get constructed twice, once only to
determine that it should be alive afterwards. Will be fixed later.

Change-Id: I5da2cafe473b25a0207bbd628632c9a259780361
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-02-14 11:02:28 +01:00
parent ec6b38dea0
commit 3007105d86
14 changed files with 45 additions and 56 deletions

View File

@@ -40,14 +40,14 @@ AndroidQtVersionFactory::AndroidQtVersionFactory()
setPriority(90);
}
QtSupport::BaseQtVersion *AndroidQtVersionFactory::create(ProFileEvaluator *evaluator)
bool AndroidQtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
if (!evaluator->values(QLatin1String("CONFIG")).contains(QLatin1String("android"))
&& evaluator->value(QLatin1String("QMAKE_PLATFORM")) != QLatin1String("android"))
return nullptr;
if (evaluator->values(QLatin1String("CONFIG")).contains(QLatin1String("android-no-sdk")))
return nullptr;
return new AndroidQtVersion;
if (!evaluator->values("CONFIG").contains("android")
&& evaluator->value("QMAKE_PLATFORM") != "android")
return false;
if (evaluator->values("CONFIG").contains("android-no-sdk"))
return false;
return true;
}
} // Internal

View File

@@ -35,7 +35,7 @@ class AndroidQtVersionFactory : public QtSupport::QtVersionFactory
public:
AndroidQtVersionFactory();
QtSupport::BaseQtVersion *create(ProFileEvaluator *evaluator) override;
bool canCreate(ProFileEvaluator *evaluator) const override;
};
} // namespace Internal

View File

@@ -39,11 +39,9 @@ IosQtVersionFactory::IosQtVersionFactory()
setPriority(90);
}
QtSupport::BaseQtVersion *IosQtVersionFactory::create(ProFileEvaluator *evaluator)
bool IosQtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
if (!(evaluator->values(QLatin1String("QMAKE_PLATFORM")).contains(QLatin1String("ios"))))
return nullptr;
return new IosQtVersion;
return evaluator->values("QMAKE_PLATFORM").contains("ios");
}
} // Internal

View File

@@ -35,7 +35,7 @@ class IosQtVersionFactory : public QtSupport::QtVersionFactory
public:
IosQtVersionFactory();
QtSupport::BaseQtVersion *create(ProFileEvaluator *evaluator) override;
bool canCreate(ProFileEvaluator *evaluator) const override;
};
} // namespace Internal

View File

@@ -40,10 +40,7 @@ QnxQtVersionFactory::QnxQtVersionFactory()
setPriority(50);
}
QtSupport::BaseQtVersion *QnxQtVersionFactory::create(ProFileEvaluator *evaluator)
bool QnxQtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
if (evaluator->contains(QLatin1String("QNX_CPUDIR")))
return new QnxQtVersion;
return nullptr;
return evaluator->contains("QNX_CPUDIR");
}

View File

@@ -35,7 +35,7 @@ class QnxQtVersionFactory : public QtSupport::QtVersionFactory
public:
QnxQtVersionFactory();
QtSupport::BaseQtVersion *create(ProFileEvaluator *evaluator) override;
bool canCreate(ProFileEvaluator *evaluator) const override;
};
} // namespace Internal

View File

@@ -35,11 +35,5 @@ DesktopQtVersionFactory::DesktopQtVersionFactory()
setQtVersionCreator([] { return new DesktopQtVersion; });
setSupportedType(Constants::DESKTOPQT);
setPriority(0); // Lowest of all, we want to be the fallback
}
BaseQtVersion *DesktopQtVersionFactory::create(ProFileEvaluator *evaluator)
{
Q_UNUSED(evaluator);
// we are the fallback :) so we don't care what kind of qt it is
return new DesktopQtVersion;
// No further restrictions. We are the fallback :) so we don't care what kind of qt it is.
}

View File

@@ -34,8 +34,6 @@ class DesktopQtVersionFactory : public QtVersionFactory
{
public:
DesktopQtVersionFactory();
BaseQtVersion *create(ProFileEvaluator *evaluator) override;
};
} // Internal

View File

@@ -71,6 +71,18 @@ BaseQtVersion *QtVersionFactory::restore(const QString &type, const QVariantMap
return version;
}
BaseQtVersion *QtVersionFactory::create() const
{
QTC_ASSERT(m_creator, return nullptr);
return m_creator();
}
bool QtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
Q_UNUSED(evaluator);
return true;
}
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected, const QString &autoDetectionSource, QString *error)
{
QHash<ProKey, ProString> versionInfo;
@@ -98,7 +110,9 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
return nullptr;
foreach (QtVersionFactory *factory, factories) {
if (BaseQtVersion *ver = factory->create(&evaluator)) {
if (factory->canCreate(&evaluator)) {
BaseQtVersion *ver = factory->create();
QTC_ASSERT(ver, continue);
ver->setupQmakePathAndId(qmakePath);
ver->setAutoDetectionSource(autoDetectionSource);
ver->setIsAutodetected(isAutoDetected);

View File

@@ -54,7 +54,9 @@ public:
/// a qtversion, the priority of the desktop factory is 0 and
/// the desktop factory claims to handle all paths
int priority() const { return m_priority; }
virtual BaseQtVersion *create(ProFileEvaluator *evaluator) = 0;
BaseQtVersion *create() const;
virtual bool canCreate(ProFileEvaluator *evaluator) const;
static BaseQtVersion *createQtVersionFromQMakePath(
const Utils::FileName &qmakePath, bool isAutoDetected = false,

View File

@@ -40,21 +40,17 @@ EmbeddedLinuxQtVersionFactory::EmbeddedLinuxQtVersionFactory()
setPriority(10);
}
QtSupport::BaseQtVersion *EmbeddedLinuxQtVersionFactory::create(ProFileEvaluator *evaluator)
bool EmbeddedLinuxQtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
Q_UNUSED(evaluator);
auto version = new EmbeddedLinuxQtVersion;
EmbeddedLinuxQtVersion tempVersion;
QList<ProjectExplorer::Abi> abis = tempVersion.qtAbis();
QList<ProjectExplorer::Abi> abis = version->qtAbis();
// Note: This fails for e.g. intel/meego cross builds on x86 linux machines.
if (abis.count() == 1
return abis.count() == 1
&& abis.at(0).os() == ProjectExplorer::Abi::LinuxOS
&& !ProjectExplorer::Abi::hostAbi().isCompatibleWith(abis.at(0)))
return version;
delete version;
return nullptr;
&& !ProjectExplorer::Abi::hostAbi().isCompatibleWith(abis.at(0));
}
} // namespace Internal

View File

@@ -35,7 +35,7 @@ class EmbeddedLinuxQtVersionFactory : public QtSupport::QtVersionFactory
public:
EmbeddedLinuxQtVersionFactory();
QtSupport::BaseQtVersion *create(ProFileEvaluator *evaluator) override;
bool canCreate(ProFileEvaluator *evaluator) const override;
};
} // Internal

View File

@@ -40,14 +40,9 @@ WinRtQtVersionFactory::WinRtQtVersionFactory()
setPriority(10);
}
QtSupport::BaseQtVersion *WinRtQtVersionFactory::create(ProFileEvaluator *evaluator)
bool WinRtQtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
foreach (const QString &value, evaluator->values(QLatin1String("QMAKE_PLATFORM"))) {
if (value == QStringLiteral("winrt"))
return new WinRtQtVersion;
}
return nullptr;
return evaluator->values("QMAKE_PLATFORM").contains("winrt");
}
@@ -59,14 +54,9 @@ WinRtPhoneQtVersionFactory::WinRtPhoneQtVersionFactory()
setPriority(10);
}
QtSupport::BaseQtVersion *WinRtPhoneQtVersionFactory::create(ProFileEvaluator *evaluator)
bool WinRtPhoneQtVersionFactory::canCreate(ProFileEvaluator *evaluator) const
{
foreach (const QString &value, evaluator->values(QLatin1String("QMAKE_PLATFORM"))) {
if (value == QStringLiteral("winphone"))
return new WinRtPhoneQtVersion;
}
return nullptr;
return evaluator->values("QMAKE_PLATFORM").contains("winphone");
}
} // Internal

View File

@@ -35,7 +35,7 @@ class WinRtQtVersionFactory : public QtSupport::QtVersionFactory
public:
WinRtQtVersionFactory();
QtSupport::BaseQtVersion *create(ProFileEvaluator *evaluator) override;
bool canCreate(ProFileEvaluator *evaluator) const override;
};
class WinRtPhoneQtVersionFactory : public QtSupport::QtVersionFactory
@@ -43,7 +43,7 @@ class WinRtPhoneQtVersionFactory : public QtSupport::QtVersionFactory
public:
WinRtPhoneQtVersionFactory();
QtSupport::BaseQtVersion *create(ProFileEvaluator *evaluator) override;
bool canCreate(ProFileEvaluator *evaluator) const override;
};
} // Internal