Files
qt-creator/src/plugins/projectexplorer/runconfiguration.cpp

619 lines
20 KiB
C++
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01: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 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
**
****************************************************************************/
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "runconfiguration.h"
#include "abi.h"
#include "buildconfiguration.h"
#include "buildsystem.h"
#include "environmentaspect.h"
#include "kitinformation.h"
#include "kitinformation.h"
#include "project.h"
#include "projectexplorer.h"
#include "projectnodes.h"
#include "runconfigurationaspects.h"
#include "runcontrol.h"
#include "session.h"
#include "target.h"
#include "toolchain.h"
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/detailswidget.h>
#include <utils/outputformatter.h>
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/variablechooser.h>
#include <QDir>
#include <QFormLayout>
#include <QHash>
#include <QPushButton>
#include <QTimer>
#include <QLoggingCategory>
#include <QSettings>
2008-12-02 12:01:29 +01:00
using namespace Utils;
using namespace ProjectExplorer::Internal;
namespace ProjectExplorer {
const char BUILD_KEY[] = "ProjectExplorer.RunConfiguration.BuildKey";
///////////////////////////////////////////////////////////////////////
//
// ISettingsAspect
//
///////////////////////////////////////////////////////////////////////
ISettingsAspect::ISettingsAspect() = default;
QWidget *ISettingsAspect::createConfigWidget() const
{
QTC_ASSERT(m_configWidgetCreator, return nullptr);
return m_configWidgetCreator();
}
void ISettingsAspect::setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator)
{
m_configWidgetCreator = configWidgetCreator;
}
///////////////////////////////////////////////////////////////////////
//
// IRunConfigurationAspect
//
///////////////////////////////////////////////////////////////////////
GlobalOrProjectAspect::GlobalOrProjectAspect() = default;
GlobalOrProjectAspect::~GlobalOrProjectAspect()
{
delete m_projectSettings;
}
void GlobalOrProjectAspect::setProjectSettings(ISettingsAspect *settings)
{
m_projectSettings = settings;
}
void GlobalOrProjectAspect::setGlobalSettings(ISettingsAspect *settings)
{
m_globalSettings = settings;
}
void GlobalOrProjectAspect::setUsingGlobalSettings(bool value)
{
m_useGlobalSettings = value;
}
ISettingsAspect *GlobalOrProjectAspect::currentSettings() const
{
return m_useGlobalSettings ? m_globalSettings : m_projectSettings;
}
void GlobalOrProjectAspect::fromMap(const QVariantMap &map)
{
if (m_projectSettings)
m_projectSettings->fromMap(map);
m_useGlobalSettings = map.value(m_id.toString() + QLatin1String(".UseGlobalSettings"), true).toBool();
}
void GlobalOrProjectAspect::toMap(QVariantMap &map) const
{
if (m_projectSettings)
m_projectSettings->toMap(map);
map.insert(m_id.toString() + QLatin1String(".UseGlobalSettings"), m_useGlobalSettings);
}
void GlobalOrProjectAspect::resetProjectToGlobalSettings()
{
QTC_ASSERT(m_globalSettings, return);
QVariantMap map;
m_globalSettings->toMap(map);
if (m_projectSettings)
m_projectSettings->fromMap(map);
}
/*!
\class ProjectExplorer::RunConfiguration
\brief The RunConfiguration class is the base class for a run configuration.
A run configuration specifies how a target should be run, while a runner
does the actual running.
The target owns the RunConfiguraitons and a RunControl will need to copy all
necessary data as the RunControl may continue to exist after the RunConfiguration
has been destroyed.
A RunConfiguration disables itself if the project has no parsing
data available. The disabledReason() method can be used to get a user-facing string
describing why the RunConfiguration considers itself unfit for use.
*/
static std::vector<RunConfiguration::AspectFactory> theAspectFactories;
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::RunConfiguration(Target *target, Core::Id id)
: ProjectConfiguration(target, id)
2008-12-02 12:01:29 +01:00
{
QTC_CHECK(target && target == this->target());
connect(target, &Target::parsingFinished, this, &RunConfiguration::enabledChanged);
connect(this, &RunConfiguration::enabledChanged, this, [this] {
if (isActive() && project() == SessionManager::startupProject())
emit ProjectExplorerPlugin::instance()->updateRunActions();
});
Utils::MacroExpander *expander = macroExpander();
expander->setDisplayName(tr("Run Settings"));
expander->setAccumulating(true);
expander->registerSubProvider([target] {
BuildConfiguration *bc = target->activeBuildConfiguration();
return bc ? bc->macroExpander() : target->macroExpander();
});
expander->registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
[this](const QString &var) {
const auto envAspect = aspect<EnvironmentAspect>();
return envAspect ? envAspect->environment().expandedValueForKey(var) : QString();
});
expander->registerVariable(Constants::VAR_CURRENTRUN_WORKINGDIR,
tr("The currently active run configuration's working directory"),
[this, expander] {
const auto wdAspect = aspect<WorkingDirectoryAspect>();
return wdAspect ? wdAspect->workingDirectory(expander).toString() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTRUN_NAME,
QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."),
[this] { return displayName(); }, false);
m_commandLineGetter = [this] {
FilePath executable;
if (const auto executableAspect = aspect<ExecutableAspect>())
executable = executableAspect->executable();
QString arguments;
if (const auto argumentsAspect = aspect<ArgumentsAspect>())
arguments = argumentsAspect->arguments(macroExpander());
return CommandLine{executable, arguments, CommandLine::Raw};
};
}
RunConfiguration::~RunConfiguration() = default;
bool RunConfiguration::isActive() const
{
return target()->isActive() && target()->activeRunConfiguration() == this;
}
QString RunConfiguration::disabledReason() const
{
BuildSystem *bs = activeBuildSystem();
return bs ? bs->disabledReason(m_buildKey) : tr("No build system active");
}
bool RunConfiguration::isEnabled() const
{
BuildSystem *bs = activeBuildSystem();
return bs && bs->hasParsingData();
}
QWidget *RunConfiguration::createConfigurationWidget()
{
auto widget = new QWidget;
{
LayoutBuilder builder(widget);
for (ProjectConfigurationAspect *aspect : m_aspects) {
if (aspect->isVisible())
aspect->addToLayout(builder.startNewRow());
}
}
Core::VariableChooser::addSupportForChildWidgets(widget, macroExpander());
auto detailsWidget = new Utils::DetailsWidget;
detailsWidget->setState(DetailsWidget::NoSummary);
detailsWidget->setWidget(widget);
return detailsWidget;
}
void RunConfiguration::addAspectFactory(const AspectFactory &aspectFactory)
{
theAspectFactories.push_back(aspectFactory);
2008-12-02 12:01:29 +01:00
}
QMap<Core::Id, QVariantMap> RunConfiguration::aspectData() const
{
QMap<Core::Id, QVariantMap> data;
for (ProjectConfigurationAspect *aspect : m_aspects)
aspect->toMap(data[aspect->id()]);
return data;
}
BuildConfiguration *RunConfiguration::activeBuildConfiguration() const
2008-12-02 12:01:29 +01:00
{
return target()->activeBuildConfiguration();
2008-12-02 12:01:29 +01:00
}
BuildSystem *RunConfiguration::activeBuildSystem() const
{
return target()->buildSystem();
}
void RunConfiguration::setUpdater(const Updater &updater)
{
m_updater = updater;
}
Task RunConfiguration::createConfigurationIssue(const QString &description) const
{
return {Task::Error, description, FilePath(), -1, Constants::TASK_CATEGORY_BUILDSYSTEM};
}
QVariantMap RunConfiguration::toMap() const
{
QVariantMap map = ProjectConfiguration::toMap();
map.insert(BUILD_KEY, m_buildKey);
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
// FIXME: Remove this id mangling, e.g. by using a separate entry for the build key.
if (!m_buildKey.isEmpty()) {
const Core::Id mangled = id().withSuffix(m_buildKey);
map.insert(settingsIdKey(), mangled.toSetting());
}
return map;
}
void RunConfiguration::setCommandLineGetter(const CommandLineGetter &cmdGetter)
{
m_commandLineGetter = cmdGetter;
}
CommandLine RunConfiguration::commandLine() const
{
return m_commandLineGetter();
}
void RunConfiguration::update()
{
if (m_updater)
m_updater();
emit enabledChanged();
}
BuildTargetInfo RunConfiguration::buildTargetInfo() const
{
BuildSystem *bs = target()->buildSystem();
QTC_ASSERT(bs, return {});
return bs->buildTarget(m_buildKey);
}
ProjectNode *RunConfiguration::productNode() const
{
return project()->rootProjectNode()->findProjectNode([this](const ProjectNode *candidate) {
return candidate->buildKey() == buildKey();
});
}
bool RunConfiguration::fromMap(const QVariantMap &map)
{
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
if (!ProjectConfiguration::fromMap(map))
return false;
m_buildKey = map.value(BUILD_KEY).toString();
if (m_buildKey.isEmpty()) {
const Core::Id mangledId = Core::Id::fromSetting(map.value(settingsIdKey()));
m_buildKey = mangledId.suffixAfter(id());
// Hack for cmake projects 4.10 -> 4.11.
const QString magicSeparator = "///::///";
const int magicIndex = m_buildKey.indexOf(magicSeparator);
if (magicIndex != -1)
m_buildKey = m_buildKey.mid(magicIndex + magicSeparator.length());
}
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
return true;
}
/*!
\class ProjectExplorer::IRunConfigurationAspect
\brief The IRunConfigurationAspect class provides an additional
configuration aspect.
Aspects are a mechanism to add RunControl-specific options to a run
configuration without subclassing the run configuration for every addition.
This prevents a combinatorial explosion of subclasses and eliminates
the need to add all options to the base class.
*/
/*!
\internal
\class ProjectExplorer::Runnable
\brief The ProjectExplorer::Runnable class wraps information needed
to execute a process on a target device.
A target specific \l RunConfiguration implementation can specify
what information it considers necessary to execute a process
on the target. Target specific) \n RunWorker implementation
can use that information either unmodified or tweak it or ignore
it when setting up a RunControl.
From Qt Creator's core perspective a Runnable object is opaque.
*/
/*!
\internal
\brief Returns a \l Runnable described by this RunConfiguration.
*/
Runnable RunConfiguration::runnable() const
{
Runnable r;
r.setCommandLine(commandLine());
if (auto workingDirectoryAspect = aspect<WorkingDirectoryAspect>())
r.workingDirectory = workingDirectoryAspect->workingDirectory(macroExpander()).toString();
if (auto environmentAspect = aspect<EnvironmentAspect>())
r.environment = environmentAspect->environment();
return r;
}
/*!
\class ProjectExplorer::IRunConfigurationFactory
\brief The IRunConfigurationFactory class restores run configurations from
settings.
The run configuration factory is used for restoring run configurations from
settings and for creating new run configurations in the \gui {Run Settings}
dialog.
To restore run configurations, use the
\c {bool canRestore(Target *parent, const QString &id)}
and \c {RunConfiguration* create(Target *parent, const QString &id)}
functions.
To generate a list of creatable run configurations, use the
\c {QStringList availableCreationIds(Target *parent)} and
\c {QString displayNameForType(const QString&)} functions. To create a
run configuration, use \c create().
*/
/*!
\fn QStringList ProjectExplorer::IRunConfigurationFactory::availableCreationIds(Target *parent) const
Shows the list of possible additions to a target. Returns a list of types.
*/
/*!
\fn QString ProjectExplorer::IRunConfigurationFactory::displayNameForId(Core::Id id) const
Translates the types to names to display to the user.
*/
static QList<RunConfigurationFactory *> g_runConfigurationFactories;
RunConfigurationFactory::RunConfigurationFactory()
2008-12-02 12:01:29 +01:00
{
g_runConfigurationFactories.append(this);
}
RunConfigurationFactory::~RunConfigurationFactory()
{
g_runConfigurationFactories.removeOne(this);
}
QString RunConfigurationFactory::decoratedTargetName(const QString &targetName, Target *target)
{
QString displayName;
if (!targetName.isEmpty())
displayName = QFileInfo(targetName).completeBaseName();
Core::Id devType = DeviceTypeKitAspect::deviceTypeId(target->kit());
if (devType != Constants::DESKTOP_DEVICE_TYPE) {
if (IDevice::ConstPtr dev = DeviceKitAspect::device(target->kit())) {
if (displayName.isEmpty()) {
//: Shown in Run configuration if no executable is given, %1 is device name
displayName = RunConfiguration::tr("Run on %1").arg(dev->displayName());
} else {
//: Shown in Run configuration, Add menu: "name of runnable (on device name)"
displayName = RunConfiguration::tr("%1 (on %2)").arg(displayName, dev->displayName());
}
}
}
return displayName;
}
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
QList<RunConfigurationCreationInfo>
RunConfigurationFactory::availableCreators(Target *parent) const
{
const QList<BuildTargetInfo> buildTargets = parent->applicationTargets();
const bool hasAnyQtcRunnable = Utils::anyOf(buildTargets,
Utils::equal(&BuildTargetInfo::isQtcRunnable, true));
return Utils::transform(buildTargets, [&](const BuildTargetInfo &ti) {
QString displayName = ti.displayName;
if (displayName.isEmpty())
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
displayName = decoratedTargetName(ti.buildKey, parent);
else if (m_decorateDisplayNames)
displayName = decoratedTargetName(displayName, parent);
RunConfigurationCreationInfo rci;
rci.factory = this;
rci.id = m_runConfigBaseId;
rci.buildKey = ti.buildKey;
rci.projectFilePath = ti.projectFilePath;
rci.displayName = displayName;
rci.displayNameUniquifier = ti.displayNameUniquifier;
rci.creationMode = ti.isQtcRunnable || !hasAnyQtcRunnable
? RunConfigurationCreationInfo::AlwaysCreate
: RunConfigurationCreationInfo::ManualCreationOnly;
rci.useTerminal = ti.usesTerminal;
rci.buildKey = ti.buildKey;
return rci;
});
}
/*!
Adds a list of device types for which this RunConfigurationFactory
can create RunConfigurations.
If this function is never called for a RunConfiguarionFactory,
the factory will create RunConfigurations for all device types.
*/
void RunConfigurationFactory::addSupportedTargetDeviceType(Core::Id id)
{
m_supportedTargetDeviceTypes.append(id);
}
void RunConfigurationFactory::setDecorateDisplayNames(bool on)
{
m_decorateDisplayNames = on;
}
void RunConfigurationFactory::addSupportedProjectType(Core::Id id)
{
m_supportedProjectTypes.append(id);
}
bool RunConfigurationFactory::canHandle(Target *target) const
{
const Project *project = target->project();
Kit *kit = target->kit();
if (containsType(target->project()->projectIssues(kit), Task::TaskType::Error))
return false;
if (!m_supportedProjectTypes.isEmpty())
if (!m_supportedProjectTypes.contains(project->id()))
return false;
if (!m_supportedTargetDeviceTypes.isEmpty())
if (!m_supportedTargetDeviceTypes.contains(
DeviceTypeKitAspect::deviceTypeId(kit)))
return false;
return true;
}
RunConfiguration *RunConfigurationFactory::create(Target *target) const
{
QTC_ASSERT(m_creator, return nullptr);
RunConfiguration *rc = m_creator(target);
QTC_ASSERT(rc, return nullptr);
// Add the universal aspects.
for (const RunConfiguration::AspectFactory &factory : theAspectFactories)
rc->m_aspects.append(factory(target));
rc->acquaintAspects();
return rc;
}
RunConfiguration *RunConfigurationCreationInfo::create(Target *target) const
{
QTC_ASSERT(factory->canHandle(target), return nullptr);
QTC_ASSERT(id == factory->runConfigurationBaseId(), return nullptr);
RunConfiguration *rc = factory->create(target);
if (!rc)
return nullptr;
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
rc->m_buildKey = buildKey;
rc->doAdditionalSetup(*this);
rc->setDisplayName(displayName);
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 rc;
}
RunConfiguration *RunConfigurationFactory::restore(Target *parent, const QVariantMap &map)
{
for (RunConfigurationFactory *factory : g_runConfigurationFactories) {
if (factory->canHandle(parent)) {
const Core::Id id = idFromMap(map);
if (id.name().startsWith(factory->m_runConfigBaseId.name())) {
RunConfiguration *rc = factory->create(parent);
if (rc->fromMap(map))
return rc;
delete rc;
return nullptr;
}
}
}
return nullptr;
}
RunConfiguration *RunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
{
return restore(parent, source->toMap());
}
const QList<RunConfigurationCreationInfo> RunConfigurationFactory::creatorsForTarget(Target *parent)
{
QList<RunConfigurationCreationInfo> items;
for (RunConfigurationFactory *factory : g_runConfigurationFactories) {
if (factory->canHandle(parent))
items.append(factory->availableCreators(parent));
}
QHash<QString, QList<RunConfigurationCreationInfo *>> itemsPerDisplayName;
for (RunConfigurationCreationInfo &item : items)
itemsPerDisplayName[item.displayName] << &item;
for (auto it = itemsPerDisplayName.cbegin(); it != itemsPerDisplayName.cend(); ++it) {
if (it.value().size() == 1)
continue;
for (RunConfigurationCreationInfo * const rci : it.value())
rci->displayName += rci->displayNameUniquifier;
}
return items;
}
FixedRunConfigurationFactory::FixedRunConfigurationFactory(const QString &displayName,
bool addDeviceName) :
m_fixedBuildTarget(displayName),
m_decorateTargetName(addDeviceName)
{ }
QList<RunConfigurationCreationInfo>
FixedRunConfigurationFactory::availableCreators(Target *parent) const
{
QString displayName = m_decorateTargetName ? decoratedTargetName(m_fixedBuildTarget, parent)
: m_fixedBuildTarget;
RunConfigurationCreationInfo rci;
rci.factory = this;
rci.id = runConfigurationBaseId();
rci.displayName = displayName;
return {rci};
}
} // namespace ProjectExplorer