Files
qt-creator/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp

254 lines
8.6 KiB
C++
Raw Normal View History

/****************************************************************************
**
** 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.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
#include "cmakerunconfiguration.h"
2008-12-09 15:25:01 +01:00
#include "cmakebuildconfiguration.h"
#include "cmakeproject.h"
2008-12-09 15:25:01 +01:00
#include "cmakeprojectconstants.h"
#include <coreplugin/coreicons.h>
#include <coreplugin/helpmanager.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtoutputformatter.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
2011-02-28 16:50:14 +01:00
#include <utils/detailswidget.h>
#include <utils/fancylineedit.h>
#include <utils/hostosinfo.h>
#include <utils/pathchooser.h>
2008-12-09 15:25:01 +01:00
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/stringutils.h>
2011-02-28 16:50:14 +01:00
#include <QFormLayout>
#include <QLineEdit>
#include <QGroupBox>
#include <QLabel>
#include <QComboBox>
#include <QToolButton>
#include <QCheckBox>
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
using namespace ProjectExplorer;
namespace {
const char CMAKE_RC_PREFIX[] = "CMakeProjectManager.CMakeRunConfiguration.";
const char TITLE_KEY[] = "CMakeProjectManager.CMakeRunConfiguation.Title";
} // namespace
CMakeRunConfiguration::CMakeRunConfiguration(Target *target)
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup This follow the rough pattern of recent *RunConfigurationFactory changes for build and deploy configurations. - Collapse the two lines of constructors similar to what 890c1906e6fb2ec did for RunConfigurations * Deploy* was purely mechanical * Build* ctors are split in connects() in the ctor body to create "empty shell for clone" etc and build step additions in initialize() functions which are only used in the create() case. -- Allows to collapse the shared 'ctor()' functions, too. - Move FooBuildConfigurationFactory::create() implementations to FooBuildConfiguration() constructor. That was a strange and unneeded ping-pong between factories and objects, and furthermore allows one level less of indirection (and for a later, left out here, some reduction of the FooBuildConfiguration interfaces that were only used to accommodate the *Factory::create() functions. - Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(), but there wasn't one in the base classses. Have one there. - Most canHandle() functions were checking simple restrictions on e.g. project or target types, specify those by setters in the constructors instead and check them in the base canHandle() - clone() is generally replaced by a creation of a "shell object" and a fromMap(source->toMap()), implemented in the base, there are two cases left for Android and Qbs that needed(?) some extra polish - generally use canHandle() in base implementation, instead of doing that in all Derived::canFoo() - as a result, canCreate/create/canClone/clone reimplementations are not needed anymore, keep the base implementation for now (could be inlined into their only users later), but de-virtualize them. - Combine Ios{Preset,DSym}BuildStepFactory. There was only one 'dsym' build step they could create. - Split the 'mangled' id into the ProjectConfiguration subtype specific constant identifier, and a QString extraId() bit. Only maintain the mangled id in saved settings. - Make ProjectConfiguration::m_id a constant member, adapt all constructors of derived classe. Not done in this patch: - Finish possible cosmetic changes on top - Add a way to specify restrictions to supported Qt versions (used in Android/Ios), as the base implementation does not depend on the qtsupport plugin - Combine the QList<X> availableFoo() + createFoo(X) function pairs to somthing like a direct QList<struct { X; std::function<X()>; }> fooCreators() to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base) pingpong - Remove the *Factories from the global object pool - Do something about priority(). Falling back to plain qmake in android+qmake setup is not helpful. Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:28:40 +01:00
: RunConfiguration(target, CMAKE_RC_PREFIX)
{
// Workaround for QTCREATORBUG-19354:
auto cmakeRunEnvironmentModifier = [](RunConfiguration *rc, Utils::Environment &env) {
if (!Utils::HostOsInfo::isWindowsHost() || !rc)
return;
const Kit *k = rc->target()->kit();
const QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(k);
if (qt)
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS"));
};
addExtraAspect(new LocalEnvironmentAspect(this, cmakeRunEnvironmentModifier));
addExtraAspect(new ArgumentsAspect(this, "CMakeProjectManager.CMakeRunConfiguration.Arguments"));
addExtraAspect(new TerminalAspect(this, "CMakeProjectManager.CMakeRunConfiguration.UseTerminal"));
addExtraAspect(new WorkingDirectoryAspect(this, "CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"));
}
2009-11-26 14:43:27 +01:00
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup This follow the rough pattern of recent *RunConfigurationFactory changes for build and deploy configurations. - Collapse the two lines of constructors similar to what 890c1906e6fb2ec did for RunConfigurations * Deploy* was purely mechanical * Build* ctors are split in connects() in the ctor body to create "empty shell for clone" etc and build step additions in initialize() functions which are only used in the create() case. -- Allows to collapse the shared 'ctor()' functions, too. - Move FooBuildConfigurationFactory::create() implementations to FooBuildConfiguration() constructor. That was a strange and unneeded ping-pong between factories and objects, and furthermore allows one level less of indirection (and for a later, left out here, some reduction of the FooBuildConfiguration interfaces that were only used to accommodate the *Factory::create() functions. - Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(), but there wasn't one in the base classses. Have one there. - Most canHandle() functions were checking simple restrictions on e.g. project or target types, specify those by setters in the constructors instead and check them in the base canHandle() - clone() is generally replaced by a creation of a "shell object" and a fromMap(source->toMap()), implemented in the base, there are two cases left for Android and Qbs that needed(?) some extra polish - generally use canHandle() in base implementation, instead of doing that in all Derived::canFoo() - as a result, canCreate/create/canClone/clone reimplementations are not needed anymore, keep the base implementation for now (could be inlined into their only users later), but de-virtualize them. - Combine Ios{Preset,DSym}BuildStepFactory. There was only one 'dsym' build step they could create. - Split the 'mangled' id into the ProjectConfiguration subtype specific constant identifier, and a QString extraId() bit. Only maintain the mangled id in saved settings. - Make ProjectConfiguration::m_id a constant member, adapt all constructors of derived classe. Not done in this patch: - Finish possible cosmetic changes on top - Add a way to specify restrictions to supported Qt versions (used in Android/Ios), as the base implementation does not depend on the qtsupport plugin - Combine the QList<X> availableFoo() + createFoo(X) function pairs to somthing like a direct QList<struct { X; std::function<X()>; }> fooCreators() to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base) pingpong - Remove the *Factories from the global object pool - Do something about priority(). Falling back to plain qmake in android+qmake setup is not helpful. Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:28:40 +01:00
QString CMakeRunConfiguration::extraId() const
{
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup This follow the rough pattern of recent *RunConfigurationFactory changes for build and deploy configurations. - Collapse the two lines of constructors similar to what 890c1906e6fb2ec did for RunConfigurations * Deploy* was purely mechanical * Build* ctors are split in connects() in the ctor body to create "empty shell for clone" etc and build step additions in initialize() functions which are only used in the create() case. -- Allows to collapse the shared 'ctor()' functions, too. - Move FooBuildConfigurationFactory::create() implementations to FooBuildConfiguration() constructor. That was a strange and unneeded ping-pong between factories and objects, and furthermore allows one level less of indirection (and for a later, left out here, some reduction of the FooBuildConfiguration interfaces that were only used to accommodate the *Factory::create() functions. - Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(), but there wasn't one in the base classses. Have one there. - Most canHandle() functions were checking simple restrictions on e.g. project or target types, specify those by setters in the constructors instead and check them in the base canHandle() - clone() is generally replaced by a creation of a "shell object" and a fromMap(source->toMap()), implemented in the base, there are two cases left for Android and Qbs that needed(?) some extra polish - generally use canHandle() in base implementation, instead of doing that in all Derived::canFoo() - as a result, canCreate/create/canClone/clone reimplementations are not needed anymore, keep the base implementation for now (could be inlined into their only users later), but de-virtualize them. - Combine Ios{Preset,DSym}BuildStepFactory. There was only one 'dsym' build step they could create. - Split the 'mangled' id into the ProjectConfiguration subtype specific constant identifier, and a QString extraId() bit. Only maintain the mangled id in saved settings. - Make ProjectConfiguration::m_id a constant member, adapt all constructors of derived classe. Not done in this patch: - Finish possible cosmetic changes on top - Add a way to specify restrictions to supported Qt versions (used in Android/Ios), as the base implementation does not depend on the qtsupport plugin - Combine the QList<X> availableFoo() + createFoo(X) function pairs to somthing like a direct QList<struct { X; std::function<X()>; }> fooCreators() to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base) pingpong - Remove the *Factories from the global object pool - Do something about priority(). Falling back to plain qmake in android+qmake setup is not helpful. Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:28:40 +01:00
return m_buildSystemTarget;
}
Runnable CMakeRunConfiguration::runnable() const
{
StandardRunnable r;
r.executable = m_executable;
r.commandLineArguments = extraAspect<ArgumentsAspect>()->arguments();
r.workingDirectory = extraAspect<WorkingDirectoryAspect>()->workingDirectory().toString();
r.environment = extraAspect<LocalEnvironmentAspect>()->environment();
r.runMode = extraAspect<TerminalAspect>()->runMode();
return r;
}
QString CMakeRunConfiguration::baseWorkingDirectory() const
{
const QString exe = m_executable;
if (!exe.isEmpty())
return QFileInfo(m_executable).absolutePath();
return QString();
}
QString CMakeRunConfiguration::title() const
{
return m_title;
}
void CMakeRunConfiguration::setExecutable(const QString &executable)
{
m_executable = executable;
}
void CMakeRunConfiguration::setBaseWorkingDirectory(const Utils::FileName &wd)
{
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(wd);
}
QVariantMap CMakeRunConfiguration::toMap() const
{
QVariantMap map(RunConfiguration::toMap());
map.insert(QLatin1String(TITLE_KEY), m_title);
return map;
}
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
{
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup This follow the rough pattern of recent *RunConfigurationFactory changes for build and deploy configurations. - Collapse the two lines of constructors similar to what 890c1906e6fb2ec did for RunConfigurations * Deploy* was purely mechanical * Build* ctors are split in connects() in the ctor body to create "empty shell for clone" etc and build step additions in initialize() functions which are only used in the create() case. -- Allows to collapse the shared 'ctor()' functions, too. - Move FooBuildConfigurationFactory::create() implementations to FooBuildConfiguration() constructor. That was a strange and unneeded ping-pong between factories and objects, and furthermore allows one level less of indirection (and for a later, left out here, some reduction of the FooBuildConfiguration interfaces that were only used to accommodate the *Factory::create() functions. - Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(), but there wasn't one in the base classses. Have one there. - Most canHandle() functions were checking simple restrictions on e.g. project or target types, specify those by setters in the constructors instead and check them in the base canHandle() - clone() is generally replaced by a creation of a "shell object" and a fromMap(source->toMap()), implemented in the base, there are two cases left for Android and Qbs that needed(?) some extra polish - generally use canHandle() in base implementation, instead of doing that in all Derived::canFoo() - as a result, canCreate/create/canClone/clone reimplementations are not needed anymore, keep the base implementation for now (could be inlined into their only users later), but de-virtualize them. - Combine Ios{Preset,DSym}BuildStepFactory. There was only one 'dsym' build step they could create. - Split the 'mangled' id into the ProjectConfiguration subtype specific constant identifier, and a QString extraId() bit. Only maintain the mangled id in saved settings. - Make ProjectConfiguration::m_id a constant member, adapt all constructors of derived classe. Not done in this patch: - Finish possible cosmetic changes on top - Add a way to specify restrictions to supported Qt versions (used in Android/Ios), as the base implementation does not depend on the qtsupport plugin - Combine the QList<X> availableFoo() + createFoo(X) function pairs to somthing like a direct QList<struct { X; std::function<X()>; }> fooCreators() to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base) pingpong - Remove the *Factories from the global object pool - Do something about priority(). Falling back to plain qmake in android+qmake setup is not helpful. Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:28:40 +01:00
RunConfiguration::fromMap(map);
m_title = map.value(QLatin1String(TITLE_KEY)).toString();
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup This follow the rough pattern of recent *RunConfigurationFactory changes for build and deploy configurations. - Collapse the two lines of constructors similar to what 890c1906e6fb2ec did for RunConfigurations * Deploy* was purely mechanical * Build* ctors are split in connects() in the ctor body to create "empty shell for clone" etc and build step additions in initialize() functions which are only used in the create() case. -- Allows to collapse the shared 'ctor()' functions, too. - Move FooBuildConfigurationFactory::create() implementations to FooBuildConfiguration() constructor. That was a strange and unneeded ping-pong between factories and objects, and furthermore allows one level less of indirection (and for a later, left out here, some reduction of the FooBuildConfiguration interfaces that were only used to accommodate the *Factory::create() functions. - Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(), but there wasn't one in the base classses. Have one there. - Most canHandle() functions were checking simple restrictions on e.g. project or target types, specify those by setters in the constructors instead and check them in the base canHandle() - clone() is generally replaced by a creation of a "shell object" and a fromMap(source->toMap()), implemented in the base, there are two cases left for Android and Qbs that needed(?) some extra polish - generally use canHandle() in base implementation, instead of doing that in all Derived::canFoo() - as a result, canCreate/create/canClone/clone reimplementations are not needed anymore, keep the base implementation for now (could be inlined into their only users later), but de-virtualize them. - Combine Ios{Preset,DSym}BuildStepFactory. There was only one 'dsym' build step they could create. - Split the 'mangled' id into the ProjectConfiguration subtype specific constant identifier, and a QString extraId() bit. Only maintain the mangled id in saved settings. - Make ProjectConfiguration::m_id a constant member, adapt all constructors of derived classe. Not done in this patch: - Finish possible cosmetic changes on top - Add a way to specify restrictions to supported Qt versions (used in Android/Ios), as the base implementation does not depend on the qtsupport plugin - Combine the QList<X> availableFoo() + createFoo(X) function pairs to somthing like a direct QList<struct { X; std::function<X()>; }> fooCreators() to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base) pingpong - Remove the *Factories from the global object pool - Do something about priority(). Falling back to plain qmake in android+qmake setup is not helpful. Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:28:40 +01:00
QString extraId = ProjectExplorer::idFromMap(map).suffixAfter(id());
if (!extraId.isEmpty()) {
m_buildSystemTarget = extraId;
m_executable = extraId;
if (m_title.isEmpty())
m_title = extraId;
CMakeProject *project = static_cast<CMakeProject *>(target()->project());
const CMakeBuildTarget ct = project->buildTargetForTitle(m_title);
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(ct.workingDirectory);
}
setDefaultDisplayName(defaultDisplayName());
return true;
}
QString CMakeRunConfiguration::defaultDisplayName() const
{
if (m_title.isEmpty())
return tr("Run CMake kit");
return m_title;
}
void CMakeRunConfiguration::updateEnabledState()
{
auto cp = qobject_cast<CMakeProject *>(target()->project());
if (!cp->hasBuildTarget(m_buildSystemTarget))
setEnabled(false);
else
RunConfiguration::updateEnabledState();
}
QWidget *CMakeRunConfiguration::createConfigurationWidget()
{
return new CMakeRunConfigurationWidget(this);
}
QString CMakeRunConfiguration::disabledReason() const
{
auto cp = qobject_cast<CMakeProject *>(target()->project());
QTC_ASSERT(cp, return QString());
if (!cp->hasBuildTarget(m_buildSystemTarget))
return tr("The project no longer builds the target associated with this run configuration.");
return RunConfiguration::disabledReason();
}
Utils::OutputFormatter *CMakeRunConfiguration::createOutputFormatter() const
{
if (QtSupport::QtKitInformation::qtVersion(target()->kit()))
return new QtSupport::QtOutputFormatter(target()->project());
return RunConfiguration::createOutputFormatter();
}
static void updateExecutable(CMakeRunConfiguration *rc, Utils::FancyLineEdit *fle)
{
const Runnable runnable = rc->runnable();
fle->setText(runnable.is<StandardRunnable>()
? Utils::FileName::fromString(runnable.as<StandardRunnable>().executable).toUserOutput()
: QString());
}
// Configuration widget
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
: QWidget(parent)
{
auto fl = new QFormLayout();
fl->setMargin(0);
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
auto executableLabel = new QLabel(tr("Executable:"));
auto executable = new Utils::FancyLineEdit;
executable->setReadOnly(true);
executable->setPlaceholderText(tr("<unknown>"));
connect(cmakeRunConfiguration, &CMakeRunConfiguration::enabledChanged,
this, std::bind(updateExecutable, cmakeRunConfiguration, executable));
updateExecutable(cmakeRunConfiguration, executable);
fl->addRow(executableLabel, executable);
cmakeRunConfiguration->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, fl);
cmakeRunConfiguration->extraAspect<WorkingDirectoryAspect>()->addToMainConfigurationWidget(this, fl);
cmakeRunConfiguration->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, fl);
auto detailsContainer = new Utils::DetailsWidget(this);
detailsContainer->setState(Utils::DetailsWidget::NoSummary);
auto detailsWidget = new QWidget(detailsContainer);
detailsContainer->setWidget(detailsWidget);
detailsWidget->setLayout(fl);
auto vbx = new QVBoxLayout(this);
vbx->setMargin(0);
vbx->addWidget(detailsContainer);
}
// Factory
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
IRunConfigurationFactory(parent)
{
setObjectName("CMakeRunConfigurationFactory");
registerRunConfiguration<CMakeRunConfiguration>(CMAKE_RC_PREFIX);
setSupportedProjectType<CMakeProject>();
}
QList<QString> CMakeRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode) const
{
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
return project->buildTargetTitles(true);
}
bool CMakeRunConfigurationFactory::canCreateHelper(Target *parent, const QString &buildTarget) const
{
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
return project->hasBuildTarget(buildTarget);
}