Maemo: Use devrootsh only on remote systems that have MAD developer.

This commit is contained in:
Christian Kandeler
2011-04-26 12:10:37 +02:00
parent 701742168a
commit b2ef0926e3
18 changed files with 88 additions and 54 deletions

View File

@@ -370,14 +370,6 @@ void AbstractMaemoDeployStep::handleRemoteStderr(const QString &output)
}
}
MaemoPortList AbstractMaemoDeployStep::freePorts(const MaemoDeviceConfig::ConstPtr &devConf) const
{
const Qt4BuildConfiguration * const qt4bc = qt4BuildConfiguration();
if (!qt4bc)
return MaemoPortList();
return MaemoGlobal::freePorts(devConf, qt4bc->qtVersion());
}
const Qt4BuildConfiguration *AbstractMaemoDeployStep::qt4BuildConfiguration() const
{
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());

View File

@@ -93,7 +93,6 @@ protected:
QString deployMountPoint() const;
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
MaemoPortList freePorts(const QSharedPointer<const MaemoDeviceConfig> &devConfig) const;
QSharedPointer<Utils::SshConnection> connection() const { return m_connection; }
private slots:

View File

@@ -151,17 +151,20 @@ void MaemoConfigTestDialog::handleGeneralTestResult(int exitStatus)
m_ui->testResultEdit->setPlainText(output);
}
if (m_config->osVersion() == MaemoDeviceConfig::GenericLinux) {
switch (m_config->osVersion()) {
case MaemoDeviceConfig::Maemo5:
case MaemoDeviceConfig::Maemo6:
case MaemoDeviceConfig::Meego:
m_currentTest = MadDeveloperTest;
disconnect(m_testProcessRunner.data(),
SIGNAL(processOutputAvailable(QByteArray)), this,
SLOT(processSshOutput(QByteArray)));
m_testProcessRunner->run("test -x "
+ MaemoGlobal::devrootshPath().toUtf8());
break;
default:
testPorts();
return;
}
m_currentTest = MadDeveloperTest;
disconnect(m_testProcessRunner.data(),
SIGNAL(processOutputAvailable(QByteArray)), this,
SLOT(processSshOutput(QByteArray)));
const QByteArray command = "test -x " + MaemoGlobal::devrootshPath().toUtf8();
m_testProcessRunner->run(command);
}
void MaemoConfigTestDialog::handleMadDeveloperTestResult(int exitStatus)
@@ -208,8 +211,7 @@ void MaemoConfigTestDialog::handlePortListReady()
void MaemoConfigTestDialog::testPorts()
{
if (m_config->freePorts().hasMore())
m_portsGatherer->start(m_testProcessRunner->connection(),
m_config->freePorts());
m_portsGatherer->start(m_testProcessRunner->connection(), m_config);
else
finish();
}

View File

@@ -153,8 +153,8 @@ void AbstractMaemoDeployByMountStep::handleMountDebugOutput(const QString &outpu
void AbstractMaemoDeployByMountStep::mount()
{
m_extendedState = Mounting;
m_mounter->setupMounts(connection(), mountSpecifications(),
freePorts(helper().cachedDeviceConfig()), qt4BuildConfiguration());
m_mounter->setupMounts(connection(), helper().cachedDeviceConfig(),
mountSpecifications(), qt4BuildConfiguration());
}
QString AbstractMaemoDeployByMountStep::deployMountPoint() const
@@ -259,7 +259,8 @@ void MaemoMountAndInstallDeployStep::deploy()
{
const QString remoteFilePath = deployMountPoint() + QLatin1Char('/')
+ QFileInfo(packagingStep()->packageFilePath()).fileName();
m_installer->installPackage(connection(), remoteFilePath, false);
m_installer->installPackage(connection(), helper().cachedDeviceConfig(),
remoteFilePath, false);
}
void MaemoMountAndInstallDeployStep::cancelInstallation()
@@ -365,7 +366,8 @@ QList<MaemoMountSpecification> MaemoMountAndCopyDeployStep::mountSpecifications(
void MaemoMountAndCopyDeployStep::deploy()
{
m_copyFacility->copyFiles(connection(), m_filesToCopy, deployMountPoint());
m_copyFacility->copyFiles(connection(), helper().cachedDeviceConfig(),
m_filesToCopy, deployMountPoint());
}
void MaemoMountAndCopyDeployStep::handleFileCopied(const MaemoDeployable &deployable)

View File

@@ -67,15 +67,16 @@ MaemoDeploymentMounter::MaemoDeploymentMounter(QObject *parent)
}
void MaemoDeploymentMounter::setupMounts(const SshConnection::Ptr &connection,
const MaemoDeviceConfig::ConstPtr &devConf,
const QList<MaemoMountSpecification> &mountSpecs,
const MaemoPortList &freePorts, const Qt4BuildConfiguration *bc)
const Qt4BuildConfiguration *bc)
{
ASSERT_STATE(Inactive);
m_freePorts = freePorts;
m_mountSpecs = mountSpecs;
m_connection = connection;
m_mounter->setConnection(m_connection);
m_devConf = devConf;
m_mounter->setConnection(m_connection, m_devConf);
m_buildConfig = bc;
connect(m_connection.data(), SIGNAL(error(Utils::SshError)),
SLOT(handleConnectionError()));
@@ -136,7 +137,7 @@ void MaemoDeploymentMounter::handleUnmounted()
break;
case UnmountingCurrentDirs:
setState(GatheringPorts);
m_portsGatherer->start(m_connection, m_freePorts);
m_portsGatherer->start(m_connection, m_devConf);
break;
case UnmountingCurrentMounts:
setState(Inactive);
@@ -166,6 +167,7 @@ void MaemoDeploymentMounter::handlePortListReady()
return;
setState(Mounting);
m_freePorts = MaemoGlobal::freePorts(m_devConf, m_buildConfig->qtVersion());
m_mounter->mount(&m_freePorts, m_portsGatherer);
}

View File

@@ -45,6 +45,7 @@ namespace Utils { class SshConnection; }
namespace Qt4ProjectManager {
class Qt4BuildConfiguration;
namespace Internal {
class MaemoDeviceConfig;
class MaemoRemoteMounter;
class MaemoUsedPortsGatherer;
@@ -56,8 +57,9 @@ public:
// Connection must be in connected state.
void setupMounts(const QSharedPointer<Utils::SshConnection> &connection,
const QSharedPointer<const MaemoDeviceConfig> &devConf,
const QList<MaemoMountSpecification> &mountSpecs,
const MaemoPortList &freePorts, const Qt4BuildConfiguration *bc);
const Qt4BuildConfiguration *bc);
void tearDownMounts();
signals:
@@ -87,6 +89,7 @@ private:
State m_state;
QSharedPointer<Utils::SshConnection> m_connection;
QSharedPointer<const MaemoDeviceConfig> m_devConf;
MaemoRemoteMounter * const m_mounter;
MaemoUsedPortsGatherer * const m_portsGatherer;
MaemoPortList m_freePorts;

View File

@@ -127,16 +127,26 @@ QString MaemoGlobal::devrootshPath()
return QLatin1String("/usr/lib/mad-developer/devrootsh");
}
QString MaemoGlobal::remoteSudo(const QString &uname)
QString MaemoGlobal::remoteSudo(MaemoDeviceConfig::OsVersion osVersion,
const QString &uname)
{
return uname == QLatin1String("root") ? QString() : devrootshPath();
if (uname == QLatin1String("root"))
return QString();
switch (osVersion) {
case MaemoDeviceConfig::Maemo5:
case MaemoDeviceConfig::Maemo6:
case MaemoDeviceConfig::Meego:
return devrootshPath();
default:
return QLatin1String("sudo");
}
}
QString MaemoGlobal::remoteCommandPrefix(MaemoDeviceConfig::OsVersion osVersion,
const QString &userName, const QString &commandFilePath)
{
QString prefix = QString::fromLocal8Bit("%1 chmod a+x %2; %3; ")
.arg(remoteSudo(userName), commandFilePath, remoteSourceProfilesCommand());
.arg(remoteSudo(osVersion, userName), commandFilePath, remoteSourceProfilesCommand());
if (osVersion != MaemoDeviceConfig::Maemo5 && osVersion != MaemoDeviceConfig::Maemo6)
prefix += QLatin1String("DISPLAY=:0.0 ");
return prefix;

View File

@@ -83,7 +83,8 @@ public:
static QString homeDirOnDevice(const QString &uname);
static QString devrootshPath();
static QString remoteSudo(const QString &uname);
static QString remoteSudo(MaemoDeviceConfig::OsVersion,
const QString &uname);
static QString remoteCommandPrefix(MaemoDeviceConfig::OsVersion osVersion,
const QString &userName, const QString &commandFilePath);
static QString remoteEnvironment(const QList<Utils::EnvironmentItem> &list);

View File

@@ -50,7 +50,8 @@ AbstractMaemoPackageInstaller::AbstractMaemoPackageInstaller(QObject *parent)
AbstractMaemoPackageInstaller::~AbstractMaemoPackageInstaller() {}
void AbstractMaemoPackageInstaller::installPackage(const SshConnection::Ptr &connection,
const QString &packageFilePath, bool removePackageFile)
const MaemoDeviceConfig::ConstPtr &devConf, const QString &packageFilePath,
bool removePackageFile)
{
Q_ASSERT(connection && connection->state() == SshConnection::Connected);
Q_ASSERT(!m_isRunning);
@@ -69,7 +70,8 @@ void AbstractMaemoPackageInstaller::installPackage(const SshConnection::Ptr &con
const QString space = QLatin1String(" ");
QString cmdLine = QLatin1String("cd ") + workingDirectory()
+ QLatin1String(" && ")
+ MaemoGlobal::remoteSudo(m_installer->connection()->connectionParameters().userName)
+ MaemoGlobal::remoteSudo(devConf->osVersion(),
m_installer->connection()->connectionParameters().userName)
+ space + installCommand()
+ space + installCommandArguments().join(space) + space
+ packageFilePath;

View File

@@ -45,6 +45,7 @@ class SshRemoteProcessRunner;
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfig;
class AbstractMaemoPackageInstaller : public QObject
{
@@ -53,6 +54,7 @@ public:
~AbstractMaemoPackageInstaller();
void installPackage(const QSharedPointer<Utils::SshConnection> &connection,
const QSharedPointer<const MaemoDeviceConfig> &devConfig,
const QString &packageFilePath, bool removePackageFile);
void cancelInstallation();

View File

@@ -51,11 +51,13 @@ MaemoRemoteCopyFacility::MaemoRemoteCopyFacility(QObject *parent) :
MaemoRemoteCopyFacility::~MaemoRemoteCopyFacility() {}
void MaemoRemoteCopyFacility::copyFiles(const SshConnection::Ptr &connection,
const MaemoDeviceConfig::ConstPtr &devConf,
const QList<MaemoDeployable> &deployables, const QString &mountPoint)
{
Q_ASSERT(connection->state() == SshConnection::Connected);
Q_ASSERT(!m_isCopying);
m_devConf = devConf;
m_deployables = deployables;
m_mountPoint = mountPoint;
@@ -137,7 +139,8 @@ void MaemoRemoteCopyFacility::copyNextFile()
#endif
QString command = QString::fromLatin1("%1 mkdir -p %3 && %1 cp -r %2 %3")
.arg(MaemoGlobal::remoteSudo(m_copyRunner->connection()->connectionParameters().userName),
.arg(MaemoGlobal::remoteSudo(m_devConf->osVersion(),
m_copyRunner->connection()->connectionParameters().userName),
sourceFilePath, d.remoteDir);
emit progress(tr("Copying file '%1' to directory '%2' on the device...")
.arg(d.localFilePath, d.remoteDir));

View File

@@ -47,6 +47,7 @@ class SshRemoteProcessRunner;
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfig;
class MaemoRemoteCopyFacility : public QObject
{
@@ -56,6 +57,7 @@ public:
~MaemoRemoteCopyFacility();
void copyFiles(const QSharedPointer<Utils::SshConnection> &connection,
const QSharedPointer<const MaemoDeviceConfig> &devConf,
const QList<MaemoDeployable> &deployables, const QString &mountPoint);
void cancel();
@@ -77,6 +79,7 @@ private:
void setFinished();
QSharedPointer<Utils::SshRemoteProcessRunner> m_copyRunner;
QSharedPointer<const MaemoDeviceConfig> m_devConf;
QList<MaemoDeployable> m_deployables;
QString m_mountPoint;
bool m_isCopying;

View File

@@ -63,10 +63,12 @@ MaemoRemoteMounter::~MaemoRemoteMounter()
killAllUtfsServers();
}
void MaemoRemoteMounter::setConnection(const SshConnection::Ptr &connection)
void MaemoRemoteMounter::setConnection(const SshConnection::Ptr &connection,
const MaemoDeviceConfig::ConstPtr &devConf)
{
ASSERT_STATE(Inactive);
m_connection = connection;
m_devConf = devConf;
}
void MaemoRemoteMounter::setBuildConfiguration(const Qt4BuildConfiguration *bc)
@@ -121,10 +123,11 @@ void MaemoRemoteMounter::unmount()
}
QString remoteCall;
const QString remoteSudo = MaemoGlobal::remoteSudo(m_devConf->osVersion(),
m_connection->connectionParameters().userName);
for (int i = 0; i < m_mountSpecs.count(); ++i) {
remoteCall += QString::fromLocal8Bit("%1 umount %2 && %1 rmdir %2;")
.arg(MaemoGlobal::remoteSudo(m_connection->connectionParameters().userName),
m_mountSpecs.at(i).mountSpec.remoteMountPoint);
.arg(remoteSudo, m_mountSpecs.at(i).mountSpec.remoteMountPoint);
}
m_umountStderr.clear();
@@ -183,8 +186,8 @@ void MaemoRemoteMounter::stop()
void MaemoRemoteMounter::startUtfsClients()
{
const QString userName = m_connection->connectionParameters().userName;
const QString chmodFuse = MaemoGlobal::remoteSudo(userName)
+ QLatin1String(" chmod a+r+w /dev/fuse");
const QString chmodFuse = MaemoGlobal::remoteSudo(m_devConf->osVersion(),
userName) + QLatin1String(" chmod a+r+w /dev/fuse");
const QString chmodUtfsClient
= QLatin1String("chmod a+x ") + utfsClientOnDevice();
const QLatin1String andOp(" && ");
@@ -199,17 +202,21 @@ void MaemoRemoteMounter::startUtfsClients()
return;
}
const QString remoteSudo
= MaemoGlobal::remoteSudo(m_devConf->osVersion(), userName);
const MaemoMountSpecification &mountSpec = mountInfo.mountSpec;
const QString mkdir = QString::fromLocal8Bit("%1 mkdir -p %2")
.arg(MaemoGlobal::remoteSudo(userName), mountSpec.remoteMountPoint);
.arg(remoteSudo, mountSpec.remoteMountPoint);
const QString chmod = QString::fromLocal8Bit("%1 chmod a+r+w+x %2")
.arg(MaemoGlobal::remoteSudo(userName), mountSpec.remoteMountPoint);
.arg(remoteSudo, mountSpec.remoteMountPoint);
QString utfsClient
= QString::fromLocal8Bit("%1 -l %2 -r %2 -b %2 %4 -o nonempty")
.arg(utfsClientOnDevice()).arg(mountInfo.remotePort)
.arg(mountSpec.remoteMountPoint);
if (mountInfo.mountAsRoot)
utfsClient.prepend(MaemoGlobal::remoteSudo(userName) + QLatin1Char(' '));
if (mountInfo.mountAsRoot) {
utfsClient.prepend(MaemoGlobal::remoteSudo(m_devConf->osVersion(),
userName) + QLatin1Char(' '));
}
QLatin1String seqOp("; ");
remoteCall += seqOp + MaemoGlobal::remoteSourceProfilesCommand()
+ seqOp + mkdir + andOp + chmod + andOp + utfsClient;

View File

@@ -53,6 +53,7 @@ class SshRemoteProcess;
namespace Qt4ProjectManager {
class Qt4BuildConfiguration;
namespace Internal {
class MaemoDeviceConfig;
class MaemoUsedPortsGatherer;
class MaemoRemoteMounter : public QObject
@@ -63,7 +64,8 @@ public:
~MaemoRemoteMounter();
// Must already be connected.
void setConnection(const QSharedPointer<Utils::SshConnection> &connection);
void setConnection(const QSharedPointer<Utils::SshConnection> &connection,
const QSharedPointer<const MaemoDeviceConfig> &devConf);
void setBuildConfiguration(const Qt4BuildConfiguration *bc);
void addMountSpecification(const MaemoMountSpecification &mountSpec,
@@ -120,6 +122,7 @@ private:
};
QSharedPointer<Utils::SshConnection> m_connection;
QSharedPointer<const MaemoDeviceConfig> m_devConf;
QList<MountInfo> m_mountSpecs;
QSharedPointer<Utils::SshRemoteProcess> m_mountProcess;
QSharedPointer<Utils::SshRemoteProcess> m_unmountProcess;

View File

@@ -208,7 +208,7 @@ void MaemoSshRunner::handleCleanupFinished(int exitStatus)
emitError(tr("Initial cleanup failed: %1")
.arg(m_cleaner->errorString()));
} else {
m_mounter->setConnection(m_connection);
m_mounter->setConnection(m_connection, m_devConfig);
unmount();
}
}
@@ -228,7 +228,7 @@ void MaemoSshRunner::handleUnmounted()
}
case PreMountUnmounting:
setState(GatheringPorts);
m_portsGatherer->start(m_connection, m_freePorts);
m_portsGatherer->start(m_connection, m_devConfig);
break;
case PostRunCleaning:
case StopRequested: {
@@ -307,7 +307,7 @@ bool MaemoSshRunner::isConnectionUsable() const
void MaemoSshRunner::setState(State newState)
{
if (newState == Inactive) {
m_mounter->setConnection(SshConnection::Ptr());
m_mounter->setConnection(SshConnection::Ptr(), m_devConfig);
m_portsGatherer->stop();
if (m_connection) {
disconnect(m_connection.data(), 0, this, 0);

View File

@@ -155,7 +155,8 @@ void AbstractMaemoUploadAndInstallStep::handleUploadFinished(const QString &erro
+ QFileInfo(packagingStep()->packageFilePath()).fileName();
m_extendedState = Installing;
writeOutput(tr("Installing package to device..."));
m_installer->installPackage(connection(), remoteFilePath, true);
m_installer->installPackage(connection(), helper().cachedDeviceConfig(),
remoteFilePath, true);
}
}

View File

@@ -48,7 +48,7 @@ MaemoUsedPortsGatherer::MaemoUsedPortsGatherer(QObject *parent) :
MaemoUsedPortsGatherer::~MaemoUsedPortsGatherer() {}
void MaemoUsedPortsGatherer::start(const Utils::SshConnection::Ptr &connection,
const MaemoPortList &portList)
const MaemoDeviceConfig::ConstPtr &devConf)
{
if (m_running)
qWarning("Unexpected call of %s in running state", Q_FUNC_INFO);
@@ -64,8 +64,9 @@ void MaemoUsedPortsGatherer::start(const Utils::SshConnection::Ptr &connection,
SLOT(handleRemoteStdOut(QByteArray)));
connect(m_procRunner.data(), SIGNAL(processErrorOutputAvailable(QByteArray)),
SLOT(handleRemoteStdErr(QByteArray)));
const QString command = MaemoGlobal::remoteSudo(m_procRunner->connection()->connectionParameters().userName)
+ QLatin1String(" lsof -nPi4tcp:") + portList.toString()
const QString command = MaemoGlobal::remoteSudo(devConf->osVersion(),
m_procRunner->connection()->connectionParameters().userName)
+ QLatin1String(" lsof -nPi4tcp:") + devConf->freePorts().toString()
+ QLatin1String(" -F n |grep '^n' |sed -r 's/[^:]*:([[:digit:]]+).*/\\1/g' |sort -n |uniq");
m_procRunner->run(command.toUtf8());
m_running = true;

View File

@@ -46,6 +46,7 @@ class SshRemoteProcessRunner;
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfig;
class MaemoUsedPortsGatherer : public QObject
{
@@ -54,7 +55,7 @@ public:
explicit MaemoUsedPortsGatherer(QObject *parent = 0);
~MaemoUsedPortsGatherer();
void start(const QSharedPointer<Utils::SshConnection> &connection,
const MaemoPortList &portList);
const QSharedPointer<const MaemoDeviceConfig> &devConf);
void stop();
int getNextFreePort(MaemoPortList *freePorts) const; // returns -1 if no more are left
QList<int> usedPorts() const { return m_usedPorts; }