2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-04-24 15:49:09 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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
|
|
|
|
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
|
|
|
|
2014-07-09 15:31:09 +02:00
|
|
|
#include <projectexplorer/kitinformationmacroexpander.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);
|
|
|
|
|
|
2013-02-28 15:30:35 +01:00
|
|
|
connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsLoaded()),
|
|
|
|
|
this, SLOT(kitsWereLoaded()));
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-09 20:41:30 +03:00
|
|
|
QVariant QtKitInformation::defaultValue(ProjectExplorer::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":
|
2013-07-29 17:04:28 +02:00
|
|
|
Utils::FileName qmake = Utils::BuildableHelperLibrary::findSystemQt(Utils::Environment::systemEnvironment());
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
if (qmake.isEmpty())
|
|
|
|
|
return -1;
|
|
|
|
|
|
2013-08-29 14:11:29 +02:00
|
|
|
QList<BaseQtVersion *> versionList = QtVersionManager::versions();
|
2012-09-25 10:47:35 +02:00
|
|
|
BaseQtVersion *fallBack = 0;
|
2012-04-24 15:49:09 +02:00
|
|
|
foreach (BaseQtVersion *v, versionList) {
|
|
|
|
|
if (qmake == v->qmakeCommand())
|
|
|
|
|
return v->uniqueId();
|
2012-09-25 10:47:35 +02:00
|
|
|
if (v->type() == QLatin1String(QtSupport::Constants::DESKTOPQT) && !fallBack)
|
|
|
|
|
fallBack = v;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
2012-09-25 10:47:35 +02:00
|
|
|
if (fallBack)
|
|
|
|
|
return fallBack->uniqueId();
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2013-02-28 15:30:35 +01:00
|
|
|
QList<ProjectExplorer::Task> result;
|
2013-08-29 14:11:29 +02:00
|
|
|
QTC_ASSERT(QtVersionManager::isLoaded(), return result);
|
2012-10-11 13:47:23 +02:00
|
|
|
BaseQtVersion *version = qtVersion(k);
|
|
|
|
|
if (!version)
|
2013-02-28 15:30:35 +01:00
|
|
|
return result;
|
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-13 12:49:05 +02:00
|
|
|
bool QtKitInformation::resolveMacro(const ProjectExplorer::Kit *kit, const QString &name, QString *ret) const
|
2014-07-09 15:31:09 +02:00
|
|
|
{
|
2014-10-13 12:49:05 +02:00
|
|
|
if (BaseQtVersion *version = qtVersion(kit)) {
|
|
|
|
|
MacroExpander *expander = version->macroExpander();
|
|
|
|
|
if (expander->resolveMacro(name, ret))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// FIXME: Handle in version expander once we can detect loops.
|
|
|
|
|
if (name == QLatin1String("Qt:name")) {
|
|
|
|
|
*ret = version->displayName();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 18:49:44 +02:00
|
|
|
if (Utils::globalMacroExpander()->resolveMacro(name, ret))
|
|
|
|
|
return true;
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
return false;
|
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();
|
2013-08-29 14:11:29 +02:00
|
|
|
foreach (BaseQtVersion *v, QtVersionManager::versions()) {
|
2012-09-18 15:47:08 +02:00
|
|
|
if (v->autodetectionSource() != source)
|
|
|
|
|
continue;
|
|
|
|
|
id = v->uniqueId();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
|
|
connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
|
|
|
|
|
this, SLOT(qtVersionsChanged(QList<int>,QList<int>,QList<int>)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 09:09:20 +02:00
|
|
|
KitMatcher QtKitInformation::platformMatcher(const QString &platform)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2014-07-23 09:09:20 +02:00
|
|
|
return std::function<bool(const Kit *)>([platform](const Kit *kit) -> bool {
|
|
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(kit);
|
|
|
|
|
return version && version->platformName() == platform;
|
|
|
|
|
});
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 09:09:20 +02:00
|
|
|
KitMatcher QtKitInformation::qtVersionMatcher(const Core::FeatureSet &required,
|
|
|
|
|
const QtVersionNumber &min, const QtVersionNumber &max)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2014-07-23 09:09:20 +02:00
|
|
|
return std::function<bool(const Kit *)>([required, min, max](const Kit *kit) -> bool {
|
|
|
|
|
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);
|
|
|
|
|
});
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-29 15:15:27 +02:00
|
|
|
QSet<QString> QtKitInformation::availablePlatforms(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
QSet<QString> result;
|
|
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(k);
|
2014-09-19 15:24:20 +02:00
|
|
|
if (version) {
|
|
|
|
|
QString platform = version->platformName();
|
|
|
|
|
if (!platform.isEmpty())
|
|
|
|
|
result.insert(version->platformName());
|
|
|
|
|
}
|
2014-07-29 15:15:27 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString QtKitInformation::displayNameForPlatform(const Kit *k, const QString &platform) const
|
|
|
|
|
{
|
|
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(k);
|
|
|
|
|
if (version && version->platformName() == platform)
|
|
|
|
|
return version->platformDisplayName();
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::FeatureSet QtKitInformation::availableFeatures(const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
BaseQtVersion *version = QtKitInformation::qtVersion(k);
|
|
|
|
|
return version ? version->availableFeatures() : Core::FeatureSet();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
} // namespace QtSupport
|