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-06 12:04:53 +02:00
|
|
|
#include "maemodeployables.h"
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemoglobal.h"
|
|
|
|
|
#include "maemopackagecreationwidget.h"
|
2011-03-09 12:07:35 +01:00
|
|
|
#include "qt4maemodeployconfiguration.h"
|
2011-01-17 19:43:59 +01:00
|
|
|
#include "qt4maemotarget.h"
|
2010-04-09 18:24:43 +02:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
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>
|
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-07 17:10:00 +02:00
|
|
|
#include <QtCore/QStringBuilder>
|
2010-04-06 16:56:47 +02:00
|
|
|
#include <QtGui/QWidget>
|
|
|
|
|
|
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-05-25 11:23:25 +02:00
|
|
|
namespace RemoteLinux {
|
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,
|
|
|
|
|
const QString &id)
|
|
|
|
|
: ProjectExplorer::BuildStep(bsl, id)
|
2010-04-06 16:56:47 +02:00
|
|
|
{
|
2010-07-28 16:03:11 +02:00
|
|
|
ctor();
|
2010-04-06 16:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
AbstractMaemoPackageCreationStep::AbstractMaemoPackageCreationStep(BuildStepList *bsl,
|
|
|
|
|
AbstractMaemoPackageCreationStep *other) : BuildStep(bsl, other)
|
2010-04-06 16:56:47 +02:00
|
|
|
{
|
2010-07-28 16:03:11 +02:00
|
|
|
ctor();
|
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::ctor()
|
2010-07-28 16:03:11 +02:00
|
|
|
{
|
2010-08-23 17:49:07 +02:00
|
|
|
m_lastBuildConfig = qt4BuildConfiguration();
|
|
|
|
|
connect(target(),
|
|
|
|
|
SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(handleBuildConfigChanged()));
|
|
|
|
|
handleBuildConfigChanged();
|
2010-07-28 16:03:11 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
bool AbstractMaemoPackageCreationStep::init()
|
2010-04-06 16:56:47 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
void AbstractMaemoPackageCreationStep::run(QFutureInterface<bool> &fi)
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
2010-08-27 12:39:15 +02:00
|
|
|
if (!packagingNeeded()) {
|
|
|
|
|
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-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();
|
|
|
|
|
if (success) {
|
|
|
|
|
emit addOutput(tr("Package created."), BuildStep::MessageOutput);
|
|
|
|
|
deployConfig()->deployables()->setUnmodified();
|
2011-01-31 17:46:19 +01:00
|
|
|
}
|
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
|
|
|
void AbstractMaemoPackageCreationStep::handleBuildConfigChanged()
|
2010-08-23 17:49:07 +02:00
|
|
|
{
|
|
|
|
|
if (m_lastBuildConfig)
|
|
|
|
|
disconnect(m_lastBuildConfig, 0, this, 0);
|
|
|
|
|
m_lastBuildConfig = qt4BuildConfiguration();
|
|
|
|
|
connect(m_lastBuildConfig, SIGNAL(qtVersionChanged()), this,
|
|
|
|
|
SIGNAL(qtVersionChanged()));
|
|
|
|
|
connect(m_lastBuildConfig, SIGNAL(buildDirectoryChanged()), this,
|
|
|
|
|
SIGNAL(packageFilePathChanged()));
|
|
|
|
|
emit qtVersionChanged();
|
|
|
|
|
emit packageFilePathChanged();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
Qt4MaemoDeployConfiguration *AbstractMaemoPackageCreationStep::deployConfig() const
|
2010-06-29 13:39:30 +02:00
|
|
|
{
|
2011-03-09 12:07:35 +01:00
|
|
|
return qobject_cast<Qt4MaemoDeployConfiguration *>(parent()->parent());
|
2010-06-29 13:39:30 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
QString AbstractMaemoPackageCreationStep::buildDirectory() const
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
2011-03-09 12:07:35 +01:00
|
|
|
return qt4BuildConfiguration()->buildDirectory();
|
2010-04-07 17:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
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-03-09 12:07:35 +01:00
|
|
|
bool AbstractMaemoPackageCreationStep::packagingNeeded() const
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
2010-10-27 10:50:52 +02:00
|
|
|
const QSharedPointer<MaemoDeployables> &deployables
|
2011-03-09 12:07:35 +01:00
|
|
|
= deployConfig()->deployables();
|
2010-04-15 12:47:02 +02:00
|
|
|
QFileInfo packageInfo(packageFilePath());
|
2010-07-14 12:21:35 +02:00
|
|
|
if (!packageInfo.exists() || deployables->isModified())
|
2010-04-20 17:02:31 +02:00
|
|
|
return true;
|
|
|
|
|
|
2010-07-14 12:21:35 +02:00
|
|
|
const int deployableCount = deployables->deployableCount();
|
2010-07-06 12:04:53 +02:00
|
|
|
for (int i = 0; i < deployableCount; ++i) {
|
2011-03-09 12:07:35 +01:00
|
|
|
if (MaemoGlobal::isFileNewerThan(deployables->deployableAt(i).localFilePath,
|
2010-10-28 10:45:01 +02:00
|
|
|
packageInfo.lastModified()))
|
2010-04-20 17:02:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
return isMetaDataNewerThan(packageInfo.lastModified());
|
2010-10-28 10:45:01 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
QString AbstractMaemoPackageCreationStep::packageFilePath() 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());
|
|
|
|
|
return buildDirectory() + QLatin1Char('/') + 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-03-09 12:07:35 +01:00
|
|
|
bool AbstractMaemoPackageCreationStep::setVersionString(const QString &version,
|
2010-08-03 16:27:34 +02:00
|
|
|
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
|
|
|
void AbstractMaemoPackageCreationStep::raiseError(const QString &shortMsg,
|
2010-04-15 14:46:15 +02:00
|
|
|
const QString &detailedMsg)
|
|
|
|
|
{
|
2010-07-15 10:29:38 +02:00
|
|
|
emit addOutput(detailedMsg.isNull() ? shortMsg : detailedMsg, BuildStep::ErrorOutput);
|
2010-04-15 14:46:15 +02:00
|
|
|
emit addTask(Task(Task::Error, shortMsg, QString(), -1,
|
|
|
|
|
TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
bool AbstractMaemoPackageCreationStep::callPackagingCommand(QProcess *proc,
|
|
|
|
|
const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
preparePackagingProcess(proc, qt4BuildConfiguration(), buildDirectory());
|
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-06-14 17:17:24 +02:00
|
|
|
raiseError(tr("Packaging failed."), tr("Packaging error: 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()) {
|
|
|
|
|
raiseError(tr("Packaging failed."),
|
|
|
|
|
tr("Packaging error: Could not start command '%1'. Reason: %2")
|
|
|
|
|
.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-03-09 12:07:35 +01:00
|
|
|
QString AbstractMaemoPackageCreationStep::replaceDots(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QString adaptedName = name;
|
|
|
|
|
return adaptedName.replace(QLatin1Char('.'), QLatin1Char('_'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
const QString projectDir
|
|
|
|
|
= buildConfiguration()->target()->project()->projectDirectory();
|
|
|
|
|
const bool inSourceBuild
|
|
|
|
|
= QFileInfo(buildDirectory()) == QFileInfo(projectDir);
|
|
|
|
|
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=.
|
|
|
|
|
if (!QDir(buildDirectory()).isRoot()) {
|
|
|
|
|
const AbstractQt4MaemoTarget * const target = maemoTarget();
|
|
|
|
|
QString error;
|
|
|
|
|
const QString pkgFileName = target->packageFileName();
|
|
|
|
|
if (!error.isEmpty())
|
|
|
|
|
raiseError(tr("Packaging failed."), "Failed to get package name.");
|
|
|
|
|
const QString changesSourceFileName = QFileInfo(pkgFileName).completeBaseName()
|
|
|
|
|
+ QLatin1String(".changes");
|
|
|
|
|
const QString changesTargetFileName = replaceDots(QFileInfo(pkgFileName).completeBaseName())
|
|
|
|
|
+ QLatin1String(".changes");
|
|
|
|
|
const QString packageSourceDir = buildDirectory() + QLatin1String("/../");
|
|
|
|
|
const QString packageSourceFilePath
|
|
|
|
|
= packageSourceDir + pkgFileName;
|
|
|
|
|
const QString changesSourceFilePath
|
|
|
|
|
= packageSourceDir + changesSourceFileName;
|
|
|
|
|
const QString changesTargetFilePath
|
|
|
|
|
= buildDirectory() + QLatin1Char('/') + changesTargetFileName;
|
|
|
|
|
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, buildDirectory()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inSourceBuild) {
|
|
|
|
|
buildProc->start(packagingCommand(qt4BuildConfiguration(),
|
|
|
|
|
QLatin1String("dh_clean")));
|
|
|
|
|
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) {
|
|
|
|
|
const QString absFilePath
|
|
|
|
|
= debianPath + QLatin1Char('/') + debianFile;
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
const QString debianDirPath = buildDirectory() + QLatin1String("/debian");
|
|
|
|
|
const QString magicFilePath
|
|
|
|
|
= debianDirPath + QLatin1Char('/') + MagicFileName;
|
|
|
|
|
if (inSourceBuild && QFileInfo(debianDirPath).isDir()
|
|
|
|
|
&& !QFileInfo(magicFilePath).exists()) {
|
|
|
|
|
raiseError(tr("Packaging failed: Foreign debian directory detected."),
|
|
|
|
|
tr("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)));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString error;
|
|
|
|
|
if (!MaemoGlobal::removeRecursively(debianDirPath, error)) {
|
|
|
|
|
raiseError(tr("Packaging failed."),
|
|
|
|
|
tr("Could not remove directory '%1': %2").arg(debianDirPath, error));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QDir buildDir(buildDirectory());
|
|
|
|
|
if (!buildDir.mkdir("debian")) {
|
|
|
|
|
raiseError(tr("Could not create Debian directory '%1'.")
|
|
|
|
|
.arg(debianDirPath));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const QString templatesDirPath = debBasedMaemoTarget()->debianDirPath();
|
|
|
|
|
QDir templatesDir(templatesDirPath);
|
|
|
|
|
const QStringList &files = templatesDir.entryList(QDir::Files);
|
|
|
|
|
foreach (const QString &fileName, files) {
|
|
|
|
|
const QString srcFile
|
|
|
|
|
= templatesDirPath + QLatin1Char('/') + fileName;
|
|
|
|
|
const QString destFile
|
|
|
|
|
= debianDirPath + QLatin1Char('/') + fileName;
|
2011-03-30 15:18:52 +02:00
|
|
|
if (fileName == QLatin1String("rules")) {
|
|
|
|
|
if (!adaptRulesFile(srcFile, destFile))
|
|
|
|
|
return false;
|
|
|
|
|
} else if (!QFile::copy(srcFile, destFile)) {
|
2011-03-09 12:07:35 +01:00
|
|
|
raiseError(tr("Could not copy file '%1' to '%2'")
|
|
|
|
|
.arg(QDir::toNativeSeparators(srcFile),
|
|
|
|
|
QDir::toNativeSeparators(destFile)));
|
|
|
|
|
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-01-04 15:56:28 +01: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-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());
|
|
|
|
|
const QString packageSourceFilePath = rpmBuildDir(qt4BuildConfiguration())
|
|
|
|
|
+ QLatin1Char('/') + rpmBasedMaemoTarget()->packageFileName();
|
|
|
|
|
if (!QFile::rename(packageSourceFilePath, packageFilePath())) {
|
|
|
|
|
raiseError(tr("Packaging failed."),
|
|
|
|
|
tr("Could not move package file from %1 to %2.")
|
|
|
|
|
.arg(packageSourceFilePath, packageFilePath()));
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoRpmPackageCreationStep::rpmBuildDir(const Qt4BuildConfiguration *bc)
|
2011-01-31 17:46:19 +01:00
|
|
|
{
|
|
|
|
|
return bc->buildDirectory() + QLatin1String("/rrpmbuild");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
const QString MaemoRpmPackageCreationStep::CreatePackageId
|
|
|
|
|
= QLatin1String("MaemoRpmPackageCreationStep");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-09 17:04:07 +01:00
|
|
|
class CreateTarStepWidget : public BuildStepConfigWidget
|
2011-03-09 12:07:35 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2011-05-30 13:30:10 +02:00
|
|
|
CreateTarStepWidget(MaemoTarPackageCreationStep *step) : m_step(step)
|
2011-03-09 12:07:35 +01:00
|
|
|
{
|
|
|
|
|
connect(m_step, SIGNAL(packageFilePathChanged()),
|
|
|
|
|
SIGNAL(updateSummary()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual QString summaryText() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("<b>") + tr("Create tarball:")
|
|
|
|
|
+ QLatin1String("</b> ") + m_step->packageFilePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual QString displayName() const { return QString(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const MaemoTarPackageCreationStep * const m_step;
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
namespace {
|
|
|
|
|
const int TarBlockSize = 512;
|
|
|
|
|
struct TarFileHeader {
|
|
|
|
|
char fileName[100];
|
|
|
|
|
char fileMode[8];
|
|
|
|
|
char uid[8];
|
|
|
|
|
char gid[8];
|
|
|
|
|
char length[12];
|
|
|
|
|
char mtime[12];
|
|
|
|
|
char chksum[8];
|
|
|
|
|
char typeflag;
|
|
|
|
|
char linkname[100];
|
|
|
|
|
char magic[6];
|
|
|
|
|
char version[2];
|
|
|
|
|
char uname[32];
|
|
|
|
|
char gname[32];
|
|
|
|
|
char devmajor[8];
|
|
|
|
|
char devminor[8];
|
|
|
|
|
char fileNamePrefix[155];
|
|
|
|
|
char padding[12];
|
|
|
|
|
};
|
|
|
|
|
} // Anonymous namespace.
|
|
|
|
|
|
2011-03-09 12:07:35 +01:00
|
|
|
MaemoTarPackageCreationStep::MaemoTarPackageCreationStep(BuildStepList *bsl)
|
|
|
|
|
: AbstractMaemoPackageCreationStep(bsl, CreatePackageId)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoTarPackageCreationStep::MaemoTarPackageCreationStep(BuildStepList *buildConfig,
|
|
|
|
|
MaemoTarPackageCreationStep *other)
|
|
|
|
|
: AbstractMaemoPackageCreationStep(buildConfig, other)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoTarPackageCreationStep::ctor()
|
|
|
|
|
{
|
|
|
|
|
setDefaultDisplayName(tr("Create tar ball"));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
bool MaemoTarPackageCreationStep::createPackage(QProcess *buildProc,
|
|
|
|
|
const QFutureInterface<bool> &fi)
|
2011-03-09 12:07:35 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(buildProc);
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
// TODO: Optimization: Only package changed files (needs refactoring in upper level; worth the effort?)
|
|
|
|
|
QFile tarFile(packageFilePath());
|
|
|
|
|
if (!tarFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
|
|
|
|
raiseError(tr("Error: tar file %1 cannot be opened (%2).")
|
|
|
|
|
.arg(QDir::toNativeSeparators(packageFilePath()),
|
|
|
|
|
tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const QSharedPointer<MaemoDeployables> deployables = deployConfig()->deployables();
|
|
|
|
|
for (int i = 0; i < deployables->deployableCount(); ++i) {
|
|
|
|
|
const MaemoDeployable &d = deployables->deployableAt(i);
|
|
|
|
|
QFileInfo fileInfo(d.localFilePath);
|
|
|
|
|
if (!appendFile(tarFile, fileInfo, d.remoteDir + QLatin1Char('/')
|
|
|
|
|
+ fileInfo.fileName(), fi)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 11:39:38 +02:00
|
|
|
const QByteArray eofIndicator(2*sizeof(TarFileHeader), 0);
|
|
|
|
|
if (tarFile.write(eofIndicator) != eofIndicator.length()) {
|
|
|
|
|
raiseError(tr("Error writing tar file '%1': %2.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(tarFile.fileName()),
|
|
|
|
|
tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoTarPackageCreationStep::appendFile(QFile &tarFile,
|
|
|
|
|
const QFileInfo &fileInfo, const QString &remoteFilePath,
|
|
|
|
|
const QFutureInterface<bool> &fi)
|
|
|
|
|
{
|
|
|
|
|
if (!writeHeader(tarFile, fileInfo, remoteFilePath))
|
|
|
|
|
return false;
|
|
|
|
|
if (fileInfo.isDir()) {
|
|
|
|
|
QDir dir(fileInfo.absoluteFilePath());
|
|
|
|
|
foreach (const QString &fileName,
|
|
|
|
|
dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) {
|
|
|
|
|
const QString thisLocalFilePath
|
|
|
|
|
= dir.path() + QLatin1Char('/') + fileName;
|
|
|
|
|
const QString thisRemoteFilePath = remoteFilePath
|
|
|
|
|
+ QLatin1Char('/') + fileName;
|
|
|
|
|
if (!appendFile(tarFile, QFileInfo(thisLocalFilePath),
|
|
|
|
|
thisRemoteFilePath, fi)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const QString nativePath
|
|
|
|
|
= QDir::toNativeSeparators(fileInfo.filePath());
|
|
|
|
|
QFile file(fileInfo.filePath());
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
|
raiseError(tr("Error reading file '%1': %2.")
|
|
|
|
|
.arg(nativePath, file.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int chunkSize = 1024*1024;
|
2011-03-09 12:07:35 +01:00
|
|
|
|
2011-04-05 17:25:10 +02:00
|
|
|
// TODO: Wasteful. Work with fixed-size buffer.
|
|
|
|
|
while (!file.atEnd() && !file.error() != QFile::NoError
|
|
|
|
|
&& !tarFile.error() != QFile::NoError) {
|
|
|
|
|
const QByteArray data = file.read(chunkSize);
|
|
|
|
|
tarFile.write(data);
|
|
|
|
|
if (fi.isCanceled())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (file.error() != QFile::NoError) {
|
|
|
|
|
raiseError(tr("Error reading file '%1': %2.")
|
|
|
|
|
.arg(nativePath, file.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int blockModulo = file.size() % TarBlockSize;
|
|
|
|
|
if (blockModulo != 0) {
|
|
|
|
|
tarFile.write(QByteArray(TarBlockSize - blockModulo, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tarFile.error() != QFile::NoError) {
|
|
|
|
|
raiseError(tr("Error writing tar file '%1': %2.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(tarFile.fileName()),
|
|
|
|
|
tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoTarPackageCreationStep::writeHeader(QFile &tarFile,
|
|
|
|
|
const QFileInfo &fileInfo, const QString &remoteFilePath)
|
|
|
|
|
{
|
|
|
|
|
TarFileHeader header;
|
|
|
|
|
qMemSet(&header, '\0', sizeof header);
|
|
|
|
|
const QByteArray &filePath = remoteFilePath.toUtf8();
|
|
|
|
|
const int maxFilePathLength = sizeof header.fileNamePrefix
|
|
|
|
|
+ sizeof header.fileName;
|
|
|
|
|
if (filePath.count() > maxFilePathLength) {
|
|
|
|
|
raiseError(tr("Cannot tar file '%1': path is too long.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(filePath)));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int fileNameBytesToWrite
|
|
|
|
|
= qMin<int>(filePath.length(), sizeof header.fileName);
|
|
|
|
|
const int fileNameOffset = filePath.length() - fileNameBytesToWrite;
|
|
|
|
|
qMemCopy(&header.fileName, filePath.data() + fileNameOffset,
|
|
|
|
|
fileNameBytesToWrite);
|
|
|
|
|
if (fileNameOffset > 0)
|
|
|
|
|
qMemCopy(&header.fileNamePrefix, filePath.data(), fileNameOffset);
|
|
|
|
|
int permissions = (0400 * fileInfo.permission(QFile::ReadOwner))
|
|
|
|
|
| (0200 * fileInfo.permission(QFile::WriteOwner))
|
|
|
|
|
| (0100 * fileInfo.permission(QFile::ExeOwner))
|
|
|
|
|
| (040 * fileInfo.permission(QFile::ReadGroup))
|
|
|
|
|
| (020 * fileInfo.permission(QFile::WriteGroup))
|
|
|
|
|
| (010 * fileInfo.permission(QFile::ExeGroup))
|
|
|
|
|
| (04 * fileInfo.permission(QFile::ReadOther))
|
|
|
|
|
| (02 * fileInfo.permission(QFile::WriteOther))
|
|
|
|
|
| (01 * fileInfo.permission(QFile::ExeOther));
|
|
|
|
|
const QByteArray permissionString = QString("%1").arg(permissions,
|
|
|
|
|
sizeof header.fileMode - 1, 8, QLatin1Char('0')).toAscii();
|
|
|
|
|
qMemCopy(&header.fileMode, permissionString.data(),
|
|
|
|
|
permissionString.length());
|
|
|
|
|
const QByteArray uidString = QString("%1").arg(fileInfo.ownerId(),
|
|
|
|
|
sizeof header.uid - 1, 8, QLatin1Char('0')).toAscii();
|
|
|
|
|
qMemCopy(&header.uid, uidString.data(), uidString.length());
|
|
|
|
|
const QByteArray gidString = QString("%1").arg(fileInfo.groupId(),
|
|
|
|
|
sizeof header.gid - 1, 8, QLatin1Char('0')).toAscii();
|
|
|
|
|
qMemCopy(&header.gid, gidString.data(), gidString.length());
|
|
|
|
|
const QByteArray sizeString = QString("%1").arg(fileInfo.size(),
|
|
|
|
|
sizeof header.length - 1, 8, QLatin1Char('0')).toAscii();
|
|
|
|
|
qMemCopy(&header.length, sizeString.data(), sizeString.length());
|
|
|
|
|
const QByteArray mtimeString = QString("%1").arg(fileInfo.lastModified().toTime_t(),
|
|
|
|
|
sizeof header.mtime - 1, 8, QLatin1Char('0')).toAscii();
|
|
|
|
|
qMemCopy(&header.mtime, mtimeString.data(), mtimeString.length());
|
|
|
|
|
if (fileInfo.isDir())
|
|
|
|
|
header.typeflag = '5';
|
|
|
|
|
qMemCopy(&header.magic, "ustar", sizeof "ustar");
|
|
|
|
|
qMemCopy(&header.version, "00", 2);
|
|
|
|
|
const QByteArray &owner = fileInfo.owner().toUtf8();
|
|
|
|
|
qMemCopy(&header.uname, owner.data(),
|
|
|
|
|
qMin<int>(owner.length(), sizeof header.uname - 1));
|
|
|
|
|
const QByteArray &group = fileInfo.group().toUtf8();
|
|
|
|
|
qMemCopy(&header.gname, group.data(),
|
|
|
|
|
qMin<int>(group.length(), sizeof header.gname - 1));
|
|
|
|
|
qMemSet(&header.chksum, ' ', sizeof header.chksum);
|
|
|
|
|
quint64 checksum = 0;
|
|
|
|
|
for (size_t i = 0; i < sizeof header; ++i)
|
|
|
|
|
checksum += reinterpret_cast<char *>(&header)[i];
|
|
|
|
|
const QByteArray checksumString = QString("%1").arg(checksum,
|
|
|
|
|
sizeof header.chksum - 1, 8, QLatin1Char('0')).toAscii();
|
|
|
|
|
qMemCopy(&header.chksum, checksumString.data(), checksumString.length());
|
|
|
|
|
header.chksum[sizeof header.chksum-1] = 0;
|
|
|
|
|
if (!tarFile.write(reinterpret_cast<char *>(&header), sizeof header)) {
|
|
|
|
|
raiseError(tr("Error writing tar file '%1': %2")
|
|
|
|
|
.arg(QDir::toNativeSeparators(packageFilePath()),
|
|
|
|
|
tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-03-09 12:07:35 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoTarPackageCreationStep::isMetaDataNewerThan(const QDateTime &packageDate) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(packageDate);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoTarPackageCreationStep::packageFilePath() const
|
|
|
|
|
{
|
|
|
|
|
return buildDirectory() + QLatin1Char('/') + projectName()
|
|
|
|
|
+ QLatin1String(".tar");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildStepConfigWidget *MaemoTarPackageCreationStep::createConfigWidget()
|
|
|
|
|
{
|
|
|
|
|
return new CreateTarStepWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString MaemoTarPackageCreationStep::CreatePackageId
|
|
|
|
|
= QLatin1String("MaemoTarPackageCreationStep");
|
2010-04-06 16:56:47 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
2011-05-25 11:23:25 +02:00
|
|
|
} // namespace RemoteLinux
|
2011-03-09 12:07:35 +01:00
|
|
|
|
|
|
|
|
#include "maemopackagecreationstep.moc"
|