RemoteLinux: Introduce abstract packaging step.

This removes the dependency of the tar packaging step on Maemo-specific code.

Change-Id: I863b13e643a5028edaf2f571f63b1a52d229812b
Reviewed-on: http://codereview.qt.nokia.com/1709
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
Christian Kandeler
2011-07-15 16:57:25 +02:00
parent 89ac110ab0
commit 076064ce30
12 changed files with 690 additions and 435 deletions

View File

@@ -0,0 +1,159 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "abstractpackagingstep.h"
#include "deploymentinfo.h"
#include "remotelinuxdeployconfiguration.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <utils/fileutils.h>
#include <QtCore/QFileInfo>
using namespace ProjectExplorer;
namespace RemoteLinux {
namespace Internal {
class AbstractPackagingStepPrivate
{
public:
AbstractPackagingStepPrivate() : currentBuildConfiguration(0), running(false) { }
BuildConfiguration *currentBuildConfiguration;
bool running;
QString cachedPackageDirectory;
};
} // namespace Internal
AbstractPackagingStep::AbstractPackagingStep(BuildStepList *bsl, const QString &id)
: BuildStep(bsl, id)
{
ctor();
}
AbstractPackagingStep::AbstractPackagingStep(BuildStepList *bsl, AbstractPackagingStep *other)
: BuildStep(bsl, other)
{
ctor();
}
void AbstractPackagingStep::ctor()
{
m_d = new Internal::AbstractPackagingStepPrivate;
connect(target(), SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
SLOT(handleBuildConfigurationChanged()));
handleBuildConfigurationChanged();
}
AbstractPackagingStep::~AbstractPackagingStep()
{
delete m_d;
}
void AbstractPackagingStep::handleBuildConfigurationChanged()
{
if (m_d->currentBuildConfiguration)
disconnect(m_d->currentBuildConfiguration, 0, this, 0);
m_d->currentBuildConfiguration = target()->activeBuildConfiguration();
if (m_d->currentBuildConfiguration) {
connect(m_d->currentBuildConfiguration, SIGNAL(buildDirectoryChanged()), this,
SIGNAL(packageFilePathChanged()));
}
emit packageFilePathChanged();
}
QString AbstractPackagingStep::packageFilePath() const
{
if (packageDirectory().isEmpty())
return QString();
return packageDirectory() + QLatin1Char('/') + packageFileName();
}
QString AbstractPackagingStep::packageDirectory() const
{
if (m_d->running)
return m_d->cachedPackageDirectory;
return m_d->currentBuildConfiguration
? m_d->currentBuildConfiguration->buildDirectory() : QString();
}
RemoteLinuxDeployConfiguration *AbstractPackagingStep::deployConfiguration() const
{
return qobject_cast<RemoteLinuxDeployConfiguration *>(parent()->parent());
}
bool AbstractPackagingStep::isPackagingNeeded() const
{
const QSharedPointer<DeploymentInfo> &deploymentInfo = deployConfiguration()->deploymentInfo();
QFileInfo packageInfo(packageFilePath());
if (!packageInfo.exists() || deploymentInfo->isModified())
return true;
const int deployableCount = deploymentInfo->deployableCount();
for (int i = 0; i < deployableCount; ++i) {
if (Utils::FileUtils::isFileNewerThan(deploymentInfo->deployableAt(i).localFilePath,
packageInfo.lastModified()))
return true;
}
return false;
}
bool AbstractPackagingStep::init()
{
m_d->cachedPackageDirectory = packageDirectory();
return true;
}
void AbstractPackagingStep::setPackagingStarted()
{
m_d->running = true;
}
void AbstractPackagingStep::setPackagingFinished(bool success)
{
m_d->running = false;
if (success)
deployConfiguration()->deploymentInfo()->setUnmodified();
}
void AbstractPackagingStep::raiseError(const QString &errorMessage)
{
emit addOutput(errorMessage, BuildStep::ErrorOutput);
emit addTask(Task(Task::Error, errorMessage, QString(), -1,
Constants::TASK_CATEGORY_BUILDSYSTEM));
}
} // namespace RemoteLinux

View File

@@ -0,0 +1,82 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef ABSTRACTPACKAGINGSTEP_H
#define ABSTRACTPACKAGINGSTEP_H
#include "remotelinux_export.h"
#include <projectexplorer/buildstep.h>
namespace RemoteLinux {
class RemoteLinuxDeployConfiguration;
namespace Internal {
class AbstractPackagingStepPrivate;
}
class REMOTELINUX_EXPORT AbstractPackagingStep : public ProjectExplorer::BuildStep
{
Q_OBJECT
public:
AbstractPackagingStep(ProjectExplorer::BuildStepList *bsl, const QString &id);
AbstractPackagingStep(ProjectExplorer::BuildStepList *bsl, AbstractPackagingStep *other);
~AbstractPackagingStep();
QString packageFilePath() const;
bool init();
signals:
void packageFilePathChanged();
protected:
void setPackagingStarted();
void setPackagingFinished(bool success);
void raiseError(const QString &errorMessage);
RemoteLinuxDeployConfiguration *deployConfiguration() const;
QString packageDirectory() const;
virtual bool isPackagingNeeded() const;
private slots:
void handleBuildConfigurationChanged();
private:
virtual QString packageFileName() const=0;
void ctor();
Internal::AbstractPackagingStepPrivate *m_d;
};
} // namespace RemoteLinux
#endif // ABSTRACTPACKAGINGSTEP_H

View File

@@ -33,7 +33,7 @@
#include "abstractremotelinuxdeployservice.h"
#include "maemodeploystepwidget.h"
#include "qt4maemodeployconfiguration.h"
#include "remotelinuxdeployconfiguration.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <qt4projectmanager/qt4buildconfiguration.h>

View File

@@ -37,7 +37,6 @@
namespace RemoteLinux {
namespace Internal {
class AbstractMaemoPackageCreationStep;
class AbstractMaemoPackageInstaller;
class AbstractUploadAndInstallPackageServicePrivate;
}

View File

@@ -32,8 +32,8 @@
#include "genericremotelinuxdeploystepfactory.h"
#include "genericdirectuploadstep.h"
#include "maemopackagecreationstep.h"
#include "remotelinuxdeployconfigurationfactory.h"
#include "tarpackagecreationstep.h"
#include "uploadandinstalltarpackagestep.h"
#include <projectexplorer/buildsteplist.h>
@@ -55,15 +55,15 @@ QStringList GenericRemoteLinuxDeployStepFactory::availableCreationIds(BuildStepL
const DeployConfiguration * const dc = qobject_cast<DeployConfiguration *>(parent->parent());
if (!dc || dc->id() != RemoteLinuxDeployConfigurationFactory::genericDeployConfigurationId())
return ids;
ids << MaemoTarPackageCreationStep::CreatePackageId << UploadAndInstallTarPackageStep::stepId()
ids << TarPackageCreationStep::stepId() << UploadAndInstallTarPackageStep::stepId()
<< GenericDirectUploadStep::stepId();
return ids;
}
QString GenericRemoteLinuxDeployStepFactory::displayNameForId(const QString &id) const
{
if (id == MaemoTarPackageCreationStep::CreatePackageId)
return tr("Create tarball");
if (id == TarPackageCreationStep::stepId())
return TarPackageCreationStep::displayName();
if (id == UploadAndInstallTarPackageStep::stepId())
return UploadAndInstallTarPackageStep::displayName();
if (id == GenericDirectUploadStep::stepId())
@@ -80,8 +80,8 @@ BuildStep *GenericRemoteLinuxDeployStepFactory::create(BuildStepList *parent, co
{
Q_ASSERT(canCreate(parent, id));
if (id == MaemoTarPackageCreationStep::CreatePackageId)
return new MaemoTarPackageCreationStep(parent);
if (id == TarPackageCreationStep::stepId())
return new TarPackageCreationStep(parent);
if (id == UploadAndInstallTarPackageStep::stepId())
return new UploadAndInstallTarPackageStep(parent);
if (id == GenericDirectUploadStep::stepId())
@@ -115,8 +115,8 @@ bool GenericRemoteLinuxDeployStepFactory::canClone(BuildStepList *parent, BuildS
BuildStep *GenericRemoteLinuxDeployStepFactory::clone(BuildStepList *parent, BuildStep *product)
{
if (MaemoTarPackageCreationStep * const other = qobject_cast<MaemoTarPackageCreationStep *>(product))
return new MaemoTarPackageCreationStep(parent, other);
if (TarPackageCreationStep * const other = qobject_cast<TarPackageCreationStep *>(product))
return new TarPackageCreationStep(parent, other);
if (UploadAndInstallTarPackageStep * const other = qobject_cast<UploadAndInstallTarPackageStep*>(product))
return new UploadAndInstallTarPackageStep(parent, other);
if (GenericDirectUploadStep * const other = qobject_cast<GenericDirectUploadStep *>(product))

View File

@@ -31,14 +31,11 @@
#include "maemopackagecreationstep.h"
#include "deploymentinfo.h"
#include "maemoconstants.h"
#include "maemoglobal.h"
#include "maemopackagecreationwidget.h"
#include "qt4maemotarget.h"
#include "remotelinuxdeployconfiguration.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4project.h>
@@ -49,8 +46,6 @@
#include <QtCore/QDateTime>
#include <QtCore/QProcess>
#include <QtCore/QRegExp>
#include <QtCore/QStringBuilder>
#include <QtGui/QWidget>
namespace {
const QLatin1String MagicFileName(".qtcreator");
@@ -68,44 +63,28 @@ namespace Internal {
const QLatin1String AbstractMaemoPackageCreationStep::DefaultVersionNumber("0.0.1");
AbstractMaemoPackageCreationStep::AbstractMaemoPackageCreationStep(BuildStepList *bsl,
const QString &id)
: ProjectExplorer::BuildStep(bsl, id)
const QString &id) : AbstractPackagingStep(bsl, id)
{
ctor();
}
AbstractMaemoPackageCreationStep::AbstractMaemoPackageCreationStep(BuildStepList *bsl,
AbstractMaemoPackageCreationStep *other) : BuildStep(bsl, other)
AbstractMaemoPackageCreationStep *other) : AbstractPackagingStep(bsl, other)
{
ctor();
}
AbstractMaemoPackageCreationStep::~AbstractMaemoPackageCreationStep()
{
}
void AbstractMaemoPackageCreationStep::ctor()
{
m_lastBuildConfig = qt4BuildConfiguration();
connect(target(),
SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(handleBuildConfigChanged()));
handleBuildConfigChanged();
}
bool AbstractMaemoPackageCreationStep::init()
{
return true;
}
void AbstractMaemoPackageCreationStep::run(QFutureInterface<bool> &fi)
{
if (!packagingNeeded()) {
if (!isPackagingNeeded()) {
emit addOutput(tr("Package up to date."), MessageOutput);
fi.reportResult(true);
return;
}
setPackagingStarted();
// TODO: Make the build process asynchronous; i.e. no waitFor()-functions etc.
QProcess * const buildProc = new QProcess;
connect(buildProc, SIGNAL(readyReadStandardOutput()), this,
@@ -116,10 +95,9 @@ void AbstractMaemoPackageCreationStep::run(QFutureInterface<bool> &fi)
const bool success = createPackage(buildProc, fi);
disconnect(buildProc, 0, this, 0);
buildProc->deleteLater();
if (success) {
if (success)
emit addOutput(tr("Package created."), BuildStep::MessageOutput);
deployConfig()->deploymentInfo()->setUnmodified();
}
setPackagingFinished(success);
fi.reportResult(success);
}
@@ -146,19 +124,6 @@ void AbstractMaemoPackageCreationStep::handleBuildOutput()
}
}
void AbstractMaemoPackageCreationStep::handleBuildConfigChanged()
{
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();
}
const Qt4BuildConfiguration *AbstractMaemoPackageCreationStep::qt4BuildConfiguration() const
{
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
@@ -179,41 +144,20 @@ AbstractRpmBasedQt4MaemoTarget *AbstractMaemoPackageCreationStep::rpmBasedMaemoT
return qobject_cast<AbstractRpmBasedQt4MaemoTarget*>(buildConfiguration()->target());
}
RemoteLinuxDeployConfiguration *AbstractMaemoPackageCreationStep::deployConfig() const
{
return qobject_cast<RemoteLinuxDeployConfiguration *>(parent()->parent());
}
QString AbstractMaemoPackageCreationStep::buildDirectory() const
{
return qt4BuildConfiguration()->buildDirectory();
}
QString AbstractMaemoPackageCreationStep::projectName() const
{
return qt4BuildConfiguration()->qt4Target()->qt4Project()
->rootProjectNode()->displayName().toLower();
}
bool AbstractMaemoPackageCreationStep::packagingNeeded() const
bool AbstractMaemoPackageCreationStep::isPackagingNeeded() const
{
const QSharedPointer<DeploymentInfo> &deploymentInfo
= deployConfig()->deploymentInfo();
QFileInfo packageInfo(packageFilePath());
if (!packageInfo.exists() || deploymentInfo->isModified())
if (AbstractPackagingStep::isPackagingNeeded())
return true;
const int deployableCount = deploymentInfo->deployableCount();
for (int i = 0; i < deployableCount; ++i) {
if (Utils::FileUtils::isFileNewerThan(deploymentInfo->deployableAt(i).localFilePath,
packageInfo.lastModified()))
return true;
}
return isMetaDataNewerThan(packageInfo.lastModified());
return isMetaDataNewerThan(QFileInfo(packageFilePath()).lastModified());
}
QString AbstractMaemoPackageCreationStep::packageFilePath() const
QString AbstractMaemoPackageCreationStep::packageFileName() const
{
QString error;
const QString &version = versionString(&error);
@@ -221,8 +165,7 @@ QString AbstractMaemoPackageCreationStep::packageFilePath() const
return QString();
QFileInfo fi(maemoTarget()->packageFileName());
const QString baseName = replaceDots(fi.completeBaseName());
return buildDirectory() + QLatin1Char('/') + baseName
+ QLatin1Char('.') + fi.suffix();
return baseName + QLatin1Char('.') + fi.suffix();
}
QString AbstractMaemoPackageCreationStep::versionString(QString *error) const
@@ -230,8 +173,7 @@ QString AbstractMaemoPackageCreationStep::versionString(QString *error) const
return maemoTarget()->projectVersion(error);
}
bool AbstractMaemoPackageCreationStep::setVersionString(const QString &version,
QString *error)
bool AbstractMaemoPackageCreationStep::setVersionString(const QString &version, QString *error)
{
const bool success = maemoTarget()->setProjectVersion(version, error);
if (success)
@@ -244,21 +186,13 @@ QString AbstractMaemoPackageCreationStep::nativePath(const QFile &file)
return QDir::toNativeSeparators(QFileInfo(file).filePath());
}
void AbstractMaemoPackageCreationStep::raiseError(const QString &shortMsg,
const QString &detailedMsg)
{
emit addOutput(detailedMsg.isNull() ? shortMsg : detailedMsg, BuildStep::ErrorOutput);
emit addTask(Task(Task::Error, shortMsg, QString(), -1,
TASK_CATEGORY_BUILDSYSTEM));
}
bool AbstractMaemoPackageCreationStep::callPackagingCommand(QProcess *proc,
const QStringList &arguments)
{
preparePackagingProcess(proc, qt4BuildConfiguration(), buildDirectory());
preparePackagingProcess(proc, qt4BuildConfiguration(), packageDirectory());
const QtSupport::BaseQtVersion * const qtVersion = qt4BuildConfiguration()->qtVersion();
if (!qtVersion) {
raiseError(tr("Packaging failed."), tr("Packaging error: No Qt version."));
raiseError(tr("Packaging failed: No Qt version."));
return false;
}
const QString madCommand = MaemoGlobal::madCommand(qtVersion->qmakeCommand());
@@ -268,8 +202,7 @@ bool AbstractMaemoPackageCreationStep::callPackagingCommand(QProcess *proc,
BuildStep::MessageOutput);
MaemoGlobal::callMad(*proc, arguments, qtVersion->qmakeCommand(), true);
if (!proc->waitForStarted()) {
raiseError(tr("Packaging failed."),
tr("Packaging error: Could not start command '%1'. Reason: %2")
raiseError(tr("Packaging failed: Could not start command '%1'. Reason: %2")
.arg(cmdLine, proc->errorString()));
return false;
}
@@ -333,10 +266,8 @@ bool MaemoDebianPackageCreationStep::createPackage(QProcess *buildProc,
{
Q_UNUSED(fi);
checkProjectName();
const QString projectDir
= buildConfiguration()->target()->project()->projectDirectory();
const bool inSourceBuild
= QFileInfo(buildDirectory()) == QFileInfo(projectDir);
const QString projectDir = buildConfiguration()->target()->project()->projectDirectory();
const bool inSourceBuild = QFileInfo(packageDirectory()) == QFileInfo(projectDir);
if (!copyDebianFiles(inSourceBuild))
return false;
const QStringList args = QStringList() << QLatin1String("dpkg-buildpackage")
@@ -347,36 +278,32 @@ bool MaemoDebianPackageCreationStep::createPackage(QProcess *buildProc,
QFile::remove(packageFilePath());
// Workaround for non-working dh_builddeb --destdir=.
if (!QDir(buildDirectory()).isRoot()) {
if (!QDir(packageDirectory()).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.");
raiseError(tr("Packaging failed: Could not 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 packageSourceDir = packageDirectory() + QLatin1String("/../");
const QString packageSourceFilePath = packageSourceDir + pkgFileName;
const QString changesSourceFilePath = packageSourceDir + changesSourceFileName;
const QString changesTargetFilePath
= buildDirectory() + QLatin1Char('/') + changesTargetFileName;
= packageDirectory() + 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()));
raiseError(tr("Packaging failed: Could not move package files from '%1'' to '%2'.")
.arg(packageSourceDir, packageDirectory()));
return false;
}
}
if (inSourceBuild) {
buildProc->start(packagingCommand(qt4BuildConfiguration(),
QLatin1String("dh_clean")));
buildProc->start(packagingCommand(qt4BuildConfiguration(), QLatin1String("dh_clean")));
buildProc->waitForFinished();
buildProc->terminate();
}
@@ -390,8 +317,7 @@ bool MaemoDebianPackageCreationStep::isMetaDataNewerThan(const QDateTime &packag
return true;
const QStringList debianFiles = debBasedMaemoTarget()->debianFiles();
foreach (const QString &debianFile, debianFiles) {
const QString absFilePath
= debianPath + QLatin1Char('/') + debianFile;
const QString absFilePath = debianPath + QLatin1Char('/') + debianFile;
if (packageDate <= QFileInfo(absFilePath).lastModified())
return true;
}
@@ -413,29 +339,27 @@ void MaemoDebianPackageCreationStep::checkProjectName()
bool MaemoDebianPackageCreationStep::copyDebianFiles(bool inSourceBuild)
{
const QString debianDirPath = buildDirectory() + QLatin1String("/debian");
const QString debianDirPath = packageDirectory() + 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 "
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)));
"shadow build feature.").arg(QDir::toNativeSeparators(debianDirPath)));
return false;
}
QString error;
if (!Utils::FileUtils::removeRecursively(debianDirPath, &error)) {
raiseError(tr("Packaging failed."),
tr("Could not remove directory '%1': %2").arg(debianDirPath, error));
raiseError(tr("Packaging failed: Could not remove directory '%1': %2")
.arg(debianDirPath, error));
return false;
}
QDir buildDir(buildDirectory());
QDir buildDir(packageDirectory());
if (!buildDir.mkdir("debian")) {
raiseError(tr("Could not create Debian directory '%1'.")
.arg(debianDirPath));
raiseError(tr("Could not create Debian directory '%1'.").arg(debianDirPath));
return false;
}
const QString templatesDirPath = debBasedMaemoTarget()->debianDirPath();
@@ -457,8 +381,7 @@ bool MaemoDebianPackageCreationStep::copyDebianFiles(bool inSourceBuild)
return false;
} else if (!QFile::copy(srcFile, destFile)) {
raiseError(tr("Could not copy file '%1' to '%2'")
.arg(QDir::toNativeSeparators(srcFile),
QDir::toNativeSeparators(destFile)));
.arg(QDir::toNativeSeparators(srcFile), QDir::toNativeSeparators(destFile)));
return false;
}
}
@@ -545,17 +468,18 @@ void MaemoRpmPackageCreationStep::ctor()
bool MaemoRpmPackageCreationStep::createPackage(QProcess *buildProc,
const QFutureInterface<bool> &fi)
{
setPackagingStarted();
Q_UNUSED(fi);
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();
const QString packageSourceFilePath = rpmBuildDir() + QLatin1Char('/')
+ rpmBasedMaemoTarget()->packageFileName();
if (!QFile::rename(packageSourceFilePath, packageFilePath())) {
raiseError(tr("Packaging failed."),
tr("Could not move package file from %1 to %2.")
raiseError(tr("Packaging failed: Could not move package file from %1 to %2.")
.arg(packageSourceFilePath, packageFilePath()));
return false;
}
@@ -570,267 +494,13 @@ bool MaemoRpmPackageCreationStep::isMetaDataNewerThan(const QDateTime &packageDa
return packageDate <= specFileChangeDate;
}
QString MaemoRpmPackageCreationStep::rpmBuildDir(const Qt4BuildConfiguration *bc)
QString MaemoRpmPackageCreationStep::rpmBuildDir() const
{
return bc->buildDirectory() + QLatin1String("/rrpmbuild");
return packageDirectory() + QLatin1String("/rrpmbuild");
}
const QString MaemoRpmPackageCreationStep::CreatePackageId
= QLatin1String("MaemoRpmPackageCreationStep");
class CreateTarStepWidget : public BuildStepConfigWidget
{
Q_OBJECT
public:
CreateTarStepWidget(MaemoTarPackageCreationStep *step) : m_step(step)
{
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;
};
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.
MaemoTarPackageCreationStep::MaemoTarPackageCreationStep(BuildStepList *bsl)
: AbstractMaemoPackageCreationStep(bsl, CreatePackageId)
{
ctor();
}
MaemoTarPackageCreationStep::MaemoTarPackageCreationStep(BuildStepList *buildConfig,
MaemoTarPackageCreationStep *other)
: AbstractMaemoPackageCreationStep(buildConfig, other)
{
ctor();
}
void MaemoTarPackageCreationStep::ctor()
{
setDefaultDisplayName(tr("Create tarball"));
}
bool MaemoTarPackageCreationStep::createPackage(QProcess *buildProc,
const QFutureInterface<bool> &fi)
{
Q_UNUSED(buildProc);
// 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<DeploymentInfo> deploymentInfo = deployConfig()->deploymentInfo();
for (int i = 0; i < deploymentInfo->deployableCount(); ++i) {
const DeployableFile &d = deploymentInfo->deployableAt(i);
QFileInfo fileInfo(d.localFilePath);
if (!appendFile(tarFile, fileInfo, d.remoteDir + QLatin1Char('/')
+ fileInfo.fileName(), fi)) {
return false;
}
}
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;
}
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;
// 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 add file '%1' to tar-archive: path 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;
}
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");
} // namespace Internal
} // namespace RemoteLinux
#include "maemopackagecreationstep.moc"

View File

@@ -32,12 +32,11 @@
#ifndef MAEMOPACKAGECREATIONSTEP_H
#define MAEMOPACKAGECREATIONSTEP_H
#include <projectexplorer/buildstep.h>
#include<remotelinux/abstractpackagingstep.h>
QT_BEGIN_NAMESPACE
class QDateTime;
class QFile;
class QFileInfo;
class QProcess;
QT_END_NAMESPACE
@@ -51,14 +50,12 @@ class AbstractQt4MaemoTarget;
class AbstractDebBasedQt4MaemoTarget;
class AbstractRpmBasedQt4MaemoTarget;
class AbstractMaemoPackageCreationStep : public ProjectExplorer::BuildStep
class AbstractMaemoPackageCreationStep : public RemoteLinux::AbstractPackagingStep
{
Q_OBJECT
public:
virtual ~AbstractMaemoPackageCreationStep();
virtual QString packageFilePath() const;
QString versionString(QString *error) const;
bool setVersionString(const QString &version, QString *error);
@@ -66,18 +63,13 @@ public:
const Qt4ProjectManager::Qt4BuildConfiguration *bc,
const QString &workingDir);
QString projectName() const;
const Qt4ProjectManager::Qt4BuildConfiguration *qt4BuildConfiguration() const;
AbstractQt4MaemoTarget *maemoTarget() const;
AbstractDebBasedQt4MaemoTarget *debBasedMaemoTarget() const;
AbstractRpmBasedQt4MaemoTarget *rpmBasedMaemoTarget() const;
RemoteLinuxDeployConfiguration *deployConfig() const;
static const QLatin1String DefaultVersionNumber;
signals:
void packageFilePathChanged();
void qtVersionChanged();
protected:
AbstractMaemoPackageCreationStep(ProjectExplorer::BuildStepList *bsl,
@@ -85,27 +77,24 @@ protected:
AbstractMaemoPackageCreationStep(ProjectExplorer::BuildStepList *buildConfig,
AbstractMaemoPackageCreationStep *other);
void raiseError(const QString &shortMsg,
const QString &detailedMsg = QString());
bool callPackagingCommand(QProcess *proc, const QStringList &arguments);
static QString replaceDots(const QString &name);
QString buildDirectory() const;
private slots:
void handleBuildOutput();
void handleBuildConfigChanged();
private:
void ctor();
virtual bool init();
virtual void run(QFutureInterface<bool> &fi);
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual QString packageFileName() const;
virtual bool createPackage(QProcess *buildProc, const QFutureInterface<bool> &fi)=0;
virtual bool isMetaDataNewerThan(const QDateTime &packageDate) const=0;
QString projectName() const;
static QString nativePath(const QFile &file);
bool packagingNeeded() const;
bool isPackagingNeeded() const;
const Qt4ProjectManager::Qt4BuildConfiguration *m_lastBuildConfig;
};
@@ -152,34 +141,11 @@ private:
MaemoRpmPackageCreationStep *other);
void ctor();
static QString rpmBuildDir(const Qt4ProjectManager::Qt4BuildConfiguration *bc);
QString rpmBuildDir() const;
static const QString CreatePackageId;
};
class MaemoTarPackageCreationStep : public AbstractMaemoPackageCreationStep
{
Q_OBJECT
public:
MaemoTarPackageCreationStep(ProjectExplorer::BuildStepList *bsl);
MaemoTarPackageCreationStep(ProjectExplorer::BuildStepList *buildConfig,
MaemoTarPackageCreationStep *other);
virtual QString packageFilePath() const;
static const QString CreatePackageId;
private:
virtual bool createPackage(QProcess *buildProc, const QFutureInterface<bool> &fi);
virtual bool isMetaDataNewerThan(const QDateTime &packageDate) const;
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
void ctor();
bool appendFile(QFile &tarFile, const QFileInfo &fileInfo,
const QString &remoteFilePath, const QFutureInterface<bool> &fi);
bool writeHeader(QFile &tarFile, const QFileInfo &fileInfo,
const QString &remoteFilePath);
};
} // namespace Internal
} // namespace RemoteLinux

View File

@@ -89,7 +89,9 @@ HEADERS += \
genericdirectuploadservice.h \
remotelinuxdeployconfiguration.h \
remotelinuxdeployconfigurationfactory.h \
genericremotelinuxdeploystepfactory.h
genericremotelinuxdeploystepfactory.h \
abstractpackagingstep.h \
tarpackagecreationstep.h
SOURCES += \
remotelinuxplugin.cpp \
@@ -172,7 +174,9 @@ SOURCES += \
genericdirectuploadservice.cpp \
remotelinuxdeployconfiguration.cpp \
remotelinuxdeployconfigurationfactory.cpp \
genericremotelinuxdeploystepfactory.cpp
genericremotelinuxdeploystepfactory.cpp \
abstractpackagingstep.cpp \
tarpackagecreationstep.cpp
FORMS += \
maemoconfigtestdialog.ui \

View File

@@ -33,8 +33,8 @@
#include "linuxdeviceconfiguration.h"
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "remotelinuxdeployconfiguration.h"
#include "tarpackagecreationstep.h"
#include "uploadandinstalltarpackagestep.h"
using namespace ProjectExplorer;
@@ -78,7 +78,7 @@ DeployConfiguration *RemoteLinuxDeployConfigurationFactory::create(Target *paren
DeployConfiguration * const dc = new RemoteLinuxDeployConfiguration(parent, id,
genericLinuxDisplayName(), LinuxDeviceConfiguration::GenericLinuxOsType);
dc->stepList()->insertStep(0, new MaemoTarPackageCreationStep(dc->stepList()));
dc->stepList()->insertStep(0, new TarPackageCreationStep(dc->stepList()));
dc->stepList()->insertStep(1, new UploadAndInstallTarPackageStep(dc->stepList()));
return dc;
}

View File

@@ -0,0 +1,305 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "tarpackagecreationstep.h"
#include "deployablefile.h"
#include "deploymentinfo.h"
#include "remotelinuxdeployconfiguration.h"
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
using namespace ProjectExplorer;
namespace RemoteLinux {
namespace {
class CreateTarStepWidget : public BuildStepConfigWidget
{
Q_OBJECT
public:
CreateTarStepWidget(TarPackageCreationStep *step) : m_step(step)
{
connect(m_step, SIGNAL(packageFilePathChanged()), SIGNAL(updateSummary()));
}
QString summaryText() const
{
if (m_step->packageFilePath().isEmpty()) {
return QLatin1String("<font color=\"red\">")
+ tr("Tarball creation not possible.") + QLatin1String("</font>");
}
return QLatin1String("<b>") + tr("Create tarball:") + QLatin1String("</b> ")
+ m_step->packageFilePath();
}
QString displayName() const { return QString(); }
private:
const TarPackageCreationStep * const m_step;
};
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.
TarPackageCreationStep::TarPackageCreationStep(BuildStepList *bsl)
: AbstractPackagingStep(bsl, stepId())
{
ctor();
}
TarPackageCreationStep::TarPackageCreationStep(BuildStepList *bsl, TarPackageCreationStep *other)
: AbstractPackagingStep(bsl, other)
{
ctor();
}
void TarPackageCreationStep::ctor()
{
setDefaultDisplayName(displayName());
}
void TarPackageCreationStep::run(QFutureInterface<bool> &fi)
{
setPackagingStarted();
const bool success = doPackage(fi);
setPackagingFinished(success);
if (success)
emit addOutput(tr("Packaging finished successfully."), MessageOutput);
else
emit addOutput(tr("Packaging failed."), ErrorMessageOutput);
fi.reportResult(success);
}
bool TarPackageCreationStep::doPackage(QFutureInterface<bool> &fi)
{
emit addOutput(tr("Creating tarball..."), MessageOutput);
if (!isPackagingNeeded()) {
emit addOutput(tr("Tarball up to date, skipping packaging."), MessageOutput);
return true;
}
// TODO: Optimization: Only package changed files
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<DeploymentInfo> deploymentInfo = deployConfiguration()->deploymentInfo();
for (int i = 0; i < deploymentInfo->deployableCount(); ++i) {
const DeployableFile &d = deploymentInfo->deployableAt(i);
QFileInfo fileInfo(d.localFilePath);
if (!appendFile(tarFile, fileInfo, d.remoteDir + QLatin1Char('/')
+ fileInfo.fileName(), fi)) {
return false;
}
}
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;
}
return true;
}
bool TarPackageCreationStep::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;
}
return true;
}
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;
emit addOutput(tr("Adding file '%1' to tarball...").arg(nativePath), MessageOutput);
// 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 TarPackageCreationStep::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 add file '%1' to tar-archive: path 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;
}
return true;
}
QString TarPackageCreationStep::packageFileName() const
{
return target()->project()->displayName() + QLatin1String(".tar");
}
BuildStepConfigWidget *TarPackageCreationStep::createConfigWidget()
{
return new CreateTarStepWidget(this);
}
QString TarPackageCreationStep::stepId()
{
return QLatin1String("MaemoTarPackageCreationStep");
}
QString TarPackageCreationStep::displayName()
{
return tr("Create tarball");
}
} // namespace RemoteLinux
#include "tarpackagecreationstep.moc"

View File

@@ -0,0 +1,70 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef TARPACKAGECREATIONSTEP_H
#define TARPACKAGECREATIONSTEP_H
#include "abstractpackagingstep.h"
#include "remotelinux_export.h"
QT_BEGIN_NAMESPACE
class QFile;
class QFileInfo;
QT_END_NAMESPACE
namespace RemoteLinux {
class REMOTELINUX_EXPORT TarPackageCreationStep : public AbstractPackagingStep
{
Q_OBJECT
public:
TarPackageCreationStep(ProjectExplorer::BuildStepList *bsl);
TarPackageCreationStep(ProjectExplorer::BuildStepList *bsl, TarPackageCreationStep *other);
static QString stepId();
static QString displayName();
void run(QFutureInterface<bool> &fi);
private:
ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
QString packageFileName() const;
void ctor();
bool doPackage(QFutureInterface<bool> &fi);
bool appendFile(QFile &tarFile, const QFileInfo &fileInfo,
const QString &remoteFilePath, const QFutureInterface<bool> &fi);
bool writeHeader(QFile &tarFile, const QFileInfo &fileInfo,
const QString &remoteFilePath);
};
} // namespace RemoteLinux
#endif // TARPACKAGECREATIONSTEP_H

View File

@@ -32,9 +32,9 @@
#include "uploadandinstalltarpackagestep.h"
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemopackageinstaller.h"
#include "qt4maemodeployconfiguration.h"
#include "remotelinuxdeployconfiguration.h"
#include "tarpackagecreationstep.h"
#include <projectexplorer/buildsteplist.h>
@@ -92,8 +92,8 @@ void UploadAndInstallTarPackageStep::ctor()
bool UploadAndInstallTarPackageStep::isDeploymentPossible(QString *whyNot) const
{
const AbstractMaemoPackageCreationStep * const pStep
= MaemoGlobal::earlierBuildStep<MaemoTarPackageCreationStep>(deployConfiguration(), this);
const TarPackageCreationStep * const pStep
= MaemoGlobal::earlierBuildStep<TarPackageCreationStep>(deployConfiguration(), this);
if (!pStep) {
if (whyNot)
*whyNot = tr("No tarball creation step found.");