diff options
-rw-r--r-- | src/plugins/debugger/debuggerruncontrol.cpp | 3 | ||||
-rw-r--r-- | src/plugins/winrt/winrtdebugsupport.cpp | 95 | ||||
-rw-r--r-- | src/plugins/winrt/winrtdebugsupport.h | 16 | ||||
-rw-r--r-- | src/plugins/winrt/winrtdevice.cpp | 13 | ||||
-rw-r--r-- | src/plugins/winrt/winrtdevice.h | 3 | ||||
-rw-r--r-- | src/plugins/winrt/winrtruncontrol.cpp | 49 | ||||
-rw-r--r-- | src/plugins/winrt/winrtruncontrol.h | 15 | ||||
-rw-r--r-- | src/plugins/winrt/winrtrunfactories.cpp | 25 | ||||
-rw-r--r-- | src/plugins/winrt/winrtrunnerhelper.cpp | 48 | ||||
-rw-r--r-- | src/plugins/winrt/winrtrunnerhelper.h | 14 |
10 files changed, 111 insertions, 170 deletions
diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index f364813350..1a9fc9e6e6 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -535,7 +535,8 @@ void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp, QString { int portsUsed = portsUsedByDebugger(); if (portsUsed > device()->freePorts().count()) { - *errorMessage = tr("Cannot debug: Not enough free ports available."); + if (errorMessage) + *errorMessage = tr("Cannot debug: Not enough free ports available."); return; } diff --git a/src/plugins/winrt/winrtdebugsupport.cpp b/src/plugins/winrt/winrtdebugsupport.cpp index 1cb2c6b124..352ac3f3f9 100644 --- a/src/plugins/winrt/winrtdebugsupport.cpp +++ b/src/plugins/winrt/winrtdebugsupport.cpp @@ -27,10 +27,6 @@ #include "winrtrunconfiguration.h" #include "winrtrunnerhelper.h" -#include <debugger/debuggerkitinformation.h> -#include <debugger/debuggerrunconfigurationaspect.h> -#include <debugger/debuggerruncontrol.h> -#include <debugger/debuggerstartparameters.h> #include <projectexplorer/target.h> #include <projectexplorer/toolchain.h> @@ -43,53 +39,16 @@ #include <utils/qtcprocess.h> -namespace WinRt { -namespace Internal { - +using namespace Debugger; using namespace ProjectExplorer; -WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, WinRtRunnerHelper *runner) - : RunWorker(runControl) - , m_runner(runner) -{ - connect(runControl, &RunControl::finished, this, &WinRtDebugSupport::finish); -} - -bool WinRtDebugSupport::useQmlDebugging(RunConfiguration *runConfig) -{ - Debugger::DebuggerRunConfigurationAspect *extraAspect = - runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>(); - return extraAspect && extraAspect->useQmlDebugger(); -} - -bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage) -{ - QTcpServer server; - if (!server.listen(QHostAddress::LocalHost, - qmlDebuggerPort.isValid() ? qmlDebuggerPort.number() : 0)) { - *errorMessage = tr("Not enough free ports for QML debugging."); - return false; - } - qmlDebuggerPort = Utils::Port(server.serverPort()); - return true; -} - -WinRtDebugSupport::~WinRtDebugSupport() -{ - delete m_runner; -} - -void WinRtDebugSupport::finish() -{ - m_runner->stop(); -} +namespace WinRt { +namespace Internal { -RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runConfig, - Core::Id mode, - QString *errorMessage) +WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessage) + : DebuggerRunTool(runControl) { // FIXME: This is just working for local debugging; - using namespace Debugger; DebuggerStartParameters params; params.startMode = AttachExternal; // The first Thread needs to be resumed manually. @@ -101,33 +60,33 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC *errorMessage = tr("The WinRT debugging helper is missing from your Qt Creator " "installation. It was assumed to be located at %1").arg( debuggerHelper.absoluteFilePath()); - return 0; + return; } - if (useQmlDebugging(runConfig)) { + if (isQmlDebugging()) { Utils::Port qmlDebugPort; if (!getFreePort(qmlDebugPort, errorMessage)) - return 0; + return; params.qmlServer.host = QHostAddress(QHostAddress::LocalHost).toString(); params.qmlServer.port = qmlDebugPort; } - WinRtRunnerHelper *runner = new WinRtRunnerHelper(runConfig, errorMessage); + m_runner = new WinRtRunnerHelper(this, errorMessage); if (!errorMessage->isEmpty()) - return 0; + return; QLocalServer server; server.listen(QLatin1String("QtCreatorWinRtDebugPIDPipe")); - runner->debug(debuggerHelper.absoluteFilePath()); - if (!runner->waitForStarted()) { + m_runner->debug(debuggerHelper.absoluteFilePath()); + if (!m_runner->waitForStarted()) { *errorMessage = tr("Cannot start the WinRT Runner Tool."); - return 0; + return; } if (!server.waitForNewConnection(10000)) { *errorMessage = tr("Cannot establish connection to the WinRT debugging helper."); - return 0; + return; } while (server.hasPendingConnections()) { @@ -141,14 +100,11 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC if (!ok) { *errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. " "(output: %1)").arg(QString::fromLocal8Bit(output)); - return 0; + return; } server.close(); - auto debugRunControl = new RunControl(runConfig, mode); - (void) new Debugger::DebuggerRunTool(debugRunControl, params, errorMessage); - runner->setDebugRunControl(debugRunControl); - new WinRtDebugSupport(debugRunControl, runner); - return debugRunControl; + setStartParameters(params, errorMessage); + return; } } } @@ -157,8 +113,23 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC *errorMessage = tr("Cannot create an appropriate run control for " "the current run configuration."); +} - return 0; +bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage) +{ + QTcpServer server; + if (!server.listen(QHostAddress::LocalHost, + qmlDebuggerPort.isValid() ? qmlDebuggerPort.number() : 0)) { + *errorMessage = tr("Not enough free ports for QML debugging."); + return false; + } + qmlDebuggerPort = Utils::Port(server.serverPort()); + return true; +} + +WinRtDebugSupport::~WinRtDebugSupport() +{ + delete m_runner; } } // namespace Internal diff --git a/src/plugins/winrt/winrtdebugsupport.h b/src/plugins/winrt/winrtdebugsupport.h index 177e8157c1..581527ebff 100644 --- a/src/plugins/winrt/winrtdebugsupport.h +++ b/src/plugins/winrt/winrtdebugsupport.h @@ -25,9 +25,7 @@ #pragma once -#include <projectexplorer/runconfiguration.h> - -#include <QObject> +#include <debugger/debuggerruncontrol.h> namespace WinRt { namespace Internal { @@ -35,21 +33,15 @@ namespace Internal { class WinRtRunConfiguration; class WinRtRunnerHelper; -class WinRtDebugSupport : public ProjectExplorer::RunWorker +class WinRtDebugSupport : public Debugger::DebuggerRunTool { Q_OBJECT + public: - static ProjectExplorer::RunControl *createDebugRunControl(WinRtRunConfiguration *runConfig, - Core::Id mode, - QString *errorMessage); + WinRtDebugSupport(ProjectExplorer::RunControl *runControl, QString *errorMessage); ~WinRtDebugSupport(); private: - WinRtDebugSupport(ProjectExplorer::RunControl *runControl, WinRtRunnerHelper *runner); - - void finish(); - - static bool useQmlDebugging(ProjectExplorer::RunConfiguration *runConfig); static bool getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage); WinRtRunnerHelper *m_runner; diff --git a/src/plugins/winrt/winrtdevice.cpp b/src/plugins/winrt/winrtdevice.cpp index fbf059f0b9..2f5ef04ae5 100644 --- a/src/plugins/winrt/winrtdevice.cpp +++ b/src/plugins/winrt/winrtdevice.cpp @@ -29,7 +29,9 @@ #include <projectexplorer/devicesupport/desktopprocesssignaloperation.h> #include <projectexplorer/devicesupport/devicemanager.h> #include <projectexplorer/devicesupport/deviceprocesslist.h> +#include <projectexplorer/projectexplorerconstants.h> #include <utils/qtcassert.h> +#include <utils/portlist.h> #include <QFileInfo> #include <QCoreApplication> @@ -42,16 +44,27 @@ namespace Internal { WinRtDevice::WinRtDevice() : m_deviceId(-1) { + initFreePorts(); } WinRtDevice::WinRtDevice(Core::Id type, MachineType machineType, Core::Id internalId, int deviceId) : IDevice(type, AutoDetected, machineType, internalId), m_deviceId(deviceId) { + initFreePorts(); } WinRtDevice::WinRtDevice(const WinRtDevice &other) : IDevice(other), m_deviceId(other.m_deviceId) { + initFreePorts(); +} + +void WinRtDevice::initFreePorts() +{ + Utils::PortList portList; + portList.addRange(Utils::Port(ProjectExplorer::Constants::DESKTOP_PORT_START), + Utils::Port(ProjectExplorer::Constants::DESKTOP_PORT_END)); + setFreePorts(portList); } QString WinRtDevice::displayType() const diff --git a/src/plugins/winrt/winrtdevice.h b/src/plugins/winrt/winrtdevice.h index 772bc2dfeb..5915ac73f7 100644 --- a/src/plugins/winrt/winrtdevice.h +++ b/src/plugins/winrt/winrtdevice.h @@ -56,6 +56,9 @@ protected: WinRtDevice(const WinRtDevice &other); private: + void initFreePorts(); + +private: int m_deviceId; }; diff --git a/src/plugins/winrt/winrtruncontrol.cpp b/src/plugins/winrt/winrtruncontrol.cpp index eb2082063f..786d19f869 100644 --- a/src/plugins/winrt/winrtruncontrol.cpp +++ b/src/plugins/winrt/winrtruncontrol.cpp @@ -50,24 +50,32 @@ using ProjectExplorer::Target; namespace WinRt { namespace Internal { -WinRtRunControl::WinRtRunControl(WinRtRunConfiguration *runConfiguration, Core::Id mode) - : RunControl(runConfiguration, mode) - , m_runConfiguration(runConfiguration) +WinRtRunner::WinRtRunner(RunControl *runControl) + : RunWorker(runControl) { - setIcon(Utils::Icons::RUN_SMALL_TOOLBAR); + runControl->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR); } -void WinRtRunControl::start() +void WinRtRunner::start() { if (m_state != StoppedState) return; - if (!startWinRtRunner()) - m_state = StoppedState; - else - reportApplicationStart(); + + QTC_ASSERT(!m_runner, m_state = StoppedState; reportFailure(); return); + QString errorMessage; + m_runner = new WinRtRunnerHelper(this, &errorMessage); + if (!errorMessage.isEmpty()) { + reportFailure(errorMessage); + return; + } + connect(m_runner, &WinRtRunnerHelper::started, this, &WinRtRunner::onProcessStarted); + connect(m_runner, &WinRtRunnerHelper::finished, this, &WinRtRunner::onProcessFinished); + connect(m_runner, &WinRtRunnerHelper::error, this, &WinRtRunner::onProcessError); + m_state = StartingState; + m_runner->start(); } -void WinRtRunControl::stop() +void WinRtRunner::stop() { if (m_state == StoppedState) return; @@ -75,38 +83,27 @@ void WinRtRunControl::stop() m_runner->stop(); } -void WinRtRunControl::onProcessStarted() +void WinRtRunner::onProcessStarted() { QTC_CHECK(m_state == StartingState); m_state = StartedState; + reportStarted(); } -void WinRtRunControl::onProcessFinished() +void WinRtRunner::onProcessFinished() { QTC_CHECK(m_state == StartedState); onProcessError(); } -void WinRtRunControl::onProcessError() +void WinRtRunner::onProcessError() { QTC_ASSERT(m_runner, return); m_runner->disconnect(); m_runner->deleteLater(); m_runner = 0; m_state = StoppedState; - reportApplicationStop(); -} - -bool WinRtRunControl::startWinRtRunner() -{ - QTC_ASSERT(!m_runner, return false); - m_runner = new WinRtRunnerHelper(this); - connect(m_runner, &WinRtRunnerHelper::started, this, &WinRtRunControl::onProcessStarted); - connect(m_runner, &WinRtRunnerHelper::finished, this, &WinRtRunControl::onProcessFinished); - connect(m_runner, &WinRtRunnerHelper::error, this, &WinRtRunControl::onProcessError); - m_state = StartingState; - m_runner->start(); - return true; + reportStopped(); } } // namespace Internal diff --git a/src/plugins/winrt/winrtruncontrol.h b/src/plugins/winrt/winrtruncontrol.h index d7686895aa..fe8e5176d9 100644 --- a/src/plugins/winrt/winrtruncontrol.h +++ b/src/plugins/winrt/winrtruncontrol.h @@ -30,25 +30,16 @@ #include <projectexplorer/runconfiguration.h> #include <utils/qtcprocess.h> -namespace QtSupport { -class BaseQtVersion; -} // namespace QtSupport - -namespace ProjectExplorer { -class Target; -} // namespace ProjectExplorer - namespace WinRt { namespace Internal { -class WinRtRunConfiguration; class WinRtRunnerHelper; -class WinRtRunControl : public ProjectExplorer::RunControl +class WinRtRunner : public ProjectExplorer::RunWorker { Q_OBJECT public: - explicit WinRtRunControl(WinRtRunConfiguration *runConfiguration, Core::Id mode); + explicit WinRtRunner(ProjectExplorer::RunControl *runControl); void start() override; void stop() override; @@ -59,9 +50,7 @@ private: void onProcessStarted(); void onProcessFinished(); void onProcessError(); - bool startWinRtRunner(); - WinRtRunConfiguration *m_runConfiguration; State m_state = StoppedState; Utils::QtcProcess *m_process = nullptr; WinRtRunnerHelper *m_runner = nullptr; diff --git a/src/plugins/winrt/winrtrunfactories.cpp b/src/plugins/winrt/winrtrunfactories.cpp index b1b5e56829..af4914c9bd 100644 --- a/src/plugins/winrt/winrtrunfactories.cpp +++ b/src/plugins/winrt/winrtrunfactories.cpp @@ -153,17 +153,24 @@ bool WinRtRunControlFactory::canRun(RunConfiguration *runConfiguration, RunControl *WinRtRunControlFactory::create( RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) { - WinRtRunConfiguration *rc = qobject_cast<WinRtRunConfiguration *>(runConfiguration); - QTC_ASSERT(rc, return 0); - - if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) - return new WinRtRunControl(rc, mode); + RunControl *runControl = nullptr; + if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) { + runControl = new RunControl(runConfiguration, mode); + (void) new WinRtRunner(runControl); + return runControl; + } else if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE + || mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) { + runControl = new RunControl(runConfiguration, mode); + (void) new WinRtDebugSupport(runControl, errorMessage); + } else { + *errorMessage = tr("Unsupported run mode %1.").arg(mode.toString()); + } - if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE || mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) - return WinRtDebugSupport::createDebugRunControl(rc, mode, errorMessage); + if (errorMessage->isEmpty()) + return runControl; - *errorMessage = tr("Unsupported run mode %1.").arg(mode.toString()); - return 0; + delete runControl; + return nullptr; } QString WinRtRunControlFactory::displayName() const diff --git a/src/plugins/winrt/winrtrunnerhelper.cpp b/src/plugins/winrt/winrtrunnerhelper.cpp index 56006ac396..a8986a8026 100644 --- a/src/plugins/winrt/winrtrunnerhelper.cpp +++ b/src/plugins/winrt/winrtrunnerhelper.cpp @@ -32,7 +32,6 @@ #include <projectexplorer/buildtargetinfo.h> #include <projectexplorer/devicesupport/idevice.h> #include <projectexplorer/buildconfiguration.h> -#include <projectexplorer/kitinformation.h> #include <projectexplorer/project.h> #include <projectexplorer/runconfiguration.h> #include <projectexplorer/target.h> @@ -45,52 +44,34 @@ using namespace WinRt; using namespace WinRt::Internal; -WinRtRunnerHelper::WinRtRunnerHelper(WinRtRunConfiguration *runConfiguration, QString *errormessage) - : QObject() - , m_messenger(0) - , m_runConfiguration(runConfiguration) - , m_process(0) +WinRtRunnerHelper::WinRtRunnerHelper(ProjectExplorer::RunWorker *runWorker, QString *errorMessage) + : QObject(runWorker) + , m_worker(runWorker) { - init(runConfiguration, errormessage); -} + auto runConfiguration = qobject_cast<WinRtRunConfiguration *>(runWorker->runControl()->runConfiguration()); -WinRtRunnerHelper::WinRtRunnerHelper(ProjectExplorer::RunControl *runControl) - : QObject(runControl) - , m_messenger(runControl) - , m_runConfiguration(0) - , m_process(0) -{ - m_runConfiguration = qobject_cast<WinRtRunConfiguration *>(runControl->runConfiguration()); - QString errorMessage; - if (!init(m_runConfiguration, &errorMessage)) - runControl->appendMessage(errorMessage, Utils::ErrorMessageFormat); -} - -bool WinRtRunnerHelper::init(WinRtRunConfiguration *runConfiguration, QString *errorMessage) -{ ProjectExplorer::Target *target = runConfiguration->target(); - m_device = ProjectExplorer::DeviceKitInformation::device( - target->kit()).dynamicCast<const WinRtDevice>(); + m_device = runWorker->device().dynamicCast<const WinRtDevice>(); const QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit()); if (!qt) { *errorMessage = tr("The current kit has no Qt version."); - return false; + return; } m_runnerFilePath = qt->binPath().toString() + QStringLiteral("/winrtrunner.exe"); if (!QFile::exists(m_runnerFilePath)) { *errorMessage = tr("Cannot find winrtrunner.exe in \"%1\".").arg( QDir::toNativeSeparators(qt->binPath().toString())); - return false; + return; } - const QString &proFile = m_runConfiguration->proFilePath(); + const QString &proFile = runConfiguration->proFilePath(); m_executableFilePath = target->applicationTargets().targetForProject(proFile).toString(); if (m_executableFilePath.isEmpty()) { *errorMessage = tr("Cannot determine the executable file path for \"%1\".").arg( QDir::toNativeSeparators(proFile)); - return false; + return; } // ### we should not need to append ".exe" here. @@ -102,14 +83,12 @@ bool WinRtRunnerHelper::init(WinRtRunConfiguration *runConfiguration, QString *e if (ProjectExplorer::BuildConfiguration *bc = target->activeBuildConfiguration()) m_environment = bc->environment(); - - return true; } void WinRtRunnerHelper::appendMessage(const QString &message, Utils::OutputFormat format) { - if (m_messenger) - m_messenger->appendMessage(message, format); + QTC_ASSERT(m_worker, return); + m_worker->appendMessage(message, format); } void WinRtRunnerHelper::debug(const QString &debuggerExecutable, const QString &debuggerArguments) @@ -138,11 +117,6 @@ bool WinRtRunnerHelper::waitForStarted(int msecs) return m_process->waitForStarted(msecs); } -void WinRtRunnerHelper::setDebugRunControl(ProjectExplorer::RunControl *runControl) -{ - m_messenger = runControl; -} - void WinRtRunnerHelper::onProcessReadyReadStdOut() { QTC_ASSERT(m_process, return); diff --git a/src/plugins/winrt/winrtrunnerhelper.h b/src/plugins/winrt/winrtrunnerhelper.h index 88a5f76b2a..3657da06bf 100644 --- a/src/plugins/winrt/winrtrunnerhelper.h +++ b/src/plugins/winrt/winrtrunnerhelper.h @@ -35,19 +35,16 @@ namespace Utils { class QtcProcess; } -namespace ProjectExplorer { class RunControl; } +namespace ProjectExplorer { class RunWorker; } namespace WinRt { namespace Internal { -class WinRtRunConfiguration; - class WinRtRunnerHelper : public QObject { Q_OBJECT public: - WinRtRunnerHelper(ProjectExplorer::RunControl *runControl); - WinRtRunnerHelper(WinRtRunConfiguration *runConfiguration, QString *errormessage); + WinRtRunnerHelper(ProjectExplorer::RunWorker *runWorker, QString *errorMessage); void debug(const QString &debuggerExecutable, const QString &debuggerArguments = QString()); void start(); @@ -55,7 +52,6 @@ public: void stop(); bool waitForStarted(int msecs = 10000); - void setDebugRunControl(ProjectExplorer::RunControl *runControl); signals: void started(); @@ -71,11 +67,9 @@ private: void onProcessError(QProcess::ProcessError processError); void startWinRtRunner(const RunConf &conf); - bool init(WinRtRunConfiguration *runConfiguration, QString *errorMessage); void appendMessage(const QString &message, Utils::OutputFormat format); - ProjectExplorer::RunControl *m_messenger; - WinRtRunConfiguration *m_runConfiguration; + ProjectExplorer::RunWorker *m_worker = nullptr; WinRtDevice::ConstPtr m_device; Utils::Environment m_environment; QString m_runnerFilePath; @@ -84,7 +78,7 @@ private: QString m_debuggerArguments; QString m_arguments; bool m_uninstallAfterStop; - Utils::QtcProcess *m_process; + Utils::QtcProcess *m_process = nullptr; }; } // namespace WinRt |