Commit 22b5c747 authored by ck's avatar ck
Browse files

Maemo: First attempt at packaging. Disabled for now.

parent 531ce89f
......@@ -309,6 +309,13 @@ const QString MaemoRunConfiguration::sysRoot() const
return QString();
}
const QString MaemoRunConfiguration::targetRoot() const
{
if (const MaemoToolChain *tc = toolchain())
return tc->targetRoot();
return QString();
}
const QStringList MaemoRunConfiguration::arguments() const
{
return m_arguments;
......
......@@ -78,6 +78,7 @@ public:
QString maddeRoot() const;
QString executable() const;
const QString sysRoot() const;
const QString targetRoot() const;
const QStringList arguments() const;
void setArguments(const QStringList &args);
void setDeviceConfig(const MaemoDeviceConfig &deviceConfig);
......
......@@ -46,6 +46,7 @@
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QFuture>
#include <QtCore/QProcess>
#include <QtCore/QStringBuilder>
namespace Qt4ProjectManager {
......@@ -71,6 +72,13 @@ void AbstractMaemoRunControl::startDeployment(bool forDebugging)
deployables.append(Deployable(executableFileName(),
QFileInfo(executableOnHost()).canonicalPath(),
&MaemoRunConfiguration::wasDeployed));
if (false) {
if (!buildPackage()) {
qDebug("Error: Could not build package");
handleDeploymentFinished(false);
return;
}
}
}
if (forDebugging
&& runConfig->debuggingHelpersNeedDeployment(devConfig.host)) {
......@@ -85,6 +93,107 @@ void AbstractMaemoRunControl::startDeployment(bool forDebugging)
}
}
bool AbstractMaemoRunControl::buildPackage()
{
qDebug("%s", Q_FUNC_INFO);
const QString projectDir = QFileInfo(executableOnHost()).absolutePath();
QFile configFile(runConfig->targetRoot() % QLatin1String("/config.sh"));
if (!configFile.open(QIODevice::ReadOnly)) {
qDebug("Cannot open config file '%s'", qPrintable(configFile.fileName()));
return false;
}
const QString &maddeRoot = runConfig->maddeRoot();
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QLatin1String pathKey("PATH");
env.insert(pathKey, maddeRoot % QLatin1String("/madbin:")
% env.value(pathKey));
env.insert(QLatin1String("PERL5LIB"),
maddeRoot % QLatin1String("/madlib/perl5"));
const QRegExp envPattern(QLatin1String("([^=]+)=[\"']?([^;\"']+)[\"']? ;.*"));
env.insert(QLatin1String("PWD"), projectDir);
QByteArray line;
do {
line = configFile.readLine(200);
if (envPattern.exactMatch(line))
env.insert(envPattern.cap(1), envPattern.cap(2));
} while (!line.isEmpty());
qDebug("Process environment: %s",
qPrintable(env.toStringList().join(QLatin1String(":"))));
qDebug("sysroot: '%s'", qPrintable(env.value(QLatin1String("SYSROOT_DIR"))));
QProcess buildProc;
buildProc.setProcessEnvironment(env);
buildProc.setWorkingDirectory(projectDir);
if (!QFileInfo(projectDir + QLatin1String("/debian")).exists()) {
if (!runCommand(buildProc, QLatin1String("dh_make -s -n")))
return false;
QFile rulesFile(projectDir + QLatin1String("/debian/rules"));
if (!rulesFile.open(QIODevice::ReadWrite)) {
qDebug("Error: Could not open debian/rules.");
return false;
}
QByteArray rulesContents = rulesFile.readAll();
rulesContents.replace("DESTDIR", "INSTALL_ROOT");
rulesFile.resize(0);
rulesFile.write(rulesContents);
if (rulesFile.error() != QFile::NoError) {
qDebug("Error: could not access debian/rules");
return false;
}
}
if (!runCommand(buildProc, QLatin1String("dh_installdirs")))
return false;
const QString targetFile(projectDir % QLatin1String("/debian/")
% executableFileName().toLower() % QLatin1String("/usr/bin/")
% executableFileName());
if (QFile::exists(targetFile)) {
if (!QFile::remove(targetFile)) {
qDebug("Error: Could not remove '%s'", qPrintable(targetFile));
return false;
}
}
if (!QFile::copy(executableOnHost(), targetFile)) {
qDebug("Error: Could not copy '%s' to '%s'",
qPrintable(executableOnHost()), qPrintable(targetFile));
return false;
}
const QStringList commands = QStringList() << QLatin1String("dh_link")
<< QLatin1String("dh_fixperms") << QLatin1String("dh_installdeb")
<< QLatin1String("dh_shlibdeps") << QLatin1String("dh_gencontrol")
<< QLatin1String("dh_md5sums") << QLatin1String("dh_builddeb --destdir=.");
foreach (const QString &command, commands) {
if (!runCommand(buildProc, command))
return false;
}
return true;
}
bool AbstractMaemoRunControl::runCommand(QProcess &proc,
const QString &command)
{
qDebug("Running command '%s'", qPrintable(command));
proc.start(runConfig->maddeRoot() % QLatin1String("/madbin/") % command);
proc.write("\n"); // For dh_make
if (!proc.waitForFinished(5000) && proc.error() == QProcess::Timedout) {
qDebug("command '%s' hangs", qPrintable(command));
return false;
}
if (proc.exitCode() != 0) {
qDebug("command '%s' failed with return value %d and output '%s'",
qPrintable(command), proc.exitCode(),
(proc.readAllStandardOutput() + "\n" + proc.readAllStandardError()).data());
return false;
}
qDebug("Command finished, output was '%s'",
(proc.readAllStandardOutput() + "\n" + proc.readAllStandardError()).data());
return true;
}
void AbstractMaemoRunControl::deploy()
{
if (!deployables.isEmpty()) {
......
......@@ -44,6 +44,10 @@
#include <QtCore/QScopedPointer>
#include <QtCore/QString>
QT_BEGIN_NAMESPACE
class QProcess;
QT_END_NAMESPACE
namespace Debugger {
class DebuggerManager;
class DebuggerStartParameters;
......@@ -85,6 +89,9 @@ protected:
private:
virtual void handleDeploymentFinished(bool success)=0;
bool buildPackage();
bool runCommand(QProcess &proc, const QString &command);
QFutureInterface<void> m_progress;
QScopedPointer<MaemoSshDeployer> sshDeployer;
......
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