summaryrefslogtreecommitdiff
path: root/src/plugins/winrt/winrtrunnerhelper.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@digia.com>2014-04-25 09:20:57 +0200
committerhjk <hjk121@nokiamail.com>2014-05-16 11:21:33 +0200
commit751a61b2e4429f09209ad6f9d24c4e4eea84f2fe (patch)
treefeb5c61de14c929439c749e49d042dd7adca5b7c /src/plugins/winrt/winrtrunnerhelper.cpp
parent93e37b7e78156f2ff17d5d62645327c3eece839a (diff)
downloadqt-creator-751a61b2e4429f09209ad6f9d24c4e4eea84f2fe.tar.gz
WinRT: Enable debugging for local packages.
Change-Id: Ic04f1a471f951caf7a79c69cceecb0ebd5d09919 Reviewed-by: hjk <hjk121@nokiamail.com>
Diffstat (limited to 'src/plugins/winrt/winrtrunnerhelper.cpp')
-rw-r--r--src/plugins/winrt/winrtrunnerhelper.cpp240
1 files changed, 240 insertions, 0 deletions
diff --git a/src/plugins/winrt/winrtrunnerhelper.cpp b/src/plugins/winrt/winrtrunnerhelper.cpp
new file mode 100644
index 0000000000..119bcbc8e3
--- /dev/null
+++ b/src/plugins/winrt/winrtrunnerhelper.cpp
@@ -0,0 +1,240 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+
+#include "winrtrunnerhelper.h"
+
+#include "winrtconstants.h"
+#include "winrtrunconfiguration.h"
+
+#include <coreplugin/idocument.h>
+#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>
+#include <qtsupport/baseqtversion.h>
+#include <qtsupport/qtkitinformation.h>
+#include <utils/qtcprocess.h>
+
+#include <QDir>
+
+using namespace WinRt;
+using namespace WinRt::Internal;
+
+WinRtRunnerHelper::WinRtRunnerHelper(WinRtRunConfiguration *runConfiguration, QString *errormessage)
+ : QObject(runConfiguration)
+ , m_messenger(0)
+ , m_runConfiguration(runConfiguration)
+ , m_process(0)
+{
+ init(runConfiguration, errormessage);
+}
+
+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>();
+
+ const QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit());
+ if (!qt) {
+ *errorMessage = tr("The current kit has no Qt version.");
+ return false;
+ }
+
+ m_isWinPhone = (qt->type() == QLatin1String(Constants::WINRT_WINPHONEQT));
+ 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;
+ }
+
+ const Utils::FileName proFile = Utils::FileName::fromString(
+ target->project()->document()->filePath());
+ m_executableFilePath = target->applicationTargets().targetForProject(proFile).toString()
+ + QStringLiteral(".exe"); // ### we should not need to append ".exe" here.
+
+ m_arguments = runConfiguration->arguments();
+ m_uninstallAfterStop = runConfiguration->uninstallAfterStop();
+
+ if (ProjectExplorer::BuildConfiguration *bc = target->activeBuildConfiguration())
+ m_environment = bc->environment();
+
+ return true;
+}
+
+void WinRtRunnerHelper::debug(const QString &debuggerExecutable, const QString &debuggerArguments)
+{
+ m_debuggerExecutable = debuggerExecutable;
+ m_debuggerArguments = debuggerArguments;
+ startWinRtRunner(Debug);
+}
+
+void WinRtRunnerHelper::start()
+{
+ startWinRtRunner(Start);
+}
+
+void WinRtRunnerHelper::stop()
+{
+ if (m_process)
+ m_process->interrupt();
+ else
+ startWinRtRunner(Stop);
+}
+
+bool WinRtRunnerHelper::waitForStarted(int msecs)
+{
+ QTC_ASSERT(m_process, return false);
+ return m_process->waitForStarted(msecs);
+}
+
+void WinRtRunnerHelper::setRunControl(ProjectExplorer::RunControl *runControl)
+{
+ m_messenger = runControl;
+}
+
+void WinRtRunnerHelper::onProcessReadyReadStdOut()
+{
+ QTC_ASSERT(m_process, return);
+ if (m_messenger) {
+ m_messenger->appendMessage(QString::fromLocal8Bit(
+ m_process->readAllStandardOutput()), Utils::StdOutFormat);
+ }
+}
+
+void WinRtRunnerHelper::onProcessReadyReadStdErr()
+{
+ QTC_ASSERT(m_process, return);
+ if (m_messenger) {
+ m_messenger->appendMessage(QString::fromLocal8Bit(
+ m_process->readAllStandardError()), Utils::StdErrFormat);
+ }
+}
+
+void WinRtRunnerHelper::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+ QTC_ASSERT(m_process, return);
+ m_process->disconnect();
+ m_process->deleteLater();
+ m_process = 0;
+ emit finished(exitCode, exitStatus);
+}
+
+void WinRtRunnerHelper::onProcessError(QProcess::ProcessError processError)
+{
+ QTC_ASSERT(m_process, return);
+ if (m_messenger) {
+ m_messenger->appendMessage(tr("Error while executing the WinRT Runner Tool: %1\n").arg(
+ m_process->errorString()),
+ Utils::ErrorMessageFormat);
+ }
+ m_process->disconnect();
+ m_process->deleteLater();
+ m_process = 0;
+ emit error(processError);
+}
+
+void WinRtRunnerHelper::startWinRtRunner(const RunConf &conf)
+{
+ using namespace Utils;
+ QString runnerArgs;
+ QtcProcess::addArg(&runnerArgs, QStringLiteral("--profile"));
+ QtcProcess::addArg(&runnerArgs, m_isWinPhone ? QStringLiteral("xap") : QStringLiteral("appx"));
+ if (m_device) {
+ QtcProcess::addArg(&runnerArgs, QStringLiteral("--device"));
+ QtcProcess::addArg(&runnerArgs, QString::number(m_device->deviceId()));
+ }
+
+ Utils::QtcProcess *process = 0;
+ bool connectProcess = false;
+
+ switch (conf) {
+ case Debug:
+ Utils::QtcProcess::addArg(&runnerArgs, QStringLiteral("--debug"));
+ Utils::QtcProcess::addArg(&runnerArgs, m_debuggerExecutable);
+ if (!m_debuggerArguments.isEmpty()) {
+ Utils::QtcProcess::addArg(&runnerArgs, QStringLiteral("--debugger-arguments"));
+ Utils::QtcProcess::addArg(&runnerArgs, m_debuggerArguments);
+ }
+ // fall through
+ case Start:
+ QtcProcess::addArgs(&runnerArgs, QStringLiteral("--start --stop --install --wait 0"));
+ connectProcess = true;
+ QTC_ASSERT(!m_process, m_process->deleteLater());
+ m_process = new QtcProcess(this);
+ process = m_process;
+ break;
+ case Stop:
+ Utils::QtcProcess::addArgs(&runnerArgs, QStringLiteral("--stop"));
+ process = new QtcProcess(this);
+ break;
+ }
+
+ QtcProcess::addArg(&runnerArgs, m_executableFilePath);
+ if (!m_arguments.isEmpty())
+ QtcProcess::addArgs(&runnerArgs, m_arguments);
+
+ if (m_messenger) {
+ m_messenger->appendMessage(QStringLiteral("winrtrunner ") + runnerArgs + QLatin1Char('\n'),
+ Utils::NormalMessageFormat);
+ }
+
+ if (connectProcess) {
+ connect(process, SIGNAL(started()), SIGNAL(started()));
+ connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
+ SLOT(onProcessFinished(int, QProcess::ExitStatus)));
+ connect(process, SIGNAL(error(QProcess::ProcessError)),
+ SLOT(onProcessError(QProcess::ProcessError)));
+ connect(process, SIGNAL(readyReadStandardOutput()), SLOT(onProcessReadyReadStdOut()));
+ connect(process, SIGNAL(readyReadStandardError()), SLOT(onProcessReadyReadStdErr()));
+ }
+
+ process->setUseCtrlCStub(true);
+ process->setCommand(m_runnerFilePath, runnerArgs);
+ process->setEnvironment(m_environment);
+ process->setWorkingDirectory(QFileInfo(m_executableFilePath).absolutePath());
+ process->start();
+}