Commit 397869c9 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Don't hold a reference to a run config in a run control.

Save all relevant information at run control creation time, so we can
re-run even without a project.

Task-number: https://projects.maemo.org/bugzilla/show_bug.cgi?id=203698
parent f6fb0d82
......@@ -83,7 +83,8 @@ RunControl *MaemoDebugSupport::createDebugRunControl(MaemoRunConfiguration *runC
params.executable = runConfig->remoteExecutableFilePath();
params.debuggerCommand
= MaemoGlobal::remoteCommandPrefix(runConfig->remoteExecutableFilePath())
+ environment(runConfig) + QLatin1String(" /usr/bin/gdb");
+ environment(runConfig->debuggingType(), runConfig->userEnvironmentChanges())
+ QLatin1String(" /usr/bin/gdb");
params.connParams = devConf.server;
params.localMountDir = runConfig->localDirToMountForRemoteGdb();
params.remoteMountPoint
......@@ -116,9 +117,9 @@ RunControl *MaemoDebugSupport::createDebugRunControl(MaemoRunConfiguration *runC
MaemoDebugSupport::MaemoDebugSupport(MaemoRunConfiguration *runConfig,
DebuggerRunControl *runControl)
: QObject(runControl), m_runControl(runControl), m_runConfig(runConfig),
m_deviceConfig(m_runConfig->deviceConfig()),
m_runner(new MaemoSshRunner(this, m_runConfig, true)),
m_debuggingType(m_runConfig->debuggingType()),
m_runner(new MaemoSshRunner(this, runConfig, true)),
m_debuggingType(runConfig->debuggingType()),
m_dumperLib(runConfig->dumperLib()),
m_state(Inactive), m_gdbServerPort(-1), m_qmlPort(-1)
{
connect(m_runControl, SIGNAL(engineRequestSetup()), this,
......@@ -136,10 +137,6 @@ void MaemoDebugSupport::handleAdapterSetupRequested()
{
ASSERT_STATE(Inactive);
if (!m_deviceConfig.isValid()) {
handleAdapterSetupFailed(tr("No device configuration set for run configuration."));
return;
}
setState(StartingRunner);
m_runControl->showMessage(tr("Preparing remote side ..."), AppStuff);
disconnect(m_runner, 0, this, 0);
......@@ -178,11 +175,11 @@ void MaemoDebugSupport::startExecution()
return;
}
const QString &dumperLib = m_runConfig->dumperLib();
if (m_debuggingType != MaemoRunConfiguration::DebugQmlOnly
&& !dumperLib.isEmpty()
&& m_runConfig->deployStep()->currentlyNeedsDeployment(m_deviceConfig.server.host,
MaemoDeployable(dumperLib, uploadDir(m_deviceConfig)))) {
&& !m_dumperLib.isEmpty()
&& m_runConfig
&& m_runConfig->deployStep()->currentlyNeedsDeployment(m_runner->deviceConfig().server.host,
MaemoDeployable(m_dumperLib, uploadDir(m_runner->deviceConfig())))) {
setState(InitializingUploader);
m_uploader = m_runner->connection()->createSftpChannel();
connect(m_uploader.data(), SIGNAL(initialized()), this,
......@@ -205,18 +202,18 @@ void MaemoDebugSupport::handleSftpChannelInitialized()
ASSERT_STATE(InitializingUploader);
const QString dumperLib = m_runConfig->dumperLib();
const QString fileName = QFileInfo(dumperLib).fileName();
const QString remoteFilePath = uploadDir(m_deviceConfig) + '/' + fileName;
m_uploadJob = m_uploader->uploadFile(dumperLib, remoteFilePath,
const QString fileName = QFileInfo(m_dumperLib).fileName();
const QString remoteFilePath
= uploadDir(m_runner->deviceConfig()) + '/' + fileName;
m_uploadJob = m_uploader->uploadFile(m_dumperLib, remoteFilePath,
SftpOverwriteExisting);
if (m_uploadJob == SftpInvalidJob) {
handleAdapterSetupFailed(tr("Upload failed: Could not open file '%1'")
.arg(dumperLib));
.arg(m_dumperLib));
} else {
setState(UploadingDumpers);
m_runControl->showMessage(tr("Started uploading debugging helpers ('%1').")
.arg(dumperLib), AppStuff);
.arg(m_dumperLib), AppStuff);
}
}
......@@ -246,8 +243,10 @@ void MaemoDebugSupport::handleSftpJobFinished(Core::SftpJobId job,
.arg(error));
} else {
setState(DumpersUploaded);
m_runConfig->deployStep()->setDeployed(m_deviceConfig.server.host,
MaemoDeployable(m_runConfig->dumperLib(), uploadDir(m_deviceConfig)));
if (m_runConfig) {
m_runConfig->deployStep()->setDeployed(m_runner->deviceConfig().server.host,
MaemoDeployable(m_dumperLib, uploadDir(m_runner->deviceConfig())));
}
m_runControl->showMessage(tr("Finished uploading debugging helpers."), AppStuff);
startDebugging();
}
......@@ -267,10 +266,11 @@ void MaemoDebugSupport::startDebugging()
SLOT(handleRemoteErrorOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteOutput(QByteArray)), this,
SLOT(handleRemoteOutput(QByteArray)));
const QString &remoteExe = m_runConfig->remoteExecutableFilePath();
const QString &remoteExe = m_runner->remoteExecutable();
const QString cmdPrefix = MaemoGlobal::remoteCommandPrefix(remoteExe);
const QString env = environment(m_runConfig);
const QString args = m_runConfig->arguments().join(QLatin1String(" "));
const QString env
= environment(m_debuggingType, m_runner->userEnvChanges());
const QString args = m_runner->arguments().join(QLatin1String(" "));
const QString remoteCommandLine
= m_debuggingType == MaemoRunConfiguration::DebugQmlOnly
? QString::fromLocal8Bit("%1 %2 %3 %4").arg(cmdPrefix).arg(env)
......@@ -344,15 +344,15 @@ void MaemoDebugSupport::setState(State newState)
}
}
QString MaemoDebugSupport::environment(const MaemoRunConfiguration *rc)
QString MaemoDebugSupport::environment(MaemoRunConfiguration::DebuggingType debuggingType,
const QList<Utils::EnvironmentItem> &userEnvChanges)
{
QList<Utils::EnvironmentItem> env = rc->userEnvironmentChanges();
// FIXME: this must use command line argument instead: -qmljsdebugger=port:1234.
if (rc->debuggingType() != MaemoRunConfiguration::DebugCppOnly) {
if (debuggingType != MaemoRunConfiguration::DebugCppOnly) {
// env << Utils::EnvironmentItem(QLatin1String(Debugger::Constants::E_QML_DEBUG_SERVER_PORT),
// QString::number(qmlServerPort(rc)));
}
return MaemoGlobal::remoteEnvironment(env);
return MaemoGlobal::remoteEnvironment(userEnvChanges);
}
QString MaemoDebugSupport::uploadDir(const MaemoDeviceConfig &devConf)
......
......@@ -35,10 +35,10 @@
#ifndef MAEMODEBUGSUPPORT_H
#define MAEMODEBUGSUPPORT_H
#include "maemodeviceconfigurations.h"
#include "maemorunconfiguration.h"
#include <coreplugin/ssh/sftpdefs.h>
#include <utils/environment.h>
#include <QtCore/QObject>
#include <QtCore/QPointer>
......@@ -88,7 +88,8 @@ private:
DumpersUploaded, StartingRemoteProcess, Debugging
};
static QString environment(const MaemoRunConfiguration *rc);
static QString environment(MaemoRunConfiguration::DebuggingType debuggingType,
const QList<Utils::EnvironmentItem> &userEnvChanges);
void handleAdapterSetupFailed(const QString &error);
void handleAdapterSetupDone();
......@@ -98,10 +99,10 @@ private:
bool setPort(int &port);
const QPointer<Debugger::DebuggerRunControl> m_runControl;
MaemoRunConfiguration * const m_runConfig;
const MaemoDeviceConfig m_deviceConfig;
const QPointer<MaemoRunConfiguration> m_runConfig;
MaemoSshRunner * const m_runner;
const MaemoRunConfiguration::DebuggingType m_debuggingType;
const QString m_dumperLib;
QSharedPointer<Core::SftpChannel> m_uploader;
Core::SftpJobId m_uploadJob;
......
......@@ -48,7 +48,7 @@ namespace Qt4ProjectManager {
namespace Internal {
MaemoRemoteMounter::MaemoRemoteMounter(QObject *parent)
: QObject(parent), m_toolChain(0), m_utfsServerTimer(new QTimer(this)),
: QObject(parent), m_utfsServerTimer(new QTimer(this)),
m_uploadJobId(SftpInvalidJob), m_state(Inactive)
{
connect(m_utfsServerTimer, SIGNAL(timeout()), this,
......@@ -60,20 +60,25 @@ MaemoRemoteMounter::~MaemoRemoteMounter()
killAllUtfsServers();
}
void MaemoRemoteMounter::setConnection(const Core::SshConnection::Ptr &connection)
void MaemoRemoteMounter::setConnection(const SshConnection::Ptr &connection)
{
ASSERT_STATE(Inactive);
m_connection = connection;
}
void MaemoRemoteMounter::setToolchain(const MaemoToolChain *toolChain)
{
ASSERT_STATE(Inactive);
m_remoteMountsAllowed = toolChain->allowsRemoteMounts();
m_maddeRoot = toolChain->maddeRoot();
}
void MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mountSpec,
bool mountAsRoot)
{
Q_ASSERT(m_toolChain);
ASSERT_STATE(Inactive);
if (m_toolChain->allowsRemoteMounts() && mountSpec.isValid())
if (m_remoteMountsAllowed && mountSpec.isValid())
m_mountSpecs << MountInfo(mountSpec, mountAsRoot);
}
......@@ -204,7 +209,7 @@ void MaemoRemoteMounter::handleUploaderInitialized()
SIGNAL(finished(Core::SftpJobId, QString)), this,
SLOT(handleUploadFinished(Core::SftpJobId, QString)));
const QString localFile
= m_toolChain->maddeRoot() + QLatin1String("/madlib/armel/utfs-client");
= m_maddeRoot + QLatin1String("/madlib/armel/utfs-client");
m_uploadJobId = m_utfsClientUploader->uploadFile(localFile,
utfsClientOnDevice(), SftpOverwriteExisting);
if (m_uploadJobId == SftpInvalidJob) {
......@@ -405,7 +410,7 @@ QString MaemoRemoteMounter::utfsClientOnDevice() const
QString MaemoRemoteMounter::utfsServer() const
{
return m_toolChain->maddeRoot() + QLatin1String("/madlib/utfs-server");
return m_maddeRoot + QLatin1String("/madlib/utfs-server");
}
void MaemoRemoteMounter::killAllUtfsServers()
......
......@@ -60,7 +60,11 @@ class MaemoRemoteMounter : public QObject
public:
MaemoRemoteMounter(QObject *parent);
~MaemoRemoteMounter();
void setToolchain(const MaemoToolChain *toolchain) { m_toolChain = toolchain; }
// Must already be connected.
void setConnection(const QSharedPointer<Core::SshConnection> &connection);
void setToolchain(const MaemoToolChain *toolChain);
void addMountSpecification(const MaemoMountSpecification &mountSpec,
bool mountAsRoot);
bool hasValidMountSpecifications() const;
......@@ -70,9 +74,6 @@ public:
void unmount();
void stop();
// Must be connected already.
void setConnection(const QSharedPointer<Core::SshConnection> &connection);
signals:
void mounted();
void unmounted();
......@@ -111,7 +112,6 @@ private:
QString utfsClientOnDevice() const;
QString utfsServer() const;
const MaemoToolChain *m_toolChain;
QTimer * const m_utfsServerTimer;
struct MountInfo {
......@@ -136,6 +136,8 @@ private:
QByteArray m_umountStderr;
MaemoPortList *m_freePorts;
const MaemoUsedPortsGatherer *m_portsGatherer;
bool m_remoteMountsAllowed;
QString m_maddeRoot;
State m_state;
};
......
......@@ -49,6 +49,7 @@ public:
int validMountSpecificationCount() const;
MaemoMountSpecification mountSpecificationAt(int pos) const { return m_mountSpecs.at(pos); }
bool hasValidMountSpecifications() const;
const QList<MaemoMountSpecification> &mountSpecs() const { return m_mountSpecs; }
void addMountSpecification(const QString &localDir);
void removeMountSpecificationAt(int pos);
......
......@@ -53,9 +53,7 @@ using ProjectExplorer::RunConfiguration;
MaemoRunControl::MaemoRunControl(RunConfiguration *rc)
: RunControl(rc, ProjectExplorer::Constants::RUNMODE)
, m_runConfig(qobject_cast<MaemoRunConfiguration *>(rc))
, m_devConfig(m_runConfig ? m_runConfig->deviceConfig() : MaemoDeviceConfig())
, m_runner(new MaemoSshRunner(this, m_runConfig, false))
, m_runner(new MaemoSshRunner(this, qobject_cast<MaemoRunConfiguration *>(rc), false))
, m_running(false)
{
}
......@@ -67,32 +65,24 @@ MaemoRunControl::~MaemoRunControl()
void MaemoRunControl::start()
{
if (!m_devConfig.isValid()) {
handleError(tr("No device configuration set for run configuration."));
} else if (!m_runConfig) {
handleError(tr("Run configuration no longer available."));
} else {
m_running = true;
emit started();
disconnect(m_runner, 0, this, 0);
connect(m_runner, SIGNAL(error(QString)), this,
SLOT(handleSshError(QString)));
connect(m_runner, SIGNAL(readyForExecution()), this,
SLOT(startExecution()));
connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)), this,
SLOT(handleRemoteErrorOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteOutput(QByteArray)), this,
SLOT(handleRemoteOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteProcessStarted()), this,
SLOT(handleRemoteProcessStarted()));
connect(m_runner, SIGNAL(remoteProcessFinished(qint64)), this,
SLOT(handleRemoteProcessFinished(qint64)));
connect(m_runner, SIGNAL(reportProgress(QString)), this,
SLOT(handleProgressReport(QString)));
connect(m_runner, SIGNAL(mountDebugOutput(QString)), this,
SLOT(handleMountDebugOutput(QString)));
m_runner->start();
}
m_running = true;
emit started();
disconnect(m_runner, 0, this, 0);
connect(m_runner, SIGNAL(error(QString)), SLOT(handleSshError(QString)));
connect(m_runner, SIGNAL(readyForExecution()), SLOT(startExecution()));
connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
SLOT(handleRemoteErrorOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
SLOT(handleRemoteOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteProcessStarted()),
SLOT(handleRemoteProcessStarted()));
connect(m_runner, SIGNAL(remoteProcessFinished(qint64)),
SLOT(handleRemoteProcessFinished(qint64)));
connect(m_runner, SIGNAL(reportProgress(QString)),
SLOT(handleProgressReport(QString)));
connect(m_runner, SIGNAL(mountDebugOutput(QString)),
SLOT(handleMountDebugOutput(QString)));
m_runner->start();
}
ProjectExplorer::RunControl::StopResult MaemoRunControl::stop()
......@@ -110,12 +100,11 @@ void MaemoRunControl::handleSshError(const QString &error)
void MaemoRunControl::startExecution()
{
emit appendMessage(this, tr("Starting remote process ..."), false);
const QString &remoteExe = m_runConfig->remoteExecutableFilePath();
m_runner->startExecution(QString::fromLocal8Bit("%1 %2 %3 %4")
.arg(MaemoGlobal::remoteCommandPrefix(remoteExe))
.arg(MaemoGlobal::remoteEnvironment(m_runConfig->userEnvironmentChanges()))
.arg(remoteExe)
.arg(m_runConfig->arguments().join(QLatin1String(" "))).toUtf8());
.arg(MaemoGlobal::remoteCommandPrefix(m_runner->remoteExecutable()))
.arg(MaemoGlobal::remoteEnvironment(m_runner->userEnvChanges()))
.arg(m_runner->remoteExecutable())
.arg(m_runner->arguments().join(QLatin1String(" "))).toUtf8());
}
void MaemoRunControl::handleRemoteProcessFinished(qint64 exitCode)
......
......@@ -35,11 +35,8 @@
#ifndef MAEMORUNCONTROL_H
#define MAEMORUNCONTROL_H
#include "maemodeviceconfigurations.h"
#include <projectexplorer/runconfiguration.h>
#include <QtCore/QPointer>
#include <QtCore/QString>
namespace Qt4ProjectManager {
......@@ -72,8 +69,6 @@ private:
void setFinished();
void handleError(const QString &errString);
QPointer<MaemoRunConfiguration> m_runConfig;
const MaemoDeviceConfig m_devConfig;
MaemoSshRunner * const m_runner;
bool m_running;
};
......
......@@ -58,14 +58,25 @@ namespace Internal {
MaemoSshRunner::MaemoSshRunner(QObject *parent,
MaemoRunConfiguration *runConfig, bool debugging)
: QObject(parent), m_runConfig(runConfig),
: QObject(parent),
m_mounter(new MaemoRemoteMounter(this)),
m_portsGatherer(new MaemoUsedPortsGatherer(this)),
m_devConfig(runConfig->deviceConfig()),
m_freePorts(runConfig->freePorts()),
m_debugging(debugging), m_state(Inactive)
m_remoteExecutable(runConfig->remoteExecutableFilePath()),
m_appArguments(runConfig->arguments()),
m_userEnvChanges(runConfig->userEnvironmentChanges()),
m_initialFreePorts(runConfig->freePorts()),
m_mountSpecs(runConfig->remoteMounts()->mountSpecs()),
m_state(Inactive)
{
m_procsToKill << QFileInfo(m_runConfig->localExecutableFilePath()).fileName();
m_connection = runConfig->deployStep()->sshConnection();
m_mounter->setToolchain(runConfig->toolchain());
if (debugging && runConfig->useRemoteGdb()) {
m_mountSpecs << MaemoMountSpecification(runConfig->localDirToMountForRemoteGdb(),
runConfig->remoteProjectSourcesMountPoint());
}
m_procsToKill << QFileInfo(m_remoteExecutable).fileName();
connect(m_mounter, SIGNAL(mounted()), this, SLOT(handleMounted()));
connect(m_mounter, SIGNAL(unmounted()), this, SLOT(handleUnmounted()));
connect(m_mounter, SIGNAL(error(QString)), this,
......@@ -86,11 +97,20 @@ void MaemoSshRunner::start()
{
ASSERT_STATE(QList<State>() << Inactive << StopRequested);
if (m_remoteExecutable.isEmpty()) {
emitError(tr("Cannot run: No remote executable set."));
return;
}
if (!m_devConfig.isValid()) {
emitError(tr("Cannot run: No device configuration set."));
return;
}
setState(Connecting);
m_exitStatus = -1;
m_freePorts = m_initialFreePorts;
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
m_connection = m_runConfig->deployStep()->sshConnection();
const bool reUse = isConnectionUsable();
if (!reUse)
m_connection = SshConnection::create();
......@@ -193,17 +213,8 @@ void MaemoSshRunner::handleUnmounted()
switch (m_state) {
case PreRunCleaning: {
m_mounter->resetMountSpecifications();
m_mounter->setToolchain(m_runConfig->toolchain());
const MaemoRemoteMountsModel * const remoteMounts
= m_runConfig->remoteMounts();
for (int i = 0; i < remoteMounts->mountSpecificationCount(); ++i)
m_mounter->addMountSpecification(remoteMounts->mountSpecificationAt(i), false);
if (m_debugging && m_runConfig->useRemoteGdb()) {
m_mounter->addMountSpecification(MaemoMountSpecification(
m_runConfig->localDirToMountForRemoteGdb(),
m_runConfig->remoteProjectSourcesMountPoint()), false);
}
for (int i = 0; i < m_mountSpecs.count(); ++i)
m_mounter->addMountSpecification(m_mountSpecs.at(i), false);
setState(PreMountUnmounting);
unmount();
break;
......@@ -253,11 +264,6 @@ void MaemoSshRunner::startExecution(const QByteArray &remoteCall)
{
ASSERT_STATE(ReadyForExecution);
if (m_runConfig->remoteExecutableFilePath().isEmpty()) {
emitError(tr("Cannot run: No remote executable set."));
return;
}
m_runner = m_connection->createRemoteProcess(remoteCall);
connect(m_runner.data(), SIGNAL(started()), this,
SIGNAL(remoteProcessStarted()));
......
......@@ -38,6 +38,8 @@
#include "maemodeviceconfigurations.h"
#include "maemomountspecification.h"
#include <utils/environment.h>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QStringList>
......@@ -70,6 +72,10 @@ public:
const MaemoUsedPortsGatherer *usedPortsGatherer() const { return m_portsGatherer; }
MaemoPortList *freePorts() { return &m_freePorts; }
MaemoDeviceConfig deviceConfig() const { return m_devConfig; }
QString remoteExecutable() const { return m_remoteExecutable; }
QStringList arguments() const { return m_appArguments; }
QList<Utils::EnvironmentItem> userEnvChanges() const { return m_userEnvChanges; }
static const qint64 InvalidExitCode;
......@@ -108,10 +114,14 @@ private:
void mount();
void unmount();
MaemoRunConfiguration * const m_runConfig; // TODO this pointer can be invalid
MaemoRemoteMounter * const m_mounter;
MaemoUsedPortsGatherer * const m_portsGatherer;
const MaemoDeviceConfig m_devConfig;
const QString m_remoteExecutable;
const QStringList m_appArguments;
const QList<Utils::EnvironmentItem> m_userEnvChanges;
const MaemoPortList m_initialFreePorts;
QList<MaemoMountSpecification> m_mountSpecs;
QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_runner;
......@@ -120,7 +130,6 @@ private:
MaemoPortList m_freePorts;
int m_exitStatus;
const bool m_debugging;
State m_state;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment