forked from qt-creator/qt-creator
BareMetal: Split runconfigs into independent classes
Since the need for code reuse is gone due to the recent changes in the RunConfiguration base infrastructure, it's easier and less code to completely separate the cases. Change-Id: I3fc558ea60e02f34b50869d4b55a43a6360e9208 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -29,10 +29,8 @@
|
||||
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/runconfigurationaspects.h>
|
||||
#include <qtsupport/qtoutputformatter.h>
|
||||
#include <utils/pathchooser.h>
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <qtsupport/qtoutputformatter.h>
|
||||
|
||||
using namespace Utils;
|
||||
using namespace ProjectExplorer;
|
||||
@@ -40,45 +38,27 @@ using namespace ProjectExplorer;
|
||||
namespace BareMetal {
|
||||
namespace Internal {
|
||||
|
||||
class BareMetalCustomRunConfigWidget : public RunConfigWidget
|
||||
BareMetalCustomRunConfiguration::BareMetalCustomRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
public:
|
||||
BareMetalCustomRunConfigWidget(BareMetalCustomRunConfiguration *runConfig)
|
||||
: m_runConfig(runConfig)
|
||||
{
|
||||
auto executableChooser = new PathChooser;
|
||||
executableChooser->setExpectedKind(PathChooser::File);
|
||||
executableChooser->setPath(m_runConfig->localExecutableFilePath());
|
||||
auto exeAspect = new ExecutableAspect(this);
|
||||
exeAspect->setSettingsKey("BareMetal.CustomRunConfig.Executable");
|
||||
exeAspect->setPlaceHolderText(tr("Unknown"));
|
||||
exeAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
||||
exeAspect->setExpectedKind(PathChooser::Any);
|
||||
addExtraAspect(exeAspect);
|
||||
|
||||
auto clayout = new QFormLayout(this);
|
||||
clayout->addRow(BareMetalCustomRunConfiguration::tr("Executable:"), executableChooser);
|
||||
addExtraAspect(new ArgumentsAspect(this, "Qt4ProjectManager.MaemoRunConfiguration.Arguments"));
|
||||
addExtraAspect(new WorkingDirectoryAspect(this, "BareMetal.RunConfig.WorkingDirectory"));
|
||||
|
||||
runConfig->extraAspect<ArgumentsAspect>()->addToConfigurationLayout(clayout);
|
||||
runConfig->extraAspect<WorkingDirectoryAspect>()->addToConfigurationLayout(clayout);
|
||||
|
||||
connect(executableChooser, &PathChooser::pathChanged,
|
||||
this, &BareMetalCustomRunConfigWidget::handleLocalExecutableChanged);
|
||||
}
|
||||
|
||||
private:
|
||||
void handleLocalExecutableChanged(const QString &path)
|
||||
{
|
||||
m_runConfig->setLocalExecutableFilePath(path.trimmed());
|
||||
}
|
||||
|
||||
QString displayName() const { return m_runConfig->displayName(); }
|
||||
|
||||
BareMetalCustomRunConfiguration * const m_runConfig;
|
||||
};
|
||||
|
||||
BareMetalCustomRunConfiguration::BareMetalCustomRunConfiguration(Target *parent, Core::Id id)
|
||||
: BareMetalRunConfiguration(parent, id)
|
||||
{
|
||||
setDefaultDisplayName(RunConfigurationFactory::decoratedTargetName(tr("Custom Executable)"), target));
|
||||
}
|
||||
|
||||
const char *BareMetalCustomRunConfiguration::Id = "BareMetal";
|
||||
|
||||
bool BareMetalCustomRunConfiguration::isConfigured() const
|
||||
{
|
||||
return !m_localExecutable.isEmpty();
|
||||
return !extraAspect<ExecutableAspect>()->executable().isEmpty();
|
||||
}
|
||||
|
||||
RunConfiguration::ConfigurationState
|
||||
@@ -94,38 +74,12 @@ BareMetalCustomRunConfiguration::ensureConfigured(QString *errorMessage)
|
||||
return Configured;
|
||||
}
|
||||
|
||||
QWidget *BareMetalCustomRunConfiguration::createConfigurationWidget()
|
||||
{
|
||||
return wrapWidget(new BareMetalCustomRunConfigWidget(this));
|
||||
}
|
||||
|
||||
static QString exeKey()
|
||||
{
|
||||
return QLatin1String("BareMetal.CustomRunConfig.Executable");
|
||||
}
|
||||
|
||||
bool BareMetalCustomRunConfiguration::fromMap(const QVariantMap &map)
|
||||
{
|
||||
if (!BareMetalRunConfiguration::fromMap(map))
|
||||
return false;
|
||||
m_localExecutable = map.value(exeKey()).toString();
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariantMap BareMetalCustomRunConfiguration::toMap() const
|
||||
{
|
||||
QVariantMap map = BareMetalRunConfiguration::toMap();
|
||||
map.insert(exeKey(), m_localExecutable);
|
||||
return map;
|
||||
}
|
||||
|
||||
// BareMetalCustomRunConfigurationFactory
|
||||
|
||||
BareMetalCustomRunConfigurationFactory::BareMetalCustomRunConfigurationFactory() :
|
||||
FixedRunConfigurationFactory(BareMetalCustomRunConfiguration::tr("Custom Executable"), true)
|
||||
BareMetalCustomRunConfigurationFactory::BareMetalCustomRunConfigurationFactory()
|
||||
: FixedRunConfigurationFactory(BareMetalCustomRunConfiguration::tr("Custom Executable"), true)
|
||||
{
|
||||
registerRunConfiguration<BareMetalCustomRunConfiguration>("BareMetal.CustomRunConfig");
|
||||
setDecorateDisplayNames(true);
|
||||
registerRunConfiguration<BareMetalCustomRunConfiguration>(BareMetalCustomRunConfiguration::Id);
|
||||
addSupportedTargetDeviceType(BareMetal::Constants::BareMetalOsType);
|
||||
}
|
||||
|
||||
|
@@ -25,31 +25,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "baremetalrunconfiguration.h"
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
|
||||
namespace BareMetal {
|
||||
namespace Internal {
|
||||
|
||||
class BareMetalCustomRunConfiguration : public BareMetalRunConfiguration
|
||||
class BareMetalCustomRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BareMetalCustomRunConfiguration(ProjectExplorer::Target *parent, Core::Id id);
|
||||
BareMetalCustomRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
|
||||
|
||||
public:
|
||||
static const char *Id;
|
||||
bool isConfigured() const override;
|
||||
ConfigurationState ensureConfigured(QString *errorMessage) override;
|
||||
QWidget *createConfigurationWidget() override;
|
||||
|
||||
virtual QString localExecutableFilePath() const override { return m_localExecutable; }
|
||||
|
||||
void setLocalExecutableFilePath(const QString &executable) { m_localExecutable = executable; }
|
||||
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
QVariantMap toMap() const override;
|
||||
|
||||
private:
|
||||
QString m_localExecutable;
|
||||
};
|
||||
|
||||
class BareMetalCustomRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory
|
||||
|
@@ -24,7 +24,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "baremetaldebugsupport.h"
|
||||
#include "baremetalrunconfiguration.h"
|
||||
#include "baremetaldevice.h"
|
||||
#include "baremetalgdbcommandsdeploystep.h"
|
||||
|
||||
@@ -86,10 +85,12 @@ BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl)
|
||||
|
||||
void BareMetalDebugSupport::start()
|
||||
{
|
||||
const auto rc = qobject_cast<BareMetalRunConfiguration *>(runControl()->runConfiguration());
|
||||
const auto rc = runControl()->runConfiguration();
|
||||
QTC_ASSERT(rc, reportFailure(); return);
|
||||
const auto exeAspect = rc->extraAspect<ExecutableAspect>();
|
||||
QTC_ASSERT(exeAspect, reportFailure(); return);
|
||||
|
||||
const QString bin = rc->localExecutableFilePath();
|
||||
const QString bin = exeAspect->executable().toString();
|
||||
if (bin.isEmpty()) {
|
||||
reportFailure(tr("Cannot debug: Local executable is not set."));
|
||||
return;
|
||||
|
@@ -75,7 +75,9 @@ bool BareMetalPlugin::initialize(const QStringList &arguments, QString *errorStr
|
||||
|
||||
auto constraint = [](RunConfiguration *runConfig) {
|
||||
const QByteArray idStr = runConfig->id().name();
|
||||
return runConfig->isEnabled() && idStr.startsWith(BareMetalRunConfiguration::IdPrefix);
|
||||
const bool res = idStr.startsWith(BareMetalRunConfiguration::IdPrefix)
|
||||
|| idStr == BareMetalCustomRunConfiguration::Id;
|
||||
return res;
|
||||
};
|
||||
|
||||
RunControl::registerWorker<BareMetalDebugSupport>
|
||||
|
@@ -32,104 +32,43 @@
|
||||
#include <projectexplorer/runconfigurationaspects.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QDir>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace BareMetal {
|
||||
namespace Internal {
|
||||
|
||||
// BareMetalRunConfigurationWidget
|
||||
|
||||
class BareMetalRunConfigurationWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
explicit BareMetalRunConfigurationWidget(BareMetalRunConfiguration *runConfiguration);
|
||||
|
||||
private:
|
||||
void updateTargetInformation();
|
||||
|
||||
BareMetalRunConfiguration * const m_runConfiguration;
|
||||
QLabel m_localExecutableLabel;
|
||||
};
|
||||
|
||||
BareMetalRunConfigurationWidget::BareMetalRunConfigurationWidget(BareMetalRunConfiguration *runConfiguration)
|
||||
: m_runConfiguration(runConfiguration)
|
||||
{
|
||||
auto formLayout = new QFormLayout(this);
|
||||
formLayout->setFormAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
|
||||
m_localExecutableLabel.setText(m_runConfiguration->localExecutableFilePath());
|
||||
formLayout->addRow(BareMetalRunConfiguration::tr("Executable:"), &m_localExecutableLabel);
|
||||
|
||||
//d->genericWidgetsLayout.addRow(tr("Debugger host:"),d->runConfiguration);
|
||||
//d->genericWidgetsLayout.addRow(tr("Debugger port:"),d->runConfiguration);
|
||||
runConfiguration->extraAspect<ArgumentsAspect>()->addToConfigurationLayout(formLayout);
|
||||
runConfiguration->extraAspect<WorkingDirectoryAspect>()->addToConfigurationLayout(formLayout);
|
||||
|
||||
connect(m_runConfiguration, &BareMetalRunConfiguration::targetInformationChanged,
|
||||
this, &BareMetalRunConfigurationWidget::updateTargetInformation);
|
||||
}
|
||||
|
||||
void BareMetalRunConfigurationWidget::updateTargetInformation()
|
||||
{
|
||||
const QString regularText = QDir::toNativeSeparators(m_runConfiguration->localExecutableFilePath());
|
||||
const QString errorMessage = "<font color=\"red\">" + tr("Unknown") + "</font>";
|
||||
m_localExecutableLabel.setText(regularText.isEmpty() ? errorMessage : regularText);
|
||||
}
|
||||
|
||||
|
||||
// BareMetalRunConfiguration
|
||||
|
||||
BareMetalRunConfiguration::BareMetalRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
auto exeAspect = new ExecutableAspect(this);
|
||||
exeAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
|
||||
exeAspect->setPlaceHolderText(tr("Unknown"));
|
||||
addExtraAspect(exeAspect);
|
||||
|
||||
addExtraAspect(new ArgumentsAspect(this, "Qt4ProjectManager.MaemoRunConfiguration.Arguments"));
|
||||
addExtraAspect(new WorkingDirectoryAspect(this, "BareMetal.RunConfig.WorkingDirectory"));
|
||||
|
||||
connect(target, &Target::deploymentDataChanged,
|
||||
this, &BareMetalRunConfiguration::handleBuildSystemDataUpdated);
|
||||
this, &BareMetalRunConfiguration::updateTargetInformation);
|
||||
connect(target, &Target::applicationTargetsChanged,
|
||||
this, &BareMetalRunConfiguration::handleBuildSystemDataUpdated);
|
||||
this, &BareMetalRunConfiguration::updateTargetInformation);
|
||||
connect(target, &Target::kitChanged,
|
||||
this, &BareMetalRunConfiguration::handleBuildSystemDataUpdated); // Handles device changes, etc.
|
||||
this, &BareMetalRunConfiguration::updateTargetInformation); // Handles device changes, etc.
|
||||
connect(target->project(), &Project::parsingFinished,
|
||||
this, &BareMetalRunConfiguration::updateTargetInformation);
|
||||
}
|
||||
|
||||
QWidget *BareMetalRunConfiguration::createConfigurationWidget()
|
||||
{
|
||||
return wrapWidget(new BareMetalRunConfigurationWidget(this));
|
||||
}
|
||||
|
||||
QVariantMap BareMetalRunConfiguration::toMap() const
|
||||
{
|
||||
return RunConfiguration::toMap();
|
||||
}
|
||||
|
||||
bool BareMetalRunConfiguration::fromMap(const QVariantMap &map)
|
||||
{
|
||||
if (!RunConfiguration::fromMap(map))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString BareMetalRunConfiguration::localExecutableFilePath() const
|
||||
void BareMetalRunConfiguration::updateTargetInformation()
|
||||
{
|
||||
const BuildTargetInfo bti = target()->applicationTargets().buildTargetInfo(buildKey());
|
||||
return bti.targetFilePath.toString();
|
||||
}
|
||||
|
||||
void BareMetalRunConfiguration::handleBuildSystemDataUpdated()
|
||||
{
|
||||
emit targetInformationChanged();
|
||||
extraAspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
|
||||
emit enabledChanged();
|
||||
}
|
||||
|
||||
const char *BareMetalRunConfiguration::IdPrefix = "BareMetal";
|
||||
|
||||
const char *BareMetalRunConfiguration::IdPrefix = "BareMetalCustom";
|
||||
|
||||
// BareMetalRunConfigurationFactory
|
||||
|
||||
|
@@ -30,8 +30,6 @@
|
||||
namespace BareMetal {
|
||||
namespace Internal {
|
||||
|
||||
class BareMetalRunConfigurationWidget;
|
||||
|
||||
class BareMetalRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -39,21 +37,10 @@ class BareMetalRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
public:
|
||||
BareMetalRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
|
||||
|
||||
QWidget *createConfigurationWidget() override;
|
||||
|
||||
virtual QString localExecutableFilePath() const;
|
||||
QVariantMap toMap() const override;
|
||||
|
||||
static const char *IdPrefix;
|
||||
|
||||
signals:
|
||||
void targetInformationChanged() const;
|
||||
|
||||
protected:
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
|
||||
private:
|
||||
void handleBuildSystemDataUpdated();
|
||||
void updateTargetInformation();
|
||||
};
|
||||
|
||||
class BareMetalRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory
|
||||
|
Reference in New Issue
Block a user