forked from qt-creator/qt-creator
Maemo: Use dpkg-buildpackage instead of calling dh-scripts manually.
Note to the merge person: This commit might trigger a merge conflict. In that case, just use the code from the master branch.
This commit is contained in:
@@ -90,6 +90,8 @@ MaemoPackageCreationStep::MaemoPackageCreationStep(BuildConfiguration *buildConf
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaemoPackageCreationStep::~MaemoPackageCreationStep() {}
|
||||||
|
|
||||||
bool MaemoPackageCreationStep::init()
|
bool MaemoPackageCreationStep::init()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -142,9 +144,9 @@ bool MaemoPackageCreationStep::createPackage()
|
|||||||
QString colon = QLatin1String(":");
|
QString colon = QLatin1String(":");
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
colon = QLatin1String(";");
|
colon = QLatin1String(";");
|
||||||
env.insert(key, targetRoot() % "/bin" % colon % env.value(key));
|
|
||||||
env.insert(key, path % QLatin1String("bin") % colon % env.value(key));
|
env.insert(key, path % QLatin1String("bin") % colon % env.value(key));
|
||||||
#endif
|
#endif
|
||||||
|
env.insert(key, targetRoot() % "/bin" % colon % env.value(key));
|
||||||
env.insert(key, path % QLatin1String("madbin") % colon % env.value(key));
|
env.insert(key, path % QLatin1String("madbin") % colon % env.value(key));
|
||||||
env.insert(QLatin1String("PERL5LIB"), path % QLatin1String("madlib/perl5"));
|
env.insert(QLatin1String("PERL5LIB"), path % QLatin1String("madlib/perl5"));
|
||||||
|
|
||||||
@@ -159,14 +161,21 @@ bool MaemoPackageCreationStep::createPackage()
|
|||||||
env.insert(envPattern.cap(1), envPattern.cap(2));
|
env.insert(envPattern.cap(1), envPattern.cap(2));
|
||||||
} while (!line.isEmpty());
|
} while (!line.isEmpty());
|
||||||
|
|
||||||
QProcess buildProc;
|
|
||||||
buildProc.setProcessEnvironment(env);
|
m_buildProc.reset(new QProcess);
|
||||||
buildProc.setWorkingDirectory(buildDir);
|
connect(m_buildProc.data(), SIGNAL(readyReadStandardOutput()), this,
|
||||||
|
SLOT(handleBuildOutput()));
|
||||||
|
connect(m_buildProc.data(), SIGNAL(readyReadStandardError()), this,
|
||||||
|
SLOT(handleBuildOutput()));
|
||||||
|
m_buildProc->setProcessEnvironment(env);
|
||||||
|
m_buildProc->setWorkingDirectory(buildDir);
|
||||||
|
m_buildProc->start("cd " + buildDir);
|
||||||
|
m_buildProc->waitForFinished();
|
||||||
|
|
||||||
if (!QFileInfo(buildDir + QLatin1String("/debian")).exists()) {
|
if (!QFileInfo(buildDir + QLatin1String("/debian")).exists()) {
|
||||||
const QString command = QLatin1String("dh_make -s -n -p ")
|
const QString command = QLatin1String("dh_make -s -n -p ")
|
||||||
% executableFileName().toLower() % QLatin1Char('_') % versionString();
|
% executableFileName().toLower() % QLatin1Char('_') % versionString();
|
||||||
if (!runCommand(buildProc, command))
|
if (!runCommand(command))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QFile rulesFile(buildDir + QLatin1String("/debian/rules"));
|
QFile rulesFile(buildDir + QLatin1String("/debian/rules"));
|
||||||
@@ -178,6 +187,11 @@ bool MaemoPackageCreationStep::createPackage()
|
|||||||
|
|
||||||
QByteArray rulesContents = rulesFile.readAll();
|
QByteArray rulesContents = rulesFile.readAll();
|
||||||
rulesContents.replace("DESTDIR", "INSTALL_ROOT");
|
rulesContents.replace("DESTDIR", "INSTALL_ROOT");
|
||||||
|
|
||||||
|
// Would be the right solution, but does not work (on Windows),
|
||||||
|
// because dpkg-genchanges doesn't know about it (and can't be told).
|
||||||
|
// rulesContents.replace("dh_builddeb", "dh_builddeb --destdir=.");
|
||||||
|
|
||||||
rulesFile.resize(0);
|
rulesFile.resize(0);
|
||||||
rulesFile.write(rulesContents);
|
rulesFile.write(rulesContents);
|
||||||
if (rulesFile.error() != QFile::NoError) {
|
if (rulesFile.error() != QFile::NoError) {
|
||||||
@@ -198,43 +212,30 @@ bool MaemoPackageCreationStep::createPackage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!runCommand(buildProc, QLatin1String("dh_installdirs")))
|
if (!runCommand(QLatin1String("dpkg-buildpackage -nc -uc -us")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QDir debianRoot = QDir(buildDir % QLatin1String("/debian/")
|
// Workaround for non-working dh_builddeb --destdir=.
|
||||||
% executableFileName().toLower());
|
if (!QDir(buildDir).isRoot()) {
|
||||||
for (int i = 0; i < m_packageContents->rowCount(); ++i) {
|
const QString packageFileName = QFileInfo(packageFilePath()).fileName();
|
||||||
const MaemoDeployable &d = m_packageContents->deployableAt(i);
|
const QString changesFileName = QFileInfo(packageFileName)
|
||||||
const QString targetFile = debianRoot.path() + '/' + d.remoteFilePath;
|
.completeBaseName() + QLatin1String(".changes");
|
||||||
const QString absTargetDir = QFileInfo(targetFile).dir().path();
|
const QString packageSourceDir = buildDir + QLatin1String("/../");
|
||||||
const QString relTargetDir = debianRoot.relativeFilePath(absTargetDir);
|
const QString packageSourceFilePath
|
||||||
if (!debianRoot.exists(relTargetDir)
|
= packageSourceDir + packageFileName;
|
||||||
&& !debianRoot.mkpath(relTargetDir)) {
|
const QString changesSourceFilePath
|
||||||
raiseError(tr("Packaging Error: Could not create directory '%1'.")
|
= packageSourceDir + changesFileName;
|
||||||
.arg(QDir::toNativeSeparators(absTargetDir)));
|
const QString changesTargetFilePath
|
||||||
|
= buildDir + QLatin1Char('/') + changesFileName;
|
||||||
|
QFile::remove(packageFilePath());
|
||||||
|
QFile::remove(changesTargetFilePath);
|
||||||
|
if (!QFile::rename(packageSourceFilePath, packageFilePath())
|
||||||
|
|| !QFile::rename(changesSourceFilePath, changesTargetFilePath)) {
|
||||||
|
raiseError(tr("Packaging failed."),
|
||||||
|
tr("Could not move package files from %1 to %2.")
|
||||||
|
.arg(packageSourceDir, buildDir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (QFile::exists(targetFile) && !QFile::remove(targetFile)) {
|
|
||||||
raiseError(tr("Packaging Error: Could not replace file '%1'.")
|
|
||||||
.arg(QDir::toNativeSeparators(targetFile)));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!QFile::copy(d.localFilePath, targetFile)) {
|
|
||||||
raiseError(tr("Packaging Error: Could not copy '%1' to '%2'.")
|
|
||||||
.arg(QDir::toNativeSeparators(d.localFilePath))
|
|
||||||
.arg(QDir::toNativeSeparators(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit addOutput(tr("Package created."), textCharFormat);
|
emit addOutput(tr("Package created."), textCharFormat);
|
||||||
@@ -242,7 +243,7 @@ bool MaemoPackageCreationStep::createPackage()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaemoPackageCreationStep::runCommand(QProcess &proc, const QString &command)
|
bool MaemoPackageCreationStep::runCommand(const QString &command)
|
||||||
{
|
{
|
||||||
QTextCharFormat textCharFormat;
|
QTextCharFormat textCharFormat;
|
||||||
emit addOutput(tr("Package Creation: Running command '%1'.").arg(command), textCharFormat);
|
emit addOutput(tr("Package Creation: Running command '%1'.").arg(command), textCharFormat);
|
||||||
@@ -250,28 +251,41 @@ bool MaemoPackageCreationStep::runCommand(QProcess &proc, const QString &command
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
perl = maddeRoot() + QLatin1String("/bin/perl.exe ");
|
perl = maddeRoot() + QLatin1String("/bin/perl.exe ");
|
||||||
#endif
|
#endif
|
||||||
proc.start(perl + maddeRoot() % QLatin1String("/madbin/") % command);
|
m_buildProc->start(perl + maddeRoot() % QLatin1String("/madbin/") % command);
|
||||||
if (!proc.waitForStarted()) {
|
if (!m_buildProc->waitForStarted()) {
|
||||||
raiseError(tr("Packaging failed."),
|
raiseError(tr("Packaging failed."),
|
||||||
tr("Packaging error: Could not start command '%1'. Reason: %2")
|
tr("Packaging error: Could not start command '%1'. Reason: %2")
|
||||||
.arg(command).arg(proc.errorString()));
|
.arg(command).arg(m_buildProc->errorString()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
proc.write("\n"); // For dh_make
|
m_buildProc->write("\n"); // For dh_make
|
||||||
proc.waitForFinished(-1);
|
m_buildProc->waitForFinished(-1);
|
||||||
if (proc.error() != QProcess::UnknownError || proc.exitCode() != 0) {
|
if (m_buildProc->error() != QProcess::UnknownError || m_buildProc->exitCode() != 0) {
|
||||||
QString mainMessage = tr("Packaging Error: Command '%1' failed.")
|
QString mainMessage = tr("Packaging Error: Command '%1' failed.")
|
||||||
.arg(command);
|
.arg(command);
|
||||||
if (proc.error() != QProcess::UnknownError)
|
if (m_buildProc->error() != QProcess::UnknownError)
|
||||||
mainMessage += tr(" Reason: %1").arg(proc.errorString());
|
mainMessage += tr(" Reason: %1").arg(m_buildProc->errorString());
|
||||||
raiseError(mainMessage, mainMessage + QLatin1Char('\n')
|
else
|
||||||
+ tr("Output was: ") + proc.readAllStandardError()
|
mainMessage += tr("Exit code: %1").arg(m_buildProc->exitCode());
|
||||||
+ QLatin1Char('\n') + proc.readAllStandardOutput());
|
raiseError(mainMessage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaemoPackageCreationStep::handleBuildOutput()
|
||||||
|
{
|
||||||
|
const QByteArray &stdOut = m_buildProc->readAllStandardOutput();
|
||||||
|
QTextCharFormat textCharFormat;
|
||||||
|
if (!stdOut.isEmpty())
|
||||||
|
emit addOutput(QString::fromLocal8Bit(stdOut), textCharFormat);
|
||||||
|
const QByteArray &errorOut = m_buildProc->readAllStandardError();
|
||||||
|
if (!errorOut.isEmpty()) {
|
||||||
|
textCharFormat.setForeground(QBrush(QColor("red")));
|
||||||
|
emit addOutput(QString::fromLocal8Bit(errorOut), textCharFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Qt4BuildConfiguration *MaemoPackageCreationStep::qt4BuildConfiguration() const
|
const Qt4BuildConfiguration *MaemoPackageCreationStep::qt4BuildConfiguration() const
|
||||||
{
|
{
|
||||||
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
|
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
|
||||||
|
@@ -44,6 +44,8 @@
|
|||||||
|
|
||||||
#include <projectexplorer/buildstep.h>
|
#include <projectexplorer/buildstep.h>
|
||||||
|
|
||||||
|
#include <QtCore/QScopedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFile;
|
class QFile;
|
||||||
class QProcess;
|
class QProcess;
|
||||||
@@ -62,6 +64,7 @@ class MaemoPackageCreationStep : public ProjectExplorer::BuildStep
|
|||||||
friend class MaemoPackageCreationFactory;
|
friend class MaemoPackageCreationFactory;
|
||||||
public:
|
public:
|
||||||
MaemoPackageCreationStep(ProjectExplorer::BuildConfiguration *buildConfig);
|
MaemoPackageCreationStep(ProjectExplorer::BuildConfiguration *buildConfig);
|
||||||
|
~MaemoPackageCreationStep();
|
||||||
|
|
||||||
QString packageFilePath() const;
|
QString packageFilePath() const;
|
||||||
QString localExecutableFilePath() const;
|
QString localExecutableFilePath() const;
|
||||||
@@ -74,6 +77,9 @@ public:
|
|||||||
QString versionString() const;
|
QString versionString() const;
|
||||||
void setVersionString(const QString &version);
|
void setVersionString(const QString &version);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handleBuildOutput();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MaemoPackageCreationStep(ProjectExplorer::BuildConfiguration *buildConfig,
|
MaemoPackageCreationStep(ProjectExplorer::BuildConfiguration *buildConfig,
|
||||||
MaemoPackageCreationStep *other);
|
MaemoPackageCreationStep *other);
|
||||||
@@ -86,8 +92,8 @@ private:
|
|||||||
virtual bool fromMap(const QVariantMap &map);
|
virtual bool fromMap(const QVariantMap &map);
|
||||||
|
|
||||||
bool createPackage();
|
bool createPackage();
|
||||||
bool runCommand(QProcess &proc, const QString &command);
|
|
||||||
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
|
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
|
||||||
|
bool runCommand(const QString &command);
|
||||||
const MaemoToolChain *maemoToolChain() const;
|
const MaemoToolChain *maemoToolChain() const;
|
||||||
QString maddeRoot() const;
|
QString maddeRoot() const;
|
||||||
QString targetRoot() const;
|
QString targetRoot() const;
|
||||||
@@ -102,6 +108,7 @@ private:
|
|||||||
MaemoPackageContents *const m_packageContents;
|
MaemoPackageContents *const m_packageContents;
|
||||||
bool m_packagingEnabled;
|
bool m_packagingEnabled;
|
||||||
QString m_versionString;
|
QString m_versionString;
|
||||||
|
QScopedPointer<QProcess> m_buildProc;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user