2011-04-13 08:42:33 +02:00
|
|
|
/**************************************************************************
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file is part of Qt Creator
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-04-13 08:42:33 +02:00
|
|
|
**
|
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-04-06 16:56:47 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-04-06 16:56:47 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
**************************************************************************/
|
2010-04-06 16:56:47 +02:00
|
|
|
|
|
|
|
|
#include "maemopackagecreationstep.h"
|
|
|
|
|
|
2010-04-09 18:24:43 +02:00
|
|
|
#include "maemoconstants.h"
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemoglobal.h"
|
|
|
|
|
#include "maemopackagecreationwidget.h"
|
2011-01-17 19:43:59 +01:00
|
|
|
#include "qt4maemotarget.h"
|
2010-04-09 18:24:43 +02:00
|
|
|
|
2010-04-15 14:46:15 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2011-05-25 11:23:25 +02:00
|
|
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
|
|
|
|
#include <qt4projectmanager/qt4project.h>
|
|
|
|
|
#include <qt4projectmanager/qt4target.h>
|
2011-08-18 16:46:44 +02:00
|
|
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
2010-11-17 11:09:40 +01:00
|
|
|
#include <utils/environment.h>
|
2011-03-30 15:18:52 +02:00
|
|
|
#include <utils/fileutils.h>
|
2010-04-07 17:10:00 +02:00
|
|
|
|
2010-10-28 10:45:01 +02:00
|
|
|
#include <QtCore/QDateTime>
|
2010-04-07 17:10:00 +02:00
|
|
|
#include <QtCore/QProcess>
|
2010-08-06 12:57:01 +02:00
|
|
|
#include <QtCore/QRegExp>
|
2010-04-06 16:56:47 +02:00
|
|
|
|
2010-06-28 11:59:36 +02:00
|
|
|
namespace {
|
2010-10-18 17:45:39 +02:00
|
|
|
const QLatin1String MagicFileName(".qtcreator");
|
2010-06-28 11:59:36 +02:00
|
|
|
}
|
2010-06-11 11:58:12 +02:00
|
|
|
|
2010-04-15 14:46:15 +02:00
|
|
|
using namespace ProjectExplorer::Constants;
|
2010-07-16 14:00:41 +02:00
|
|
|
using ProjectExplorer::BuildStepList;
|
2010-04-06 16:56:47 +02:00
|
|
|
using ProjectExplorer::BuildStepConfigWidget;
|
2010-04-15 14:46:15 +02:00
|
|
|
using ProjectExplorer::Task;
|
2011-05-25 11:23:25 +02:00
|
|
|
using namespace Qt4ProjectManager;
|
2010-04-06 16:56:47 +02:00
|
|
|
|
2011-09-20 12:16:36 +02:00
|
|
|
namespace Madde {
|
2010-04-06 16:56:47 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
const QLatin1String AbstractMaemoPackageCreationStep::DefaultVersionNumber("0.0.1");
|
2010-08-03 16:27:34 +02:00
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractMaemoPackageCreationStep::AbstractMaemoPackageCreationStep(BuildStepList *bsl,
|
2011-07-15 16:57:25 +02:00
|
|
|
const QString &id) : AbstractPackagingStep(bsl, id)
|
2010-04-06 16:56:47 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractMaemoPackageCreationStep::AbstractMaemoPackageCreationStep(BuildStepList *bsl,
|
2011-07-15 16:57:25 +02:00
|
|
|
AbstractMaemoPackageCreationStep *other) : AbstractPackagingStep(bsl, other)
|
2010-04-06 16:56:47 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractMaemoPackageCreationStep::~AbstractMaemoPackageCreationStep()
|
2010-07-06 12:04:53 +02:00
|
|
|
{
|
|
|
|
|
}
|
2010-06-29 14:10:01 +02:00
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
void AbstractMaemoPackageCreationStep::run(QFutureInterface<bool> &fi)
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
2011-07-15 16:57:25 +02:00
|
|
|
if (!isPackagingNeeded()) {
|
2010-08-27 12:39:15 +02:00
|
|
|
emit addOutput(tr("Package up to date."), MessageOutput);
|
2011-03-09 12:07:35 +01:00
|
|
|
fi.reportResult(true);
|
|
|
|
|
return;
|
2010-08-27 12:39:15 +02:00
|
|
|
}
|
2010-04-07 17:10:00 +02:00
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
setPackagingStarted();
|
2011-03-09 12:07:35 +01:00
|
|
|
// TODO: Make the build process asynchronous; i.e. no waitFor()-functions etc.
|
|
|
|
|
QProcess * const buildProc = new QProcess;
|
|
|
|
|
connect(buildProc, SIGNAL(readyReadStandardOutput()), this,
|
|
|
|
|
SLOT(handleBuildOutput()));
|
|
|
|
|
connect(buildProc, SIGNAL(readyReadStandardError()), this,
|
|
|
|
|
SLOT(handleBuildOutput()));
|
2010-08-27 12:39:15 +02:00
|
|
|
emit addOutput(tr("Creating package file ..."), MessageOutput);
|
2011-04-05 17:25:10 +02:00
|
|
|
const bool success = createPackage(buildProc, fi);
|
2011-03-09 12:07:35 +01:00
|
|
|
disconnect(buildProc, 0, this, 0);
|
|
|
|
|
buildProc->deleteLater();
|
2011-07-15 16:57:25 +02:00
|
|
|
if (success)
|
2011-03-09 12:07:35 +01:00
|
|
|
emit addOutput(tr("Package created."), BuildStep::MessageOutput);
|
2011-07-15 16:57:25 +02:00
|
|
|
setPackagingFinished(success);
|
2011-03-09 12:07:35 +01:00
|
|
|
fi.reportResult(success);
|
2010-08-27 11:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
BuildStepConfigWidget *AbstractMaemoPackageCreationStep::createConfigWidget()
|
2010-08-27 11:46:54 +02:00
|
|
|
{
|
2011-03-09 12:07:35 +01:00
|
|
|
return new MaemoPackageCreationWidget(this);
|
2010-04-07 17:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
void AbstractMaemoPackageCreationStep::handleBuildOutput()
|
2010-07-01 11:55:36 +02:00
|
|
|
{
|
2010-08-27 12:39:15 +02:00
|
|
|
QProcess * const buildProc = qobject_cast<QProcess *>(sender());
|
2010-08-30 12:55:38 +02:00
|
|
|
if (!buildProc)
|
|
|
|
|
return;
|
2011-03-29 16:10:05 +02:00
|
|
|
QByteArray stdOut = buildProc->readAllStandardOutput();
|
|
|
|
|
stdOut.replace('\0', QByteArray()); // Output contains NUL characters.
|
2010-07-01 11:55:36 +02:00
|
|
|
if (!stdOut.isEmpty())
|
2011-03-31 18:22:22 +02:00
|
|
|
emit addOutput(QString::fromLocal8Bit(stdOut), BuildStep::NormalOutput,
|
2011-04-01 10:33:20 +02:00
|
|
|
BuildStep::DontAppendNewline);
|
2011-03-29 16:10:05 +02:00
|
|
|
QByteArray errorOut = buildProc->readAllStandardError();
|
|
|
|
|
errorOut.replace('\0', QByteArray());
|
2010-07-01 11:55:36 +02:00
|
|
|
if (!errorOut.isEmpty()) {
|
2011-03-31 18:22:22 +02:00
|
|
|
emit addOutput(QString::fromLocal8Bit(errorOut), BuildStep::ErrorOutput,
|
|
|
|
|
BuildStep::DontAppendNewline);
|
2010-07-01 11:55:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
const Qt4BuildConfiguration *AbstractMaemoPackageCreationStep::qt4BuildConfiguration() const
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
|
|
|
|
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractQt4MaemoTarget *AbstractMaemoPackageCreationStep::maemoTarget() const
|
2011-01-17 19:43:59 +01:00
|
|
|
{
|
2011-01-18 15:20:57 +01:00
|
|
|
return qobject_cast<AbstractQt4MaemoTarget *>(buildConfiguration()->target());
|
2011-01-17 19:43:59 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractDebBasedQt4MaemoTarget *AbstractMaemoPackageCreationStep::debBasedMaemoTarget() const
|
2011-01-24 11:57:42 +01:00
|
|
|
{
|
|
|
|
|
return qobject_cast<AbstractDebBasedQt4MaemoTarget*>(buildConfiguration()->target());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractRpmBasedQt4MaemoTarget *AbstractMaemoPackageCreationStep::rpmBasedMaemoTarget() const
|
2011-01-31 17:46:19 +01:00
|
|
|
{
|
|
|
|
|
return qobject_cast<AbstractRpmBasedQt4MaemoTarget*>(buildConfiguration()->target());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
QString AbstractMaemoPackageCreationStep::projectName() const
|
2010-07-14 12:21:35 +02:00
|
|
|
{
|
2011-03-09 12:07:35 +01:00
|
|
|
return qt4BuildConfiguration()->qt4Target()->qt4Project()
|
|
|
|
|
->rootProjectNode()->displayName().toLower();
|
2010-07-14 12:21:35 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
bool AbstractMaemoPackageCreationStep::isPackagingNeeded() const
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
2011-07-15 16:57:25 +02:00
|
|
|
if (AbstractPackagingStep::isPackagingNeeded())
|
2010-04-20 17:02:31 +02:00
|
|
|
return true;
|
2011-07-15 16:57:25 +02:00
|
|
|
return isMetaDataNewerThan(QFileInfo(packageFilePath()).lastModified());
|
2010-10-28 10:45:01 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
QString AbstractMaemoPackageCreationStep::packageFileName() const
|
2010-04-15 12:47:02 +02:00
|
|
|
{
|
2010-08-03 16:27:34 +02:00
|
|
|
QString error;
|
|
|
|
|
const QString &version = versionString(&error);
|
|
|
|
|
if (version.isEmpty())
|
|
|
|
|
return QString();
|
2011-01-31 17:46:19 +01:00
|
|
|
QFileInfo fi(maemoTarget()->packageFileName());
|
|
|
|
|
const QString baseName = replaceDots(fi.completeBaseName());
|
2011-07-15 16:57:25 +02:00
|
|
|
return baseName + QLatin1Char('.') + fi.suffix();
|
2010-04-15 12:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
QString AbstractMaemoPackageCreationStep::versionString(QString *error) const
|
2010-04-14 14:45:04 +02:00
|
|
|
{
|
2011-01-17 19:43:59 +01:00
|
|
|
return maemoTarget()->projectVersion(error);
|
2010-06-28 11:59:36 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
bool AbstractMaemoPackageCreationStep::setVersionString(const QString &version, QString *error)
|
2010-06-28 11:59:36 +02:00
|
|
|
{
|
2011-01-17 19:43:59 +01:00
|
|
|
const bool success = maemoTarget()->setProjectVersion(version, error);
|
2010-08-03 16:27:34 +02:00
|
|
|
if (success)
|
|
|
|
|
emit packageFilePathChanged();
|
|
|
|
|
return success;
|
2010-04-14 14:45:04 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
QString AbstractMaemoPackageCreationStep::nativePath(const QFile &file)
|
2010-04-15 14:46:15 +02:00
|
|
|
{
|
|
|
|
|
return QDir::toNativeSeparators(QFileInfo(file).filePath());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
bool AbstractMaemoPackageCreationStep::callPackagingCommand(QProcess *proc,
|
|
|
|
|
const QStringList &arguments)
|
|
|
|
|
{
|
2011-07-15 16:57:25 +02:00
|
|
|
preparePackagingProcess(proc, qt4BuildConfiguration(), packageDirectory());
|
2011-05-20 21:40:53 +02:00
|
|
|
const QtSupport::BaseQtVersion * const qtVersion = qt4BuildConfiguration()->qtVersion();
|
2011-05-04 13:14:46 +02:00
|
|
|
if (!qtVersion) {
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Packaging failed: No Qt version."));
|
2011-05-04 13:14:46 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const QString madCommand = MaemoGlobal::madCommand(qtVersion->qmakeCommand());
|
2011-03-09 12:07:35 +01:00
|
|
|
const QString cmdLine = madCommand + QLatin1Char(' ')
|
|
|
|
|
+ arguments.join(QLatin1String(" "));
|
|
|
|
|
emit addOutput(tr("Package Creation: Running command '%1'.").arg(cmdLine),
|
|
|
|
|
BuildStep::MessageOutput);
|
2011-05-04 13:14:46 +02:00
|
|
|
MaemoGlobal::callMad(*proc, arguments, qtVersion->qmakeCommand(), true);
|
2011-03-09 12:07:35 +01:00
|
|
|
if (!proc->waitForStarted()) {
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Packaging failed: Could not start command '%1'. Reason: %2")
|
2011-03-09 12:07:35 +01:00
|
|
|
.arg(cmdLine, proc->errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
proc->waitForFinished(-1);
|
|
|
|
|
if (proc->error() != QProcess::UnknownError || proc->exitCode() != 0) {
|
|
|
|
|
QString mainMessage = tr("Packaging Error: Command '%1' failed.")
|
|
|
|
|
.arg(cmdLine);
|
|
|
|
|
if (proc->error() != QProcess::UnknownError)
|
|
|
|
|
mainMessage += tr(" Reason: %1").arg(proc->errorString());
|
|
|
|
|
else
|
|
|
|
|
mainMessage += tr("Exit code: %1").arg(proc->exitCode());
|
|
|
|
|
raiseError(mainMessage);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AbstractMaemoPackageCreationStep::preparePackagingProcess(QProcess *proc,
|
2011-02-09 15:10:51 +01:00
|
|
|
const Qt4BuildConfiguration *bc, const QString &workingDir)
|
2010-08-03 16:27:34 +02:00
|
|
|
{
|
2010-11-17 11:09:40 +01:00
|
|
|
Utils::Environment env = bc->environment();
|
2011-05-20 21:40:53 +02:00
|
|
|
if (bc->qmakeBuildConfiguration() & QtSupport::BaseQtVersion::DebugBuild) {
|
2010-11-17 11:09:40 +01:00
|
|
|
env.appendOrSet(QLatin1String("DEB_BUILD_OPTIONS"),
|
|
|
|
|
QLatin1String("nostrip"), QLatin1String(" "));
|
2010-11-02 16:15:56 +01:00
|
|
|
}
|
2010-11-17 11:09:40 +01:00
|
|
|
proc->setEnvironment(env.toStringList());
|
2010-08-03 16:27:34 +02:00
|
|
|
proc->setWorkingDirectory(workingDir);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 15:58:18 +02:00
|
|
|
QString AbstractMaemoPackageCreationStep::replaceDots(const QString &name) const
|
2011-03-09 12:07:35 +01:00
|
|
|
{
|
2011-08-05 15:58:18 +02:00
|
|
|
// Idiotic OVI store requirement for N900 (but not allowed for N9 ...).
|
|
|
|
|
if (qobject_cast<Qt4Maemo5Target *>(target())) {
|
|
|
|
|
QString adaptedName = name;
|
|
|
|
|
return adaptedName.replace(QLatin1Char('.'), QLatin1Char('_'));
|
|
|
|
|
}
|
|
|
|
|
return name;
|
2011-03-09 12:07:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MaemoDebianPackageCreationStep::MaemoDebianPackageCreationStep(BuildStepList *bsl)
|
|
|
|
|
: AbstractMaemoPackageCreationStep(bsl, CreatePackageId)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString MaemoDebianPackageCreationStep::CreatePackageId
|
|
|
|
|
= QLatin1String("MaemoDebianPackageCreationStep");
|
|
|
|
|
|
|
|
|
|
MaemoDebianPackageCreationStep::MaemoDebianPackageCreationStep(BuildStepList *buildConfig,
|
|
|
|
|
MaemoDebianPackageCreationStep *other)
|
|
|
|
|
: AbstractMaemoPackageCreationStep(buildConfig, other)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebianPackageCreationStep::ctor()
|
|
|
|
|
{
|
|
|
|
|
setDefaultDisplayName(tr("Create Debian Package"));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
bool MaemoDebianPackageCreationStep::createPackage(QProcess *buildProc,
|
|
|
|
|
const QFutureInterface<bool> &fi)
|
2011-03-09 12:07:35 +01:00
|
|
|
{
|
2011-04-05 17:25:10 +02:00
|
|
|
Q_UNUSED(fi);
|
2011-03-09 12:07:35 +01:00
|
|
|
checkProjectName();
|
2011-07-15 16:57:25 +02:00
|
|
|
const QString projectDir = buildConfiguration()->target()->project()->projectDirectory();
|
|
|
|
|
const bool inSourceBuild = QFileInfo(packageDirectory()) == QFileInfo(projectDir);
|
2011-03-09 12:07:35 +01:00
|
|
|
if (!copyDebianFiles(inSourceBuild))
|
|
|
|
|
return false;
|
|
|
|
|
const QStringList args = QStringList() << QLatin1String("dpkg-buildpackage")
|
|
|
|
|
<< QLatin1String("-nc") << QLatin1String("-uc") << QLatin1String("-us");
|
|
|
|
|
if (!callPackagingCommand(buildProc, args))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QFile::remove(packageFilePath());
|
|
|
|
|
|
|
|
|
|
// Workaround for non-working dh_builddeb --destdir=.
|
2011-07-15 16:57:25 +02:00
|
|
|
if (!QDir(packageDirectory()).isRoot()) {
|
2011-03-09 12:07:35 +01:00
|
|
|
const AbstractQt4MaemoTarget * const target = maemoTarget();
|
|
|
|
|
QString error;
|
|
|
|
|
const QString pkgFileName = target->packageFileName();
|
|
|
|
|
if (!error.isEmpty())
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Packaging failed: Could not get package name."));
|
2011-03-09 12:07:35 +01:00
|
|
|
const QString changesSourceFileName = QFileInfo(pkgFileName).completeBaseName()
|
|
|
|
|
+ QLatin1String(".changes");
|
|
|
|
|
const QString changesTargetFileName = replaceDots(QFileInfo(pkgFileName).completeBaseName())
|
|
|
|
|
+ QLatin1String(".changes");
|
2011-07-15 16:57:25 +02:00
|
|
|
const QString packageSourceDir = packageDirectory() + QLatin1String("/../");
|
|
|
|
|
const QString packageSourceFilePath = packageSourceDir + pkgFileName;
|
|
|
|
|
const QString changesSourceFilePath = packageSourceDir + changesSourceFileName;
|
2011-03-09 12:07:35 +01:00
|
|
|
const QString changesTargetFilePath
|
2011-07-15 16:57:25 +02:00
|
|
|
= packageDirectory() + QLatin1Char('/') + changesTargetFileName;
|
2011-03-09 12:07:35 +01:00
|
|
|
QFile::remove(changesTargetFilePath);
|
|
|
|
|
if (!QFile::rename(packageSourceFilePath, packageFilePath())
|
|
|
|
|
|| !QFile::rename(changesSourceFilePath, changesTargetFilePath)) {
|
2011-09-27 09:38:53 +02:00
|
|
|
raiseError(tr("Packaging failed: Could not move package files from '%1' to '%2'.")
|
2011-07-15 16:57:25 +02:00
|
|
|
.arg(packageSourceDir, packageDirectory()));
|
2011-03-09 12:07:35 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inSourceBuild) {
|
2011-07-15 16:57:25 +02:00
|
|
|
buildProc->start(packagingCommand(qt4BuildConfiguration(), QLatin1String("dh_clean")));
|
2011-03-09 12:07:35 +01:00
|
|
|
buildProc->waitForFinished();
|
|
|
|
|
buildProc->terminate();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoDebianPackageCreationStep::isMetaDataNewerThan(const QDateTime &packageDate) const
|
|
|
|
|
{
|
|
|
|
|
const QString debianPath = debBasedMaemoTarget()->debianDirPath();
|
|
|
|
|
if (packageDate <= QFileInfo(debianPath).lastModified())
|
|
|
|
|
return true;
|
|
|
|
|
const QStringList debianFiles = debBasedMaemoTarget()->debianFiles();
|
|
|
|
|
foreach (const QString &debianFile, debianFiles) {
|
2011-07-15 16:57:25 +02:00
|
|
|
const QString absFilePath = debianPath + QLatin1Char('/') + debianFile;
|
2011-03-09 12:07:35 +01:00
|
|
|
if (packageDate <= QFileInfo(absFilePath).lastModified())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebianPackageCreationStep::checkProjectName()
|
|
|
|
|
{
|
|
|
|
|
const QRegExp legalName(QLatin1String("[0-9-+a-z\\.]+"));
|
|
|
|
|
if (!legalName.exactMatch(buildConfiguration()->target()->project()->displayName())) {
|
|
|
|
|
emit addTask(Task(Task::Warning,
|
|
|
|
|
tr("Your project name contains characters not allowed in "
|
|
|
|
|
"Debian packages.\nThey must only use lower-case letters, "
|
|
|
|
|
"numbers, '-', '+' and '.'.\n""We will try to work around that, "
|
|
|
|
|
"but you may experience problems."),
|
|
|
|
|
QString(), -1, TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoDebianPackageCreationStep::copyDebianFiles(bool inSourceBuild)
|
|
|
|
|
{
|
2011-07-15 16:57:25 +02:00
|
|
|
const QString debianDirPath = packageDirectory() + QLatin1String("/debian");
|
2011-03-09 12:07:35 +01:00
|
|
|
const QString magicFilePath
|
|
|
|
|
= debianDirPath + QLatin1Char('/') + MagicFileName;
|
|
|
|
|
if (inSourceBuild && QFileInfo(debianDirPath).isDir()
|
|
|
|
|
&& !QFileInfo(magicFilePath).exists()) {
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Packaging failed: Foreign debian directory detected. "
|
|
|
|
|
"You are not using a shadow build and there is a debian "
|
|
|
|
|
"directory in your project root ('%1'). Qt Creator will not "
|
|
|
|
|
"overwrite that directory. Please remove it or use the "
|
|
|
|
|
"shadow build feature.").arg(QDir::toNativeSeparators(debianDirPath)));
|
2011-03-09 12:07:35 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString error;
|
2011-07-05 12:59:14 +02:00
|
|
|
if (!Utils::FileUtils::removeRecursively(debianDirPath, &error)) {
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Packaging failed: Could not remove directory '%1': %2")
|
|
|
|
|
.arg(debianDirPath, error));
|
2011-03-09 12:07:35 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-15 16:57:25 +02:00
|
|
|
QDir buildDir(packageDirectory());
|
2011-03-09 12:07:35 +01:00
|
|
|
if (!buildDir.mkdir("debian")) {
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Could not create Debian directory '%1'.").arg(debianDirPath));
|
2011-03-09 12:07:35 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const QString templatesDirPath = debBasedMaemoTarget()->debianDirPath();
|
|
|
|
|
QDir templatesDir(templatesDirPath);
|
|
|
|
|
const QStringList &files = templatesDir.entryList(QDir::Files);
|
|
|
|
|
foreach (const QString &fileName, files) {
|
2011-06-23 15:31:42 +02:00
|
|
|
const QString srcFile = templatesDirPath + QLatin1Char('/') + fileName;
|
|
|
|
|
QString newFileName = fileName;
|
|
|
|
|
if (newFileName == Qt4HarmattanTarget::aegisManifestFileName()) {
|
|
|
|
|
// If the user has touched the Aegis manifest file, we copy it for use
|
2011-10-13 17:17:53 +02:00
|
|
|
// by MADDE. Otherwise the required capabilities will be auto-detected,
|
|
|
|
|
// unless the user explicitly requests that no manifest should be created.
|
2011-06-23 15:31:42 +02:00
|
|
|
if (QFileInfo(srcFile).size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
newFileName = maemoTarget()->packageName() + QLatin1String(".aegis");
|
|
|
|
|
}
|
2011-10-13 17:17:53 +02:00
|
|
|
|
2011-06-23 15:31:42 +02:00
|
|
|
const QString destFile = debianDirPath + QLatin1Char('/') + newFileName;
|
2011-03-30 15:18:52 +02:00
|
|
|
if (fileName == QLatin1String("rules")) {
|
|
|
|
|
if (!adaptRulesFile(srcFile, destFile))
|
|
|
|
|
return false;
|
2011-10-13 17:17:53 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newFileName == maemoTarget()->packageName() + QLatin1String(".aegis")) {
|
|
|
|
|
Utils::FileReader reader;
|
|
|
|
|
if (!reader.fetch(srcFile)) {
|
|
|
|
|
raiseError(tr("Could not read manifest file '%1': %2.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(srcFile), reader.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (reader.data().startsWith("NoAegisFile")) {
|
|
|
|
|
QFile targetFile(destFile);
|
|
|
|
|
if (!targetFile.open(QIODevice::WriteOnly)) {
|
|
|
|
|
raiseError(tr("Could not write manifest file '%1': %2.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(destFile), targetFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!QFile::copy(srcFile, destFile)) {
|
|
|
|
|
raiseError(tr("Could not copy file '%1' to '%2'.")
|
2011-07-15 16:57:25 +02:00
|
|
|
.arg(QDir::toNativeSeparators(srcFile), QDir::toNativeSeparators(destFile)));
|
2011-03-09 12:07:35 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFile magicFile(magicFilePath);
|
|
|
|
|
if (!magicFile.open(QIODevice::WriteOnly)) {
|
|
|
|
|
raiseError(tr("Error: Could not create file '%1'.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(magicFilePath)));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoDebianPackageCreationStep::packagingCommand(const Qt4BuildConfiguration *bc,
|
2010-08-03 16:27:34 +02:00
|
|
|
const QString &commandName)
|
|
|
|
|
{
|
|
|
|
|
QString perl;
|
2011-05-20 21:40:53 +02:00
|
|
|
QtSupport::BaseQtVersion *v = bc->qtVersion();
|
2011-05-04 13:14:46 +02:00
|
|
|
const QString maddeRoot = MaemoGlobal::maddeRoot(v->qmakeCommand());
|
2010-08-03 16:27:34 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2011-01-04 15:56:28 +01:00
|
|
|
perl = maddeRoot + QLatin1String("/bin/perl.exe ");
|
2010-08-03 16:27:34 +02:00
|
|
|
#endif
|
2011-07-18 14:02:38 +02:00
|
|
|
return perl + maddeRoot + QLatin1String("/madbin/") + commandName;
|
2010-08-03 16:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
void MaemoDebianPackageCreationStep::ensureShlibdeps(QByteArray &rulesContent)
|
2011-01-06 15:45:50 +01:00
|
|
|
{
|
|
|
|
|
QString contentAsString = QString::fromLocal8Bit(rulesContent);
|
|
|
|
|
const QString whiteSpace(QLatin1String("[ \\t]*"));
|
|
|
|
|
const QString pattern = QLatin1String("\\n") + whiteSpace
|
|
|
|
|
+ QLatin1Char('#') + whiteSpace + QLatin1String("dh_shlibdeps")
|
2011-05-31 16:59:43 +02:00
|
|
|
+ QLatin1String("([^\\n]*)\\n");
|
2011-01-06 15:45:50 +01:00
|
|
|
contentAsString.replace(QRegExp(pattern),
|
2011-05-31 16:59:43 +02:00
|
|
|
QLatin1String("\n\tdh_shlibdeps\\1\n"));
|
2011-01-06 15:45:50 +01:00
|
|
|
rulesContent = contentAsString.toLocal8Bit();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-30 15:18:52 +02:00
|
|
|
bool MaemoDebianPackageCreationStep::adaptRulesFile(
|
|
|
|
|
const QString &templatePath, const QString &rulesFilePath)
|
2010-09-23 15:01:19 +02:00
|
|
|
{
|
2011-03-30 15:18:52 +02:00
|
|
|
Utils::FileReader reader;
|
|
|
|
|
if (!reader.fetch(templatePath)) {
|
|
|
|
|
raiseError(reader.errorString());
|
|
|
|
|
return false;
|
2010-09-23 15:01:19 +02:00
|
|
|
}
|
2011-03-30 15:18:52 +02:00
|
|
|
QByteArray content = reader.data();
|
2011-01-06 15:45:50 +01:00
|
|
|
const Qt4BuildConfiguration * const bc = qt4BuildConfiguration();
|
2011-05-04 13:14:46 +02:00
|
|
|
|
2011-01-06 15:45:50 +01:00
|
|
|
// Always check for dependencies in release builds.
|
2011-05-20 21:40:53 +02:00
|
|
|
if (!(bc->qmakeBuildConfiguration() & QtSupport::BaseQtVersion::DebugBuild))
|
2011-01-06 15:45:50 +01:00
|
|
|
ensureShlibdeps(content);
|
|
|
|
|
|
2011-03-30 15:18:52 +02:00
|
|
|
Utils::FileSaver saver(rulesFilePath);
|
|
|
|
|
saver.write(content);
|
|
|
|
|
if (!saver.finalize()) {
|
|
|
|
|
raiseError(saver.errorString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QFile rulesFile(rulesFilePath);
|
|
|
|
|
rulesFile.setPermissions(rulesFile.permissions() | QFile::ExeUser);
|
|
|
|
|
return true;
|
2010-09-23 15:01:19 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
|
|
|
|
|
MaemoRpmPackageCreationStep::MaemoRpmPackageCreationStep(BuildStepList *bsl)
|
|
|
|
|
: AbstractMaemoPackageCreationStep(bsl, CreatePackageId)
|
2011-01-20 12:37:07 +01:00
|
|
|
{
|
2011-03-09 12:07:35 +01:00
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoRpmPackageCreationStep::MaemoRpmPackageCreationStep(BuildStepList *buildConfig,
|
|
|
|
|
MaemoRpmPackageCreationStep *other)
|
|
|
|
|
: AbstractMaemoPackageCreationStep(buildConfig, other)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRpmPackageCreationStep::ctor()
|
|
|
|
|
{
|
|
|
|
|
setDefaultDisplayName(tr("Create RPM Package"));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
bool MaemoRpmPackageCreationStep::createPackage(QProcess *buildProc,
|
|
|
|
|
const QFutureInterface<bool> &fi)
|
2011-03-09 12:07:35 +01:00
|
|
|
{
|
2011-07-15 16:57:25 +02:00
|
|
|
setPackagingStarted();
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
Q_UNUSED(fi);
|
2011-03-09 12:07:35 +01:00
|
|
|
const QStringList args = QStringList() << QLatin1String("rrpmbuild")
|
|
|
|
|
<< QLatin1String("-bb") << rpmBasedMaemoTarget()->specFilePath();
|
|
|
|
|
if (!callPackagingCommand(buildProc, args))
|
|
|
|
|
return false;
|
|
|
|
|
QFile::remove(packageFilePath());
|
2011-07-15 16:57:25 +02:00
|
|
|
const QString packageSourceFilePath = rpmBuildDir() + QLatin1Char('/')
|
|
|
|
|
+ rpmBasedMaemoTarget()->packageFileName();
|
2011-03-09 12:07:35 +01:00
|
|
|
if (!QFile::rename(packageSourceFilePath, packageFilePath())) {
|
2011-07-15 16:57:25 +02:00
|
|
|
raiseError(tr("Packaging failed: Could not move package file from %1 to %2.")
|
|
|
|
|
.arg(packageSourceFilePath, packageFilePath()));
|
2011-03-09 12:07:35 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2011-01-20 12:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
bool MaemoRpmPackageCreationStep::isMetaDataNewerThan(const QDateTime &packageDate) const
|
|
|
|
|
{
|
|
|
|
|
const QDateTime specFileChangeDate
|
|
|
|
|
= QFileInfo(rpmBasedMaemoTarget()->specFilePath()).lastModified();
|
|
|
|
|
return packageDate <= specFileChangeDate;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
QString MaemoRpmPackageCreationStep::rpmBuildDir() const
|
2011-01-31 17:46:19 +01:00
|
|
|
{
|
2011-07-15 16:57:25 +02:00
|
|
|
return packageDirectory() + QLatin1String("/rrpmbuild");
|
2011-01-31 17:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
const QString MaemoRpmPackageCreationStep::CreatePackageId
|
|
|
|
|
= QLatin1String("MaemoRpmPackageCreationStep");
|
|
|
|
|
|
2010-04-06 16:56:47 +02:00
|
|
|
} // namespace Internal
|
2011-09-20 12:16:36 +02:00
|
|
|
} // namespace Madde
|