aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/runconfiguration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/projectexplorer/runconfiguration.cpp')
-rw-r--r--src/plugins/projectexplorer/runconfiguration.cpp113
1 files changed, 69 insertions, 44 deletions
diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp
index 438d631c781..52cd91751ef 100644
--- a/src/plugins/projectexplorer/runconfiguration.cpp
+++ b/src/plugins/projectexplorer/runconfiguration.cpp
@@ -466,8 +466,6 @@ Runnable RunConfiguration::runnable() const
r.workingDirectory = aspect->workingDirectory().toString();
if (auto aspect = extraAspect<EnvironmentAspect>())
r.environment = aspect->environment();
- if (auto aspect = extraAspect<TerminalAspect>())
- r.runMode = aspect->runMode();
return r;
}
@@ -520,6 +518,8 @@ RunConfigurationFactory::RunConfigurationFactory()
RunConfigurationFactory::~RunConfigurationFactory()
{
g_runConfigurationFactories.removeOne(this);
+ qDeleteAll(m_ownedRunWorkerFactories);
+ m_ownedRunWorkerFactories.clear();
}
QString RunConfigurationFactory::decoratedTargetName(const QString targetName, Target *target)
@@ -586,6 +586,16 @@ void RunConfigurationFactory::setDecorateDisplayNames(bool on)
m_decorateDisplayNames = on;
}
+RunWorkerFactory *RunConfigurationFactory::addRunWorkerFactoryHelper
+ (Core::Id runMode, const std::function<RunWorker *(RunControl *)> &creator)
+{
+ auto factory = new RunWorkerFactory;
+ factory->addConstraint(m_ownTypeChecker);
+ factory->addSupportedRunMode(runMode);
+ factory->setProducer(creator);
+ return factory;
+}
+
void RunConfigurationFactory::addSupportedProjectType(Core::Id id)
{
m_supportedProjectTypes.append(id);
@@ -682,28 +692,60 @@ FixedRunConfigurationFactory::availableCreators(Target *parent) const
// RunWorkerFactory
-using RunWorkerFactories = std::vector<RunWorkerFactory>;
+static QList<RunWorkerFactory *> g_runWorkerFactories;
-static RunWorkerFactories &theWorkerFactories()
+RunWorkerFactory::RunWorkerFactory()
{
- static RunWorkerFactories factories;
- return factories;
+ g_runWorkerFactories.append(this);
}
-RunWorkerFactory::RunWorkerFactory(Core::Id mode, Constraint constr, const WorkerCreator &prod, int prio)
- : m_runMode(mode), m_constraint(constr), m_producer(prod), m_priority(prio)
-{}
+RunWorkerFactory::~RunWorkerFactory()
+{
+ g_runWorkerFactories.removeOne(this);
+}
bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
{
- if (runMode != this->m_runMode)
+ if (!m_supportedRunModes.contains(runMode))
return false;
- if (!m_constraint)
- return true;
- return m_constraint(runConfiguration);
+
+ for (const Constraint &constraint : m_constraints) {
+ if (!constraint(runConfiguration))
+ return false;
+ }
+
+ return true;
+}
+
+void RunWorkerFactory::setPriority(int priority)
+{
+ m_priority = priority;
+}
+
+void RunWorkerFactory::setProducer(const WorkerCreator &producer)
+{
+ m_producer = producer;
+}
+
+void RunWorkerFactory::addConstraint(const Constraint &constraint)
+{
+ // Default constructed Constraints are not worth keeping.
+ // FIXME: Make it a QTC_ASSERT once there is no code path
+ // using this "feature" anymore.
+ if (!constraint)
+ return;
+ m_constraints.append(constraint);
}
+void RunWorkerFactory::addSupportedRunMode(Core::Id runMode)
+{
+ m_supportedRunModes.append(runMode);
+}
+void RunWorkerFactory::destroyRemainingRunWorkerFactories()
+{
+ qDeleteAll(g_runWorkerFactories);
+}
/*!
\class ProjectExplorer::RunControl
@@ -848,7 +890,7 @@ public:
}
}
- ~RunControlPrivate()
+ ~RunControlPrivate() override
{
QTC_CHECK(state == RunControlState::Finished || state == RunControlState::Initialized);
disconnect();
@@ -907,7 +949,7 @@ public:
using namespace Internal;
RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) :
- d(new RunControlPrivate(this, runConfiguration, mode))
+ d(std::make_unique<RunControlPrivate>(this, runConfiguration, mode))
{
#ifdef WITH_JOURNALD
JournaldWatcher::instance()->subscribe(this, [this](const JournaldWatcher::LogEntry &entry) {
@@ -939,8 +981,6 @@ RunControl::~RunControl()
#ifdef WITH_JOURNALD
JournaldWatcher::instance()->unsubscribe(this);
#endif
- delete d;
- d = nullptr;
}
void RunControl::initiateStart()
@@ -967,7 +1007,7 @@ void RunControl::forceStop()
void RunControl::initiateFinish()
{
- QTimer::singleShot(0, d, &RunControlPrivate::initiateFinish);
+ QTimer::singleShot(0, d.get(), &RunControlPrivate::initiateFinish);
}
using WorkerCreators = QHash<Core::Id, RunControl::WorkerCreator>;
@@ -1001,22 +1041,17 @@ RunWorker *RunControl::createWorker(Core::Id id)
RunWorkerFactory::WorkerCreator RunControl::producer(RunConfiguration *runConfig, Core::Id runMode)
{
const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, runConfig, runMode);
- const RunWorkerFactories candidates = Utils::filtered(theWorkerFactories(), canRun);
+ const QList<RunWorkerFactory *> candidates = Utils::filtered(g_runWorkerFactories, canRun);
if (candidates.empty())
return {};
- const auto higherPriority = std::bind(std::greater<int>(),
+ const auto higherPriority = std::bind(std::greater<>(),
std::bind(&RunWorkerFactory::priority, std::placeholders::_1),
std::bind(&RunWorkerFactory::priority, std::placeholders::_2));
const auto bestFactory = std::max_element(candidates.begin(), candidates.end(), higherPriority);
- return bestFactory->producer();
-}
-
-void RunControl::addWorkerFactory(const RunWorkerFactory &workerFactory)
-{
- theWorkerFactories().push_back(workerFactory);
+ return (*bestFactory)->producer();
}
void RunControlPrivate::initiateStart()
@@ -1406,17 +1441,6 @@ Project *RunControl::project() const
return d->project.data();
}
-bool RunControl::canReUseOutputPane(const RunControl *other) const
-{
- if (!other || other->isRunning())
- return false;
-
- return d->runnable.executable == other->d->runnable.executable
- && d->runnable.commandLineArguments == other->d->runnable.commandLineArguments
- && d->runnable.workingDirectory == other->d->runnable.workingDirectory
- && d->runnable.environment == other->d->runnable.environment;
-}
-
/*!
A handle to the application process.
@@ -1616,12 +1640,17 @@ SimpleTargetRunner::SimpleTargetRunner(RunControl *runControl)
setDisplayName("SimpleTargetRunner");
m_runnable = runControl->runnable(); // Default value. Can be overridden using setRunnable.
m_device = runControl->device(); // Default value. Can be overridden using setDevice.
+ if (auto runConfig = runControl->runConfiguration()) {
+ if (auto terminalAspect = runConfig->extraAspect<TerminalAspect>())
+ m_useTerminal = terminalAspect->useTerminal();
+ }
}
void SimpleTargetRunner::start()
{
m_stopReported = false;
m_launcher.disconnect(this);
+ m_launcher.setUseTerminal(m_useTerminal);
const bool isDesktop = m_device.isNull()
|| m_device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
@@ -1847,14 +1876,10 @@ void RunWorkerPrivate::timerEvent(QTimerEvent *ev)
*/
RunWorker::RunWorker(RunControl *runControl)
- : d(new RunWorkerPrivate(this, runControl))
-{
-}
+ : d(std::make_unique<RunWorkerPrivate>(this, runControl))
+{ }
-RunWorker::~RunWorker()
-{
- delete d;
-}
+RunWorker::~RunWorker() = default;
/*!
* This function is called by the RunControl once all dependencies