Commit 3cb34cf8 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Move MADDE environment information out of MaemoToolChain class.

The toolchain is not available in all places where we need the
respective information, which resulted in duplicated code.
parent d909d8ba
......@@ -33,7 +33,7 @@
#include "maemodeployablelistmodel.h"
#include "maemotoolchain.h"
#include "maemoglobal.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
......@@ -255,10 +255,10 @@ bool MaemoDeployableListModel::addDesktopFile(QString &error)
return false;
}
const MaemoToolChain *const tc = maemoToolchain();
QTC_ASSERT(tc, return false);
const QtVersion * const version = qtVersion();
QTC_ASSERT(version, return false);
QString remoteDir = QLatin1String("/usr/share/applications");
if (tc->version() == MaemoToolChain::Maemo5)
if (MaemoGlobal::version(version) == MaemoGlobal::Maemo5)
remoteDir += QLatin1String("/hildon");
const QLatin1String filesLine("desktopfile.files = $${TARGET}.desktop");
const QString pathLine = QLatin1String("desktopfile.path = ") + remoteDir;
......@@ -333,7 +333,7 @@ bool MaemoDeployableListModel::addLinesToProFile(const QStringList &lines)
return true;
}
const MaemoToolChain *MaemoDeployableListModel::maemoToolchain() const
const QtVersion *MaemoDeployableListModel::qtVersion() const
{
const ProjectExplorer::Project *const activeProject
= ProjectExplorer::ProjectExplorerPlugin::instance()->session()->startupProject();
......@@ -344,25 +344,22 @@ const MaemoToolChain *MaemoDeployableListModel::maemoToolchain() const
const Qt4BuildConfiguration *const bc
= activeTarget->activeBuildConfiguration();
QTC_ASSERT(bc, return 0);
const MaemoToolChain *const tc
= dynamic_cast<MaemoToolChain *>(bc->toolChain());
QTC_ASSERT(tc, return 0);
return tc;
return bc->qtVersion();
}
QString MaemoDeployableListModel::proFileScope() const
{
const MaemoToolChain *const tc = maemoToolchain();
QTC_ASSERT(tc, return QString());
return QLatin1String(tc->version() == MaemoToolChain::Maemo5
const QtVersion *const qv = qtVersion();
QTC_ASSERT(qv, return QString());
return QLatin1String(MaemoGlobal::version(qv) == MaemoGlobal::Maemo5
? "maemo5" : "unix:!symbian:!maemo5");
}
QString MaemoDeployableListModel::installPrefix() const
{
const MaemoToolChain *const tc = maemoToolchain();
QTC_ASSERT(tc, return QString());
return QLatin1String(tc->version() == MaemoToolChain::Maemo5
const QtVersion *const qv = qtVersion();
QTC_ASSERT(qv, return QString());
return QLatin1String(MaemoGlobal::version(qv) == MaemoGlobal::Maemo5
? "/opt/usr" : "/usr");
}
......
......@@ -45,8 +45,8 @@
#include <QtCore/QString>
namespace Qt4ProjectManager {
class QtVersion;
namespace Internal {
class MaemoToolChain;
class MaemoDeployableListModel : public QAbstractTableModel
{
......@@ -98,7 +98,7 @@ private:
bool isEditable(const QModelIndex &index) const;
bool buildModel();
bool addLinesToProFile(const QStringList &lines);
const MaemoToolChain *maemoToolchain() const;
const QtVersion *qtVersion() const;
QString proFileScope() const;
QString installPrefix() const;
......
......@@ -455,12 +455,15 @@ void MaemoDeployStep::handleUnmounted()
m_mounter->resetMountSpecifications();
setState(Inactive);
break;
case UnmountingOldDirs:
if (toolChain()->allowsRemoteMounts())
case UnmountingOldDirs: {
const Qt4BuildConfiguration * const bc
= static_cast<Qt4BuildConfiguration *>(buildConfiguration());
if (MaemoGlobal::allowsRemoteMounts(bc->qtVersion()))
setupMount();
else
prepareSftpConnection();
break;
}
case UnmountingCurrentDirs:
setState(GatheringPorts);
m_portsGatherer->start(m_connection, deviceConfig().freePorts());
......@@ -519,7 +522,7 @@ void MaemoDeployStep::setupMount()
Q_ASSERT(m_needsInstall || !m_filesToCopy.isEmpty());
m_mounter->resetMountSpecifications();
m_mounter->setToolchain(toolChain());
m_mounter->setBuildConfiguration(static_cast<Qt4BuildConfiguration *>(buildConfiguration()));
if (m_needsInstall) {
const QString localDir
= QFileInfo(packagingStep()->packageFilePath()).absolutePath();
......@@ -579,11 +582,13 @@ void MaemoDeployStep::installToSysroot()
if (m_needsInstall) {
writeOutput(tr("Installing package to sysroot ..."));
const MaemoToolChain * const tc = toolChain();
const Qt4BuildConfiguration * const bc
= static_cast<Qt4BuildConfiguration *>(buildConfiguration());
const QtVersion * const qtVersion = bc->qtVersion();
const QStringList args = QStringList() << QLatin1String("-t")
<< tc->targetName() << QLatin1String("xdpkg") << QLatin1String("-i")
<< packagingStep()->packageFilePath();
m_sysrootInstaller->start(tc->madAdminCommand(), args);
<< MaemoGlobal::targetName(qtVersion) << QLatin1String("xdpkg")
<< QLatin1String("-i") << packagingStep()->packageFilePath();
MaemoGlobal::callMadAdmin(*m_sysrootInstaller, args, qtVersion);
if (!m_sysrootInstaller->waitForStarted()) {
writeOutput(tr("Installation to sysroot failed, continuing anyway."),
ErrorMessageOutput);
......
......@@ -37,6 +37,7 @@
#include "maemodeviceconfigurations.h"
#include <coreplugin/ssh/sshconnection.h>
#include <qt4projectmanager/qtversionmanager.h>
#include <utils/environment.h>
#include <QtCore/QCoreApplication>
......@@ -107,17 +108,42 @@ QString MaemoGlobal::failedToConnectToServerMessage(const Core::SshConnection::P
return errorMsg;
}
QString MaemoGlobal::maddeRoot(const QString &qmakePath)
QString MaemoGlobal::maddeRoot(const QtVersion *qtVersion)
{
QDir dir(QDir::cleanPath(qmakePath).remove(binQmake));
QDir dir(targetRoot(qtVersion));
dir.cdUp(); dir.cdUp();
return dir.absolutePath();
}
QString MaemoGlobal::targetName(const QString &qmakePath)
QString MaemoGlobal::targetRoot(const QtVersion *qtVersion)
{
const QString target = QDir::cleanPath(qmakePath).remove(binQmake);
return target.mid(target.lastIndexOf(QLatin1Char('/')) + 1);
return QDir::cleanPath(qtVersion->qmakeCommand()).remove(binQmake);
}
QString MaemoGlobal::targetName(const QtVersion *qtVersion)
{
return QDir(targetRoot(qtVersion)).dirName();
}
QString MaemoGlobal::madAdminCommand(const QtVersion *qtVersion)
{
return maddeRoot(qtVersion) + QLatin1String("/bin/mad-admin");
}
QString MaemoGlobal::madCommand(const QtVersion *qtVersion)
{
return maddeRoot(qtVersion) + QLatin1String("/bin/mad");
}
MaemoGlobal::MaemoVersion MaemoGlobal::version(const QtVersion *qtVersion)
{
const QString &name = targetName(qtVersion);
if (name.startsWith(QLatin1String("fremantle")))
return Maemo5;
if (name.startsWith(QLatin1String("harmattan")))
return Maemo6;
qWarning("Unknown Maemo version!");
return static_cast<MaemoVersion>(-1);
}
bool MaemoGlobal::removeRecursively(const QString &filePath, QString &error)
......@@ -150,9 +176,25 @@ bool MaemoGlobal::removeRecursively(const QString &filePath, QString &error)
return true;
}
void MaemoGlobal::callMaddeShellScript(QProcess &proc, const QString &maddeRoot,
bool MaemoGlobal::callMad(QProcess &proc, const QStringList &args,
const QtVersion *qtVersion)
{
return callMaddeShellScript(proc, maddeRoot(qtVersion),
madCommand(qtVersion), args);
}
bool MaemoGlobal::callMadAdmin(QProcess &proc, const QStringList &args,
const QtVersion *qtVersion)
{
return callMaddeShellScript(proc, maddeRoot(qtVersion),
madAdminCommand(qtVersion), args);
}
bool MaemoGlobal::callMaddeShellScript(QProcess &proc, const QString &maddeRoot,
const QString &command, const QStringList &args)
{
if (!QFileInfo(command).exists())
return false;
QString actualCommand = command;
QStringList actualArgs = args;
#ifdef Q_OS_WIN
......@@ -167,6 +209,7 @@ void MaemoGlobal::callMaddeShellScript(QProcess &proc, const QString &maddeRoot,
Q_UNUSED(maddeRoot);
#endif
proc.start(actualCommand, actualArgs);
return true;
}
} // namespace Internal
......
......@@ -54,12 +54,15 @@ QT_END_NAMESPACE
namespace Core { class SshConnection; }
namespace Qt4ProjectManager {
class QtVersion;
namespace Internal {
class MaemoDeviceConfig;
class MaemoGlobal
{
public:
enum MaemoVersion { Maemo5, Maemo6 };
static QString homeDirOnDevice(const QString &uname);
static QString remoteSudo();
static QString remoteCommandPrefix(const QString &commandFilePath);
......@@ -67,12 +70,22 @@ public:
static QString remoteSourceProfilesCommand();
static QString failedToConnectToServerMessage(const QSharedPointer<Core::SshConnection> &connection,
const MaemoDeviceConfig &deviceConfig);
static QString maddeRoot(const QString &qmakePath);
static QString targetName(const QString &qmakePath);
static QString maddeRoot(const QtVersion *qtVersion);
static QString targetRoot(const QtVersion *qtVersion);
static QString targetName(const QtVersion *qtVersion);
static QString madCommand(const QtVersion *qtVersion);
static MaemoVersion version(const QtVersion *qtVersion);
static bool allowsRemoteMounts(const QtVersion *qtVersion) { return version(qtVersion) == Maemo5; }
static bool allowsPackagingDisabling(const QtVersion *qtVersion) { return version(qtVersion) == Maemo5; }
static bool allowsQmlDebugging(const QtVersion *qtVersion) { return version(qtVersion) == Maemo6; }
static bool callMad(QProcess &proc, const QStringList &args,
const QtVersion *qtVersion);
static bool callMadAdmin(QProcess &proc, const QStringList &args,
const QtVersion *qtVersion);
static bool removeRecursively(const QString &filePath, QString &error);
static void callMaddeShellScript(QProcess &proc, const QString &maddeRoot,
const QString &command, const QStringList &args);
template<class T> static T *buildStep(const ProjectExplorer::DeployConfiguration *dc)
{
......@@ -101,6 +114,11 @@ public:
actual, func);
}
}
private:
static QString madAdminCommand(const QtVersion *qtVersion);
static bool callMaddeShellScript(QProcess &proc, const QString &maddeRoot,
const QString &command, const QStringList &args);
};
} // namespace Internal
......
......@@ -110,26 +110,18 @@ MaemoManager &MaemoManager::instance()
bool MaemoManager::isValidMaemoQtVersion(const QtVersion *version) const
{
QString path = QDir::cleanPath(version->qmakeCommand());
path.remove(QLatin1String("/bin/qmake" EXEC_SUFFIX));
QDir dir(path);
const QByteArray target = dir.dirName().toAscii();
dir.cdUp(); dir.cdUp();
const QString madAdminCommand(dir.absolutePath() + QLatin1String("/bin/mad-admin"));
if (!QFileInfo(madAdminCommand).exists())
return false;
QProcess madAdminProc;
const QStringList arguments(QLatin1String("list"));
MaemoGlobal::callMaddeShellScript(madAdminProc, dir.absolutePath(),
madAdminCommand, arguments);
if (!MaemoGlobal::callMadAdmin(madAdminProc, arguments, version))
return false;
if (!madAdminProc.waitForStarted() || !madAdminProc.waitForFinished())
return false;
madAdminProc.setReadChannel(QProcess::StandardOutput);
const QByteArray targetName = MaemoGlobal::targetName(version).toAscii();
while (madAdminProc.canReadLine()) {
const QByteArray &line = madAdminProc.readLine();
if (line.contains(target)
if (line.contains(targetName)
&& (line.contains("(installed)") || line.contains("(default)")))
return true;
}
......@@ -138,9 +130,7 @@ bool MaemoManager::isValidMaemoQtVersion(const QtVersion *version) const
ToolChain* MaemoManager::maemoToolChain(const QtVersion *version) const
{
QString targetRoot = QDir::cleanPath(version->qmakeCommand());
targetRoot.remove(QLatin1String("/bin/qmake" EXEC_SUFFIX));
return new MaemoToolChain(targetRoot);
return new MaemoToolChain(version);
}
} // namespace Internal
......
......@@ -47,7 +47,6 @@
#include "maemoglobal.h"
#include "maemopackagecreationwidget.h"
#include "maemotemplatesmanager.h"
#include "maemotoolchain.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorerconstants.h>
......@@ -172,16 +171,17 @@ bool MaemoPackageCreationStep::createPackage(QProcess *buildProc)
if (!copyDebianFiles(inSourceBuild))
return false;
const QString maddeRoot = maemoToolChain()->maddeRoot();
const QString madCommand = maddeRoot + QLatin1String("/bin/mad");
const QtVersion * const qtVersion = qt4BuildConfiguration()->qtVersion();
const QString madCommand = MaemoGlobal::madCommand(qtVersion);
const QStringList args = QStringList() << QLatin1String("-t")
<< maemoToolChain()->targetName() << QLatin1String("dpkg-buildpackage")
<< QLatin1String("-nc") << QLatin1String("-uc") << QLatin1String("-us");
<< MaemoGlobal::targetName(qtVersion)
<< QLatin1String("dpkg-buildpackage") << QLatin1String("-nc")
<< QLatin1String("-uc") << QLatin1String("-us");
const QString cmdLine = madCommand + QLatin1Char(' ')
+ args.join(QLatin1String(" "));
emit addOutput(tr("Package Creation: Running command '%1'.").arg(cmdLine),
BuildStep::MessageOutput);
MaemoGlobal::callMaddeShellScript(*buildProc, maddeRoot, madCommand, args);
MaemoGlobal::callMad(*buildProc, args, qtVersion);
if (!buildProc->waitForStarted()) {
raiseError(tr("Packaging failed."),
tr("Packaging error: Could not start command '%1'. Reason: %2")
......@@ -233,7 +233,7 @@ bool MaemoPackageCreationStep::createPackage(QProcess *buildProc)
emit addOutput(tr("Package created."), BuildStep::MessageOutput);
deployStep()->deployables()->setUnmodified();
if (inSourceBuild) {
buildProc->start(packagingCommand(maemoToolChain(),
buildProc->start(packagingCommand(qt4BuildConfiguration(),
QLatin1String("dh_clean")));
buildProc->waitForFinished();
buildProc->terminate();
......@@ -341,11 +341,6 @@ QString MaemoPackageCreationStep::projectName() const
->rootProjectNode()->displayName().toLower();
}
const MaemoToolChain *MaemoPackageCreationStep::maemoToolChain() const
{
return static_cast<MaemoToolChain *>(qt4BuildConfiguration()->toolChain());
}
MaemoDeployStep *MaemoPackageCreationStep::deployStep() const
{
MaemoDeployStep * const deployStep
......@@ -355,16 +350,6 @@ MaemoDeployStep *MaemoPackageCreationStep::deployStep() const
return deployStep;
}
QString MaemoPackageCreationStep::maddeRoot() const
{
return maemoToolChain()->maddeRoot();
}
QString MaemoPackageCreationStep::targetRoot() const
{
return maemoToolChain()->targetRoot();
}
bool MaemoPackageCreationStep::packagingNeeded() const
{
const QSharedPointer<MaemoDeployables> &deployables
......@@ -427,7 +412,8 @@ QString MaemoPackageCreationStep::packageFilePath() const
bool MaemoPackageCreationStep::isPackagingEnabled() const
{
return m_packagingEnabled || !maemoToolChain()->allowsPackagingDisabling();
return m_packagingEnabled
|| !MaemoGlobal::allowsPackagingDisabling(qt4BuildConfiguration()->qtVersion());
}
QString MaemoPackageCreationStep::versionString(QString *error) const
......@@ -463,13 +449,8 @@ void MaemoPackageCreationStep::raiseError(const QString &shortMsg,
bool MaemoPackageCreationStep::preparePackagingProcess(QProcess *proc,
const Qt4BuildConfiguration *bc, const QString &workingDir, QString *error)
{
const MaemoToolChain * const tc
= dynamic_cast<const MaemoToolChain *>(bc->toolChain());
if (!tc) {
*error = tr("Build configuration has no Maemo toolchain.");
return false;
}
QFile configFile(tc->targetRoot() % QLatin1String("/config.sh"));
const QString targetRoot = MaemoGlobal::targetRoot(bc->qtVersion());
QFile configFile(targetRoot % QLatin1String("/config.sh"));
if (!configFile.open(QIODevice::ReadOnly)) {
*error = tr("Cannot open MADDE config file '%1'.")
.arg(nativePath(configFile));
......@@ -478,11 +459,12 @@ bool MaemoPackageCreationStep::preparePackagingProcess(QProcess *proc,
Utils::Environment env = bc->environment();
const QString &path
= QDir::toNativeSeparators(tc->maddeRoot() + QLatin1Char('/'));
= QDir::toNativeSeparators(MaemoGlobal::maddeRoot(bc->qtVersion())
+ QLatin1Char('/'));
#ifdef Q_OS_WIN
env.prependOrSetPath(path % QLatin1String("bin"));
#endif
env.prependOrSetPath(tc->targetRoot() % QLatin1String("/bin"));
env.prependOrSetPath(targetRoot % QLatin1String("/bin"));
env.prependOrSetPath(path % QLatin1String("madbin"));
if (bc->qmakeBuildConfiguration() & QtVersion::DebugBuild) {
......@@ -512,14 +494,15 @@ bool MaemoPackageCreationStep::preparePackagingProcess(QProcess *proc,
return true;
}
QString MaemoPackageCreationStep::packagingCommand(const MaemoToolChain *tc,
QString MaemoPackageCreationStep::packagingCommand(const Qt4BuildConfiguration *bc,
const QString &commandName)
{
QString perl;
#ifdef Q_OS_WIN
perl = tc->maddeRoot() + QLatin1String("/bin/perl.exe ");
#endif
return perl + tc->maddeRoot() % QLatin1String("/madbin/") % commandName;
return perl + MaemoGlobal::maddeRoot(bc->qtVersion())
% QLatin1String("/madbin/") % commandName;
}
void MaemoPackageCreationStep::checkProjectName()
......@@ -571,7 +554,9 @@ void MaemoPackageCreationStep::updateDesktopFiles(const QString &rulesFilePath)
QString desktopFileDir = QFileInfo(rulesFile).dir().path()
+ QLatin1Char('/') + projectName()
+ QLatin1String("/usr/share/applications/");
if (maemoToolChain()->version() == MaemoToolChain::Maemo5)
const MaemoGlobal::MaemoVersion version
= MaemoGlobal::version(qt4BuildConfiguration()->qtVersion());
if (version == MaemoGlobal::Maemo5)
desktopFileDir += QLatin1String("hildon/");
#ifdef Q_OS_WIN
desktopFileDir.remove(QLatin1Char(':'));
......@@ -583,7 +568,7 @@ void MaemoPackageCreationStep::updateDesktopFiles(const QString &rulesFilePath)
= deployStep()->deployables()->modelAt(i);
if (!model->hasDesktopFile())
continue;
if (maemoToolChain()->version() == MaemoToolChain::Maemo6) {
if (version == MaemoGlobal::Maemo6) {
addWorkaroundForHarmattanBug(content, insertPos,
model, desktopFileDir);
}
......
......@@ -56,8 +56,6 @@ class Qt4BuildConfiguration;
namespace Internal {
class MaemoDeployStep;
class MaemoDeployableListModel;
class MaemoToolChain;
class MaemoProFileWrapper;
class MaemoPackageCreationStep : public ProjectExplorer::BuildStep
{
......@@ -74,18 +72,17 @@ public:
QString versionString(QString *error) const;
bool setVersionString(const QString &version, QString *error);
const MaemoToolChain *maemoToolChain() const;
static bool preparePackagingProcess(QProcess *proc,
const Qt4BuildConfiguration *bc, const QString &workingDir,
QString *error);
static QString packagingCommand(const MaemoToolChain *tc,
static QString packagingCommand(const Qt4BuildConfiguration *bc,
const QString &commandName);
static QString packageName(const ProjectExplorer::Project *project);
static QString packageFileName(const ProjectExplorer::Project *project,
const QString &version);
QString projectName() const;
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
static const QLatin1String DefaultVersionNumber;
......@@ -111,8 +108,6 @@ private:
bool createPackage(QProcess *buildProc);
bool copyDebianFiles(bool inSourceBuild);
QString maddeRoot() const;
QString targetRoot() const;
static QString nativePath(const QFile &file);
bool packagingNeeded() const;
bool isFileNewerThan(const QString &filePath,
......@@ -120,7 +115,6 @@ private:
void raiseError(const QString &shortMsg,
const QString &detailedMsg = QString());
QString buildDirectory() const;
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
MaemoDeployStep * deployStep() const;
void checkProjectName();
void updateDesktopFiles(const QString &rulesFilePath);
......
......@@ -42,9 +42,9 @@
#include "maemopackagecreationwidget.h"
#include "ui_maemopackagecreationwidget.h"
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemotemplatesmanager.h"
#include "maemotoolchain.h"
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/project.h>
......@@ -209,10 +209,11 @@ void MaemoPackageCreationWidget::setShortDescription()
void MaemoPackageCreationWidget::handleToolchainChanged()
{
if (!m_step->maemoToolChain())
const Qt4BuildConfiguration * const bc = m_step->qt4BuildConfiguration();
if (!bc)
return;
m_ui->skipCheckBox
->setVisible(m_step->maemoToolChain()->allowsPackagingDisabling());
m_ui->skipCheckBox->setVisible(MaemoGlobal::allowsPackagingDisabling(
bc->qtVersion()));
m_ui->skipCheckBox->setChecked(!m_step->isPackagingEnabled());
emit updateSummary();
}
......
......@@ -38,7 +38,6 @@
#include "maemopackagecreationstep.h"
#include "maemopublishingfileselectiondialog.h"
#include "maemotemplatesmanager.h"
#include "maemotoolchain.h"
#include <coreplugin/ifile.h>
#include <projectexplorer/project.h>
......@@ -364,13 +363,11 @@ void MaemoPublisherFremantleFree::runDpkgBuildPackage()
return;
setState(BuildingPackage);
emit progressReport(tr("Building source package..."));
const MaemoToolChain * const tc
= dynamic_cast<MaemoToolChain *>(m_buildConfig->toolChain());
const QStringList args = QStringList() << QLatin1String("-t")
<< tc->targetName() << QLatin1String("dpkg-buildpackage")
<< QLatin1String("-S") << QLatin1String("-us") << QLatin1String("-uc");
const QString madCommand = tc->maddeRoot() + QLatin1String("/bin/mad");
MaemoGlobal::callMaddeShellScript(*m_process, tc->maddeRoot(), madCommand, args);
<< MaemoGlobal::targetName(m_buildConfig->qtVersion())
<< QLatin1String("dpkg-buildpackage") << QLatin1String("-S")
<< QLatin1String("-us") << QLatin1String("-uc");
MaemoGlobal::callMad(*m_process, args, m_buildConfig->qtVersion());
}
// We have to implement the SCP protocol, because the maemo.org
......
......@@ -33,8 +33,8 @@
#include "maemopublishingbuildsettingspagefremantlefree.h"
#include "ui_maemopublishingbuildsettingspagefremantlefree.h"
#include "maemoglobal.h"
#include "maemopublisherfremantlefree.h"
#include "maemotoolchain.h"
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
......@@ -80,11 +80,7 @@ void MaemoPublishingBuildSettingsPageFremantleFree::collectBuildConfigurations(c