2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-09 14:53:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-09 14:53:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-09 14:53:06 +01: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.
|
2008-12-09 14:53:06 +01: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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-09 14:53:06 +01:00
|
|
|
|
|
|
|
|
#include "cmakerunconfiguration.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
#include "cmakebuildconfiguration.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "cmakeproject.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2015-11-23 16:41:54 +01:00
|
|
|
#include <coreplugin/coreicons.h>
|
2011-02-24 14:58:37 +01:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2013-04-09 12:05:15 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-11-01 14:13:41 +01:00
|
|
|
#include <projectexplorer/localenvironmentaspect.h>
|
2015-04-30 13:11:25 +02:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/detailswidget.h>
|
2016-01-06 11:40:52 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-08-18 13:46:52 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QCheckBox>
|
2008-12-09 14:53:06 +01:00
|
|
|
|
|
|
|
|
using namespace CMakeProjectManager;
|
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
2014-05-26 22:13:14 +03:00
|
|
|
using namespace ProjectExplorer;
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
namespace {
|
2011-11-02 16:45:13 +01:00
|
|
|
const char CMAKE_RC_PREFIX[] = "CMakeProjectManager.CMakeRunConfiguration.";
|
|
|
|
|
const char TITLE_KEY[] = "CMakeProjectManager.CMakeRunConfiguation.Title";
|
2010-01-19 13:41:02 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, Core::Id id, const QString &target,
|
2016-10-13 12:02:52 +02:00
|
|
|
const Utils::FileName &workingDirectory, const QString &title) :
|
2016-01-25 15:00:20 +01:00
|
|
|
RunConfiguration(parent, id),
|
2010-02-02 12:01:11 +01:00
|
|
|
m_buildTarget(target),
|
2016-01-07 15:22:53 +01:00
|
|
|
m_title(title)
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
addExtraAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()));
|
2015-04-30 13:11:25 +02:00
|
|
|
addExtraAspect(new ArgumentsAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.Arguments")));
|
2015-05-12 13:36:09 +02:00
|
|
|
addExtraAspect(new TerminalAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.UseTerminal")));
|
2015-12-16 12:10:11 +01:00
|
|
|
|
|
|
|
|
auto wd = new WorkingDirectoryAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"));
|
2016-10-13 12:02:52 +02:00
|
|
|
wd->setDefaultWorkingDirectory(workingDirectory);
|
2015-12-16 12:10:11 +01:00
|
|
|
addExtraAspect(wd);
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
ctor();
|
|
|
|
|
}
|
2009-11-26 14:43:27 +01:00
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, CMakeRunConfiguration *source) :
|
2016-01-25 15:00:20 +01:00
|
|
|
RunConfiguration(parent, source),
|
2010-02-02 12:01:11 +01:00
|
|
|
m_buildTarget(source->m_buildTarget),
|
2010-01-19 13:41:02 +01:00
|
|
|
m_title(source->m_title),
|
2010-06-09 13:21:08 +02:00
|
|
|
m_enabled(source->m_enabled)
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
|
|
|
|
ctor();
|
2009-11-26 14:43:27 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
void CMakeRunConfiguration::ctor()
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2010-08-19 12:26:21 +02:00
|
|
|
setDefaultDisplayName(defaultDisplayName());
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
2010-01-19 13:41:02 +01:00
|
|
|
|
2016-01-25 15:00:20 +01:00
|
|
|
Runnable CMakeRunConfiguration::runnable() const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
StandardRunnable r;
|
|
|
|
|
r.executable = m_buildTarget;
|
|
|
|
|
r.commandLineArguments = extraAspect<ArgumentsAspect>()->arguments();
|
|
|
|
|
r.workingDirectory = extraAspect<WorkingDirectoryAspect>()->workingDirectory().toString();
|
|
|
|
|
r.environment = extraAspect<LocalEnvironmentAspect>()->environment();
|
|
|
|
|
r.runMode = extraAspect<TerminalAspect>()->runMode();
|
|
|
|
|
return r;
|
2010-09-27 15:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeRunConfiguration::baseWorkingDirectory() const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
const QString exe = m_buildTarget;
|
2015-12-16 12:10:11 +01:00
|
|
|
if (!exe.isEmpty())
|
2016-01-25 15:00:20 +01:00
|
|
|
return QFileInfo(m_buildTarget).absolutePath();
|
2015-12-16 12:10:11 +01:00
|
|
|
return QString();
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-16 17:33:05 +01:00
|
|
|
QString CMakeRunConfiguration::title() const
|
|
|
|
|
{
|
|
|
|
|
return m_title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunConfiguration::setExecutable(const QString &executable)
|
|
|
|
|
{
|
2010-02-02 12:01:11 +01:00
|
|
|
m_buildTarget = executable;
|
2009-03-16 17:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-13 12:02:52 +02:00
|
|
|
void CMakeRunConfiguration::setBaseWorkingDirectory(const Utils::FileName &wd)
|
2009-03-16 17:33:05 +01:00
|
|
|
{
|
2016-10-13 12:02:52 +02:00
|
|
|
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(wd);
|
2009-03-16 17:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QVariantMap CMakeRunConfiguration::toMap() const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
QVariantMap map(RunConfiguration::toMap());
|
2010-01-19 13:41:02 +01:00
|
|
|
map.insert(QLatin1String(TITLE_KEY), m_title);
|
|
|
|
|
return map;
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
m_title = map.value(QLatin1String(TITLE_KEY)).toString();
|
|
|
|
|
return RunConfiguration::fromMap(map);
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-19 12:26:21 +02:00
|
|
|
QString CMakeRunConfiguration::defaultDisplayName() const
|
|
|
|
|
{
|
|
|
|
|
if (m_title.isEmpty())
|
2012-10-19 17:07:26 +02:00
|
|
|
return tr("Run CMake kit");
|
2013-10-17 14:52:10 +02:00
|
|
|
QString result = m_title;
|
|
|
|
|
if (!m_enabled) {
|
|
|
|
|
result += QLatin1Char(' ');
|
|
|
|
|
result += tr("(disabled)");
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2010-08-19 12:26:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-16 11:46:47 +02:00
|
|
|
QWidget *CMakeRunConfiguration::createConfigurationWidget()
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2009-05-27 17:28:50 +02:00
|
|
|
return new CMakeRunConfigurationWidget(this);
|
2009-03-25 18:29:42 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-09 13:21:08 +02:00
|
|
|
void CMakeRunConfiguration::setEnabled(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (m_enabled == b)
|
|
|
|
|
return;
|
|
|
|
|
m_enabled = b;
|
2012-03-29 13:11:00 +02:00
|
|
|
emit enabledChanged();
|
2010-08-19 12:26:21 +02:00
|
|
|
setDefaultDisplayName(defaultDisplayName());
|
2010-06-09 13:21:08 +02:00
|
|
|
}
|
2009-05-27 17:28:50 +02:00
|
|
|
|
2011-05-26 15:33:24 +02:00
|
|
|
bool CMakeRunConfiguration::isEnabled() const
|
2010-06-09 13:21:08 +02:00
|
|
|
{
|
2011-05-26 15:33:24 +02:00
|
|
|
return m_enabled;
|
2010-06-09 13:21:08 +02:00
|
|
|
}
|
2009-05-27 17:28:50 +02:00
|
|
|
|
2011-05-26 16:30:35 +02:00
|
|
|
QString CMakeRunConfiguration::disabledReason() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_enabled)
|
2012-01-31 11:03:22 +01:00
|
|
|
return tr("The executable is not built by the current build configuration");
|
2011-05-26 16:30:35 +02:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 13:21:08 +02:00
|
|
|
// Configuration widget
|
2009-05-27 17:28:50 +02:00
|
|
|
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
|
2015-12-16 12:10:11 +01:00
|
|
|
: QWidget(parent)
|
2009-05-27 17:28:50 +02:00
|
|
|
{
|
2015-12-16 12:10:11 +01:00
|
|
|
auto fl = new QFormLayout();
|
2009-07-23 17:00:38 +02:00
|
|
|
fl->setMargin(0);
|
|
|
|
|
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
2015-04-30 13:11:25 +02:00
|
|
|
|
|
|
|
|
cmakeRunConfiguration->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, fl);
|
2015-12-16 12:10:11 +01:00
|
|
|
cmakeRunConfiguration->extraAspect<WorkingDirectoryAspect>()->addToMainConfigurationWidget(this, fl);
|
|
|
|
|
cmakeRunConfiguration->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, fl);
|
2009-05-27 17:28:50 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
auto detailsContainer = new Utils::DetailsWidget(this);
|
|
|
|
|
detailsContainer->setState(Utils::DetailsWidget::NoSummary);
|
2009-06-16 18:37:16 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
auto detailsWidget = new QWidget(detailsContainer);
|
|
|
|
|
detailsContainer->setWidget(detailsWidget);
|
|
|
|
|
detailsWidget->setLayout(fl);
|
2011-04-27 16:33:21 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
auto vbx = new QVBoxLayout(this);
|
2013-09-03 18:48:02 +02:00
|
|
|
vbx->setMargin(0);
|
2015-12-16 12:10:11 +01:00
|
|
|
vbx->addWidget(detailsContainer);
|
2009-06-16 18:37:16 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
setEnabled(cmakeRunConfiguration->isEnabled());
|
2013-01-29 18:00:30 +01:00
|
|
|
}
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2008-12-09 14:53:06 +01:00
|
|
|
// Factory
|
2010-01-19 13:41:02 +01:00
|
|
|
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
|
2014-05-26 22:13:14 +03:00
|
|
|
IRunConfigurationFactory(parent)
|
2012-04-24 15:49:09 +02:00
|
|
|
{ setObjectName(QLatin1String("CMakeRunConfigurationFactory")); }
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
// used to show the list of possible additons to a project, returns a list of ids
|
2014-06-12 16:24:52 +02:00
|
|
|
QList<Core::Id> CMakeRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2014-06-12 16:24:52 +02:00
|
|
|
Q_UNUSED(mode)
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2012-03-15 17:17:40 +01:00
|
|
|
return QList<Core::Id>();
|
2012-07-04 12:20:13 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
2012-03-15 17:17:40 +01:00
|
|
|
QList<Core::Id> allIds;
|
2013-02-16 14:18:39 +01:00
|
|
|
foreach (const QString &buildTarget, project->buildTargetTitles(true))
|
2010-02-02 12:01:11 +01:00
|
|
|
allIds << idFromBuildTarget(buildTarget);
|
2010-01-19 13:41:02 +01:00
|
|
|
return allIds;
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
// used to translate the ids to names to display to the user
|
2014-07-01 11:08:26 +02:00
|
|
|
QString CMakeRunConfigurationFactory::displayNameForId(Core::Id id) const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2010-02-02 12:01:11 +01:00
|
|
|
return buildTargetFromId(id);
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
bool CMakeRunConfigurationFactory::canHandle(Target *parent) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
if (!parent->project()->supportsKit(parent->kit()))
|
2012-04-24 15:49:09 +02:00
|
|
|
return false;
|
|
|
|
|
return qobject_cast<CMakeProject *>(parent->project());
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
bool CMakeRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2010-01-19 13:41:02 +01:00
|
|
|
return false;
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
|
|
|
|
return project->hasBuildTarget(buildTargetFromId(id));
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
RunConfiguration *CMakeRunConfigurationFactory::doCreate(Target *parent, Core::Id id)
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
2010-02-02 12:01:11 +01:00
|
|
|
const QString title(buildTargetFromId(id));
|
2012-04-24 15:49:09 +02:00
|
|
|
const CMakeBuildTarget &ct = project->buildTargetForTitle(title);
|
2016-10-13 12:02:52 +02:00
|
|
|
return new CMakeRunConfiguration(parent, id, ct.executable.toString(), ct.workingDirectory, ct.title);
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
bool CMakeRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2010-01-19 13:41:02 +01:00
|
|
|
return false;
|
2013-03-21 16:22:27 +01:00
|
|
|
return source->id().name().startsWith(CMAKE_RC_PREFIX);
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
RunConfiguration *CMakeRunConfigurationFactory::clone(Target *parent, RunConfiguration * source)
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
|
|
|
|
if (!canClone(parent, source))
|
|
|
|
|
return 0;
|
|
|
|
|
CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
|
2012-04-24 15:49:09 +02:00
|
|
|
return new CMakeRunConfiguration(parent, crc);
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
bool CMakeRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!qobject_cast<CMakeProject *>(parent->project()))
|
2010-01-19 13:41:02 +01:00
|
|
|
return false;
|
2014-05-26 22:13:14 +03:00
|
|
|
return idFromMap(map).name().startsWith(CMAKE_RC_PREFIX);
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-26 22:13:14 +03:00
|
|
|
RunConfiguration *CMakeRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &map)
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
2016-10-13 12:02:52 +02:00
|
|
|
return new CMakeRunConfiguration(parent, idFromMap(map), QString(), Utils::FileName(), QString());
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
2012-07-17 15:56:43 +02:00
|
|
|
|
|
|
|
|
QString CMakeRunConfigurationFactory::buildTargetFromId(Core::Id id)
|
|
|
|
|
{
|
2013-03-21 16:22:27 +01:00
|
|
|
return id.suffixAfter(CMAKE_RC_PREFIX);
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Id CMakeRunConfigurationFactory::idFromBuildTarget(const QString &target)
|
|
|
|
|
{
|
2013-03-21 16:22:27 +01:00
|
|
|
return Core::Id(CMAKE_RC_PREFIX).withSuffix(target);
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|