2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "qtkitinformation.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "qtkitconfigwidget.h"
|
2012-09-25 10:47:35 +02:00
|
|
|
#include "qtsupportconstants.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "qtversionmanager.h"
|
2012-11-02 12:45:09 +01:00
|
|
|
#include "qtparser.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2015-11-27 14:02:44 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/task.h>
|
|
|
|
|
|
2014-10-30 15:51:47 +01:00
|
|
|
#include <utils/algorithm.h>
|
2013-07-29 17:04:28 +02:00
|
|
|
#include <utils/buildablehelperlibrary.h>
|
2014-10-13 12:49:05 +02:00
|
|
|
#include <utils/macroexpander.h>
|
2013-02-28 15:30:35 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2014-07-23 09:09:20 +02:00
|
|
|
using namespace ProjectExplorer;
|
2014-10-10 14:15:57 +02:00
|
|
|
using namespace Utils;
|
2014-07-23 09:09:20 +02:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
namespace QtSupport {
|
2014-07-09 15:31:09 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QtKitInformation::QtKitInformation()
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
setObjectName(QLatin1String("QtKitInformation"));
|
2013-09-09 17:10:41 +02:00
|
|
|
setId(QtKitInformation::id());
|
2013-08-28 18:57:25 +02:00
|
|
|
setPriority(26000);
|
|
|
|
|
|
2015-11-27 14:02:44 +01:00
|
|
|
connect(KitManager::instance(), &KitManager::kitsLoaded,
|
|
|
|
|
this, &QtKitInformation::kitsWereLoaded);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-04 17:49:28 +01:00
|
|
|
QVariant QtKitInformation::defaultValue(const Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
Q_UNUSED(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
// find "Qt in PATH":
|
2017-01-11 14:43:48 +01:00
|
|
|
BaseQtVersion *result = QtVersionManager::version(equal(&BaseQtVersion::autodetectionSource,
|
|
|
|
|
QString::fromLatin1("PATH")));
|
2014-10-30 15:51:47 +01:00
|
|
|
if (result)
|
|
|
|
|
return result->uniqueId();
|
|
|
|
|
|
|
|
|
|
// Use *any* desktop Qt:
|
2017-01-11 14:43:48 +01:00
|
|
|
result = QtVersionManager::version(equal(&BaseQtVersion::type,
|
|
|
|
|
QString::fromLatin1(QtSupport::Constants::DESKTOPQT)));
|
2014-10-30 15:51:47 +01:00
|
|
|
return result ? result->uniqueId() : -1;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-11 13:47:23 +02:00
|
|
|
QList<ProjectExplorer::Task> QtKitInformation::validate(const ProjectExplorer::Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2015-11-27 14:02:44 +01:00
|
|
|
QTC_ASSERT(QtVersionManager::isLoaded(), return { });
|
2012-10-11 13:47:23 +02:00
|
|
|
BaseQtVersion *version = qtVersion(k);
|
|
|
|
|
if (!version)
|
2015-11-27 14:02:44 +01:00
|
|
|
return { };
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
return version->validateKit(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-11 13:47:23 +02:00
|
|
|
void QtKitInformation::fix(ProjectExplorer::Kit *k)
|
|
|
|
|
{
|
2013-08-29 14:11:29 +02:00
|
|
|
QTC_ASSERT(QtVersionManager::isLoaded(), return);
|
2012-10-11 13:47:23 +02:00
|
|
|
BaseQtVersion *version = qtVersion(k);
|
2013-04-04 10:34:18 +02:00
|
|
|
if (!version && qtVersionId(k) >= 0) {
|
2013-02-28 17:06:36 +01:00
|
|
|
qWarning("Qt version is no longer known, removing from kit \"%s\".", qPrintable(k->displayName()));
|
2012-10-11 13:47:23 +02:00
|
|
|
setQtVersionId(k, -1);
|
2013-02-28 17:06:36 +01:00
|
|
|
}
|
2012-10-11 13:47:23 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
ProjectExplorer::KitConfigWidget *QtKitInformation::createConfigWidget(ProjectExplorer::Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2013-09-09 17:10:41 +02:00
|
|
|
return new Internal::QtKitConfigWidget(k, this);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
QString QtKitInformation::displayNamePostfix(const ProjectExplorer::Kit *k) const
|
2012-08-07 13:09:56 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
BaseQtVersion *version = qtVersion(k);
|
2012-08-07 13:09:56 +02:00
|
|
|
return version ? version->displayName() : QString();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
ProjectExplorer::KitInformation::ItemList
|
2013-01-31 16:56:04 +01:00
|
|
|
QtKitInformation::toUserOutput(const ProjectExplorer::Kit *k) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
BaseQtVersion *version = qtVersion(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
return ItemList() << qMakePair(tr("Qt version"), version ? version->displayName() : tr("None"));
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
void QtKitInformation::addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
BaseQtVersion *version = qtVersion(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (version)
|
2012-09-09 20:41:30 +03:00
|
|
|
version->addToEnvironment(k, env);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-11-02 12:45:09 +01:00
|
|
|
ProjectExplorer::IOutputParser *QtKitInformation::createOutputParser(const ProjectExplorer::Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
if (qtVersion(k))
|
|
|
|
|
return new QtParser;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 23:13:13 +02:00
|
|
|
void QtKitInformation::addToMacroExpander(Kit *kit, MacroExpander *expander) const
|
2014-07-09 15:31:09 +02:00
|
|
|
{
|
2014-10-20 23:13:13 +02:00
|
|
|
expander->registerSubProvider(
|
2017-09-07 17:05:47 +02:00
|
|
|
[kit]() -> MacroExpander * {
|
2014-10-20 23:13:13 +02:00
|
|
|
BaseQtVersion *version = qtVersion(kit);
|
|
|
|
|
return version ? version->macroExpander() : 0;
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-22 14:25:15 +02:00
|
|
|
expander->registerVariable("Qt:Name", tr("Name of Qt Version"),
|
2017-09-07 17:05:47 +02:00
|
|
|
[kit]() -> QString {
|
2014-10-20 23:13:13 +02:00
|
|
|
BaseQtVersion *version = qtVersion(kit);
|
|
|
|
|
return version ? version->displayName() : tr("unknown");
|
|
|
|
|
});
|
2016-03-16 11:56:06 +01:00
|
|
|
expander->registerVariable("Qt:qmakeExecutable", tr("Path to the qmake executable"),
|
2017-09-07 17:05:47 +02:00
|
|
|
[kit]() -> QString {
|
2016-03-16 11:56:06 +01:00
|
|
|
BaseQtVersion *version = qtVersion(kit);
|
|
|
|
|
return version ? version->qmakeCommand().toString() : QString();
|
|
|
|
|
});
|
2014-07-09 15:31:09 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-09 17:10:41 +02:00
|
|
|
Core::Id QtKitInformation::id()
|
|
|
|
|
{
|
|
|
|
|
return "QtSupport.QtInformation";
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
int QtKitInformation::qtVersionId(const ProjectExplorer::Kit *k)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
if (!k)
|
2012-04-24 15:49:09 +02:00
|
|
|
return -1;
|
2012-09-18 15:47:08 +02:00
|
|
|
|
|
|
|
|
int id = -1;
|
2013-09-09 17:10:41 +02:00
|
|
|
QVariant data = k->value(QtKitInformation::id(), -1);
|
2012-09-18 15:47:08 +02:00
|
|
|
if (data.type() == QVariant::Int) {
|
|
|
|
|
bool ok;
|
|
|
|
|
id = data.toInt(&ok);
|
|
|
|
|
if (!ok)
|
|
|
|
|
id = -1;
|
|
|
|
|
} else {
|
|
|
|
|
QString source = data.toString();
|
2017-01-11 14:43:48 +01:00
|
|
|
BaseQtVersion *v = QtVersionManager::version([source](const BaseQtVersion *v) { return v->autodetectionSource() == source; });
|
|
|
|
|
if (v)
|
2012-09-18 15:47:08 +02:00
|
|
|
id = v->uniqueId();
|
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
void QtKitInformation::setQtVersionId(ProjectExplorer::Kit *k, const int id)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2013-09-09 17:10:41 +02:00
|
|
|
k->setValue(QtKitInformation::id(), id);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
BaseQtVersion *QtKitInformation::qtVersion(const ProjectExplorer::Kit *k)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2013-08-29 14:11:29 +02:00
|
|
|
return QtVersionManager::version(qtVersionId(k));
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
void QtKitInformation::setQtVersion(ProjectExplorer::Kit *k, const BaseQtVersion *v)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
if (!v)
|
2012-09-09 20:41:30 +03:00
|
|
|
setQtVersionId(k, -1);
|
2012-04-24 15:49:09 +02:00
|
|
|
else
|
2012-09-09 20:41:30 +03:00
|
|
|
setQtVersionId(k, v->uniqueId());
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-17 17:27:17 +02:00
|
|
|
void QtKitInformation::qtVersionsChanged(const QList<int> &addedIds,
|
|
|
|
|
const QList<int> &removedIds,
|
|
|
|
|
const QList<int> &changedIds)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(addedIds);
|
|
|
|
|
Q_UNUSED(removedIds);
|
2013-09-25 11:53:29 +02:00
|
|
|
foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::kits()) {
|
|
|
|
|
if (changedIds.contains(qtVersionId(k))) {
|
|
|
|
|
k->validate(); // Qt version may have become (in)valid
|
2012-10-17 17:27:17 +02:00
|
|
|
notifyAboutUpdate(k);
|
2013-09-25 11:53:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-10-17 17:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:30:35 +01:00
|
|
|
void QtKitInformation::kitsWereLoaded()
|
|
|
|
|
{
|
2013-08-21 12:48:46 +02:00
|
|
|
foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::kits())
|
2013-02-28 15:30:35 +01:00
|
|
|
fix(k);
|
|
|
|
|
|
2016-06-05 22:22:11 +03:00
|
|
|
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsChanged,
|
|
|
|
|
this, &QtKitInformation::qtVersionsChanged);
|
2013-02-28 15:30:35 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 17:25:58 +01:00
|
|
|
Kit::Predicate QtKitInformation::platformPredicate(Core::Id platform)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2017-01-11 17:25:58 +01:00
|
|
|
return [platform](const Kit *kit) -> bool {
|
2014-07-23 09:09:20 +02:00
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(kit);
|
2015-11-27 16:14:14 +01:00
|
|
|
return version && version->targetDeviceTypes().contains(platform);
|
2017-01-11 17:25:58 +01:00
|
|
|
};
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 17:25:58 +01:00
|
|
|
Kit::Predicate QtKitInformation::qtVersionPredicate(const QSet<Core::Id> &required,
|
|
|
|
|
const QtVersionNumber &min,
|
|
|
|
|
const QtVersionNumber &max)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2017-01-11 17:25:58 +01:00
|
|
|
return [required, min, max](const Kit *kit) -> bool {
|
2014-07-23 09:09:20 +02:00
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(kit);
|
|
|
|
|
if (!version)
|
|
|
|
|
return false;
|
|
|
|
|
QtVersionNumber current = version->qtVersion();
|
|
|
|
|
if (min.majorVersion > -1 && current < min)
|
|
|
|
|
return false;
|
|
|
|
|
if (max.majorVersion > -1 && current > max)
|
|
|
|
|
return false;
|
|
|
|
|
return version->availableFeatures().contains(required);
|
2017-01-11 17:25:58 +01:00
|
|
|
};
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 16:14:14 +01:00
|
|
|
QSet<Core::Id> QtKitInformation::supportedPlatforms(const Kit *k) const
|
2014-07-29 15:15:27 +02:00
|
|
|
{
|
|
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(k);
|
2015-11-27 16:14:14 +01:00
|
|
|
return version ? version->targetDeviceTypes() : QSet<Core::Id>();
|
2014-07-29 15:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 11:31:35 +01:00
|
|
|
QSet<Core::Id> QtKitInformation::availableFeatures(const Kit *k) const
|
2014-07-29 15:15:27 +02:00
|
|
|
{
|
|
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(k);
|
2015-11-27 11:31:35 +01:00
|
|
|
return version ? version->availableFeatures() : QSet<Core::Id>();
|
2014-07-29 15:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
} // namespace QtSupport
|