2010-04-06 16:56:47 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
** All rights reserved.
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
|
** No Commercial Usage
|
|
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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-14 12:21:35 +02:00
|
|
|
#include "maemodeploystep.h"
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemoglobal.h"
|
|
|
|
|
#include "maemopackagecreationwidget.h"
|
2010-08-03 16:27:34 +02:00
|
|
|
#include "maemotemplatesmanager.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>
|
2010-04-07 17:10:00 +02:00
|
|
|
#include <qt4buildconfiguration.h>
|
|
|
|
|
#include <qt4project.h>
|
|
|
|
|
#include <qt4target.h>
|
2010-11-17 11:09:40 +01:00
|
|
|
#include <utils/environment.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 {
|
|
|
|
|
const QLatin1String PackagingEnabledKey("Packaging Enabled");
|
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;
|
2010-04-06 16:56:47 +02:00
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-08-03 16:27:34 +02:00
|
|
|
const QLatin1String MaemoPackageCreationStep::DefaultVersionNumber("0.0.1");
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
MaemoPackageCreationStep::MaemoPackageCreationStep(BuildStepList *bsl)
|
|
|
|
|
: ProjectExplorer::BuildStep(bsl, CreatePackageId),
|
2010-08-03 16:27:34 +02:00
|
|
|
m_packagingEnabled(true)
|
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
|
|
|
}
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
MaemoPackageCreationStep::MaemoPackageCreationStep(BuildStepList *bsl,
|
2010-04-06 16:56:47 +02:00
|
|
|
MaemoPackageCreationStep *other)
|
2010-07-16 14:00:41 +02:00
|
|
|
: BuildStep(bsl, other),
|
2010-08-03 16:27:34 +02:00
|
|
|
m_packagingEnabled(other->m_packagingEnabled)
|
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
|
|
|
}
|
|
|
|
|
|
2010-07-06 12:04:53 +02:00
|
|
|
MaemoPackageCreationStep::~MaemoPackageCreationStep()
|
|
|
|
|
{
|
|
|
|
|
}
|
2010-06-29 14:10:01 +02:00
|
|
|
|
2010-07-28 16:03:11 +02:00
|
|
|
void MaemoPackageCreationStep::ctor()
|
|
|
|
|
{
|
2010-08-19 12:26:21 +02:00
|
|
|
setDefaultDisplayName(tr("Packaging for Maemo"));
|
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
|
|
|
}
|
|
|
|
|
|
2010-04-06 16:56:47 +02:00
|
|
|
bool MaemoPackageCreationStep::init()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-03 15:50:15 +02:00
|
|
|
QVariantMap MaemoPackageCreationStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map(ProjectExplorer::BuildStep::toMap());
|
2010-06-11 11:58:12 +02:00
|
|
|
map.insert(PackagingEnabledKey, m_packagingEnabled);
|
2010-06-16 08:57:13 +02:00
|
|
|
return map;
|
2010-05-03 15:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoPackageCreationStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2010-06-11 11:58:12 +02:00
|
|
|
m_packagingEnabled = map.value(PackagingEnabledKey, true).toBool();
|
2010-05-03 15:50:15 +02:00
|
|
|
return ProjectExplorer::BuildStep::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-06 16:56:47 +02:00
|
|
|
void MaemoPackageCreationStep::run(QFutureInterface<bool> &fi)
|
|
|
|
|
{
|
2010-08-27 12:39:15 +02:00
|
|
|
bool success;
|
|
|
|
|
if (m_packagingEnabled) {
|
2010-10-04 12:54:14 +02:00
|
|
|
// TODO: Make the build process asynchronous; i.e. no waitFor()-functions etc.
|
2010-08-27 12:39:15 +02:00
|
|
|
QProcess * const buildProc = new QProcess;
|
|
|
|
|
connect(buildProc, SIGNAL(readyReadStandardOutput()), this,
|
|
|
|
|
SLOT(handleBuildOutput()));
|
|
|
|
|
connect(buildProc, SIGNAL(readyReadStandardError()), this,
|
|
|
|
|
SLOT(handleBuildOutput()));
|
|
|
|
|
success = createPackage(buildProc);
|
|
|
|
|
disconnect(buildProc, 0, this, 0);
|
|
|
|
|
buildProc->deleteLater();
|
|
|
|
|
} else {
|
|
|
|
|
success = true;
|
|
|
|
|
}
|
|
|
|
|
fi.reportResult(success);
|
2010-04-06 16:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildStepConfigWidget *MaemoPackageCreationStep::createConfigWidget()
|
|
|
|
|
{
|
|
|
|
|
return new MaemoPackageCreationWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-27 12:39:15 +02:00
|
|
|
bool MaemoPackageCreationStep::createPackage(QProcess *buildProc)
|
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);
|
2010-04-07 17:10:00 +02:00
|
|
|
return true;
|
2010-08-27 12:39:15 +02:00
|
|
|
}
|
2010-04-07 17:10:00 +02:00
|
|
|
|
2010-08-27 12:39:15 +02:00
|
|
|
emit addOutput(tr("Creating package file ..."), MessageOutput);
|
2010-08-06 12:57:01 +02:00
|
|
|
checkProjectName();
|
2010-08-03 16:27:34 +02:00
|
|
|
QString error;
|
2010-11-02 16:15:56 +01:00
|
|
|
if (!preparePackagingProcess(buildProc, qt4BuildConfiguration(),
|
|
|
|
|
buildDirectory(), &error)) {
|
2010-08-03 16:27:34 +02:00
|
|
|
raiseError(error);
|
2010-04-07 17:10:00 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-04-09 17:13:33 +02:00
|
|
|
|
2010-08-27 11:46:54 +02:00
|
|
|
const QString projectDir
|
|
|
|
|
= buildConfiguration()->target()->project()->projectDirectory();
|
|
|
|
|
const bool inSourceBuild
|
|
|
|
|
= QFileInfo(buildDirectory()) == QFileInfo(projectDir);
|
2010-10-18 17:45:39 +02:00
|
|
|
if (!copyDebianFiles(inSourceBuild))
|
2010-08-03 16:27:34 +02:00
|
|
|
return false;
|
2010-06-28 11:59:36 +02:00
|
|
|
|
2011-01-04 14:14:12 +01:00
|
|
|
const QtVersion * const qtVersion = qt4BuildConfiguration()->qtVersion();
|
|
|
|
|
const QString madCommand = MaemoGlobal::madCommand(qtVersion);
|
2010-12-01 13:31:23 +01:00
|
|
|
const QStringList args = QStringList() << QLatin1String("-t")
|
2011-01-04 14:14:12 +01:00
|
|
|
<< MaemoGlobal::targetName(qtVersion)
|
|
|
|
|
<< QLatin1String("dpkg-buildpackage") << QLatin1String("-nc")
|
|
|
|
|
<< QLatin1String("-uc") << QLatin1String("-us");
|
2010-12-01 13:31:23 +01:00
|
|
|
const QString cmdLine = madCommand + QLatin1Char(' ')
|
|
|
|
|
+ args.join(QLatin1String(" "));
|
|
|
|
|
emit addOutput(tr("Package Creation: Running command '%1'.").arg(cmdLine),
|
|
|
|
|
BuildStep::MessageOutput);
|
2011-01-04 14:14:12 +01:00
|
|
|
MaemoGlobal::callMad(*buildProc, args, qtVersion);
|
2010-12-01 13:31:23 +01:00
|
|
|
if (!buildProc->waitForStarted()) {
|
|
|
|
|
raiseError(tr("Packaging failed."),
|
|
|
|
|
tr("Packaging error: Could not start command '%1'. Reason: %2")
|
|
|
|
|
.arg(cmdLine, buildProc->errorString()));
|
2010-04-07 17:10:00 +02:00
|
|
|
return false;
|
2010-12-01 13:31:23 +01:00
|
|
|
}
|
|
|
|
|
buildProc->waitForFinished(-1);
|
|
|
|
|
if (buildProc->error() != QProcess::UnknownError
|
|
|
|
|
|| buildProc->exitCode() != 0) {
|
|
|
|
|
QString mainMessage = tr("Packaging Error: Command '%1' failed.")
|
|
|
|
|
.arg(cmdLine);
|
|
|
|
|
if (buildProc->error() != QProcess::UnknownError)
|
|
|
|
|
mainMessage += tr(" Reason: %1").arg(buildProc->errorString());
|
|
|
|
|
else
|
|
|
|
|
mainMessage += tr("Exit code: %1").arg(buildProc->exitCode());
|
|
|
|
|
raiseError(mainMessage);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-05-03 14:47:40 +02:00
|
|
|
|
2010-06-18 11:54:41 +02:00
|
|
|
// Workaround for non-working dh_builddeb --destdir=.
|
2010-08-03 16:27:34 +02:00
|
|
|
if (!QDir(buildDirectory()).isRoot()) {
|
|
|
|
|
const ProjectExplorer::Project * const project
|
|
|
|
|
= buildConfiguration()->target()->project();
|
|
|
|
|
QString error;
|
|
|
|
|
const QString pkgFileName = packageFileName(project,
|
|
|
|
|
MaemoTemplatesManager::instance()->version(project, &error));
|
|
|
|
|
if (!error.isEmpty())
|
|
|
|
|
raiseError(tr("Packaging failed."), error);
|
|
|
|
|
const QString changesFileName = QFileInfo(pkgFileName)
|
2010-06-18 11:54:41 +02:00
|
|
|
.completeBaseName() + QLatin1String(".changes");
|
2010-08-03 16:27:34 +02:00
|
|
|
const QString packageSourceDir = buildDirectory() + QLatin1String("/../");
|
2010-06-18 11:54:41 +02:00
|
|
|
const QString packageSourceFilePath
|
2010-08-03 16:27:34 +02:00
|
|
|
= packageSourceDir + pkgFileName;
|
2010-06-18 11:54:41 +02:00
|
|
|
const QString changesSourceFilePath
|
|
|
|
|
= packageSourceDir + changesFileName;
|
|
|
|
|
const QString changesTargetFilePath
|
2010-08-03 16:27:34 +02:00
|
|
|
= buildDirectory() + QLatin1Char('/') + changesFileName;
|
|
|
|
|
QFile::remove(packageFilePath());
|
2010-06-18 11:54:41 +02:00
|
|
|
QFile::remove(changesTargetFilePath);
|
2010-08-03 16:27:34 +02:00
|
|
|
if (!QFile::rename(packageSourceFilePath, packageFilePath())
|
2010-06-18 11:54:41 +02:00
|
|
|
|| !QFile::rename(changesSourceFilePath, changesTargetFilePath)) {
|
|
|
|
|
raiseError(tr("Packaging failed."),
|
|
|
|
|
tr("Could not move package files from %1 to %2.")
|
2010-08-03 16:27:34 +02:00
|
|
|
.arg(packageSourceDir, buildDirectory()));
|
2010-05-03 14:47:40 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-04-07 17:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 10:29:38 +02:00
|
|
|
emit addOutput(tr("Package created."), BuildStep::MessageOutput);
|
2010-07-14 12:21:35 +02:00
|
|
|
deployStep()->deployables()->setUnmodified();
|
2010-08-27 11:46:54 +02:00
|
|
|
if (inSourceBuild) {
|
2011-01-04 14:14:12 +01:00
|
|
|
buildProc->start(packagingCommand(qt4BuildConfiguration(),
|
2010-08-27 11:46:54 +02:00
|
|
|
QLatin1String("dh_clean")));
|
2010-08-27 12:39:15 +02:00
|
|
|
buildProc->waitForFinished();
|
2010-10-18 17:45:39 +02:00
|
|
|
buildProc->terminate();
|
2010-08-27 11:46:54 +02:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-18 17:45:39 +02:00
|
|
|
bool MaemoPackageCreationStep::copyDebianFiles(bool inSourceBuild)
|
2010-08-27 11:46:54 +02:00
|
|
|
{
|
|
|
|
|
const QString debianDirPath = buildDirectory() + QLatin1String("/debian");
|
2010-10-18 17:45:39 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2010-11-26 12:19:32 +01:00
|
|
|
QString error;
|
|
|
|
|
if (!MaemoGlobal::removeRecursively(debianDirPath, error)) {
|
2010-08-27 11:46:54 +02:00
|
|
|
raiseError(tr("Packaging failed."),
|
2010-11-26 12:19:32 +01:00
|
|
|
tr("Could not remove directory '%1': %2").arg(debianDirPath, error));
|
2010-08-27 11:46:54 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QDir buildDir(buildDirectory());
|
|
|
|
|
if (!buildDir.mkdir("debian")) {
|
2010-09-10 10:51:43 +02:00
|
|
|
raiseError(tr("Could not create Debian directory '%1'.")
|
2010-08-27 11:46:54 +02:00
|
|
|
.arg(debianDirPath));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const QString templatesDirPath = MaemoTemplatesManager::instance()
|
|
|
|
|
->debianDirPath(buildConfiguration()->target()->project());
|
|
|
|
|
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;
|
|
|
|
|
if (!QFile::copy(srcFile, destFile)) {
|
|
|
|
|
raiseError(tr("Could not copy file '%1' to '%2'")
|
|
|
|
|
.arg(QDir::toNativeSeparators(srcFile),
|
|
|
|
|
QDir::toNativeSeparators(destFile)));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-23 15:01:19 +02:00
|
|
|
|
2010-11-24 15:51:48 +01:00
|
|
|
if (fileName == QLatin1String("rules"))
|
|
|
|
|
updateDesktopFiles(destFile);
|
2010-08-27 11:46:54 +02:00
|
|
|
}
|
2010-10-18 17:45:39 +02:00
|
|
|
|
|
|
|
|
QFile magicFile(magicFilePath);
|
|
|
|
|
if (!magicFile.open(QIODevice::WriteOnly)) {
|
2010-10-25 16:43:08 +02:00
|
|
|
raiseError(tr("Error: Could not create file '%1'.")
|
2010-10-18 17:45:39 +02:00
|
|
|
.arg(QDir::toNativeSeparators(magicFilePath)));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-07 17:10:00 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-01 11:55:36 +02:00
|
|
|
void MaemoPackageCreationStep::handleBuildOutput()
|
|
|
|
|
{
|
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;
|
2010-08-27 12:39:15 +02:00
|
|
|
const QByteArray &stdOut = buildProc->readAllStandardOutput();
|
2010-07-01 11:55:36 +02:00
|
|
|
if (!stdOut.isEmpty())
|
2010-07-15 10:29:38 +02:00
|
|
|
emit addOutput(QString::fromLocal8Bit(stdOut), BuildStep::NormalOutput);
|
2010-08-27 12:39:15 +02:00
|
|
|
const QByteArray &errorOut = buildProc->readAllStandardError();
|
2010-07-01 11:55:36 +02:00
|
|
|
if (!errorOut.isEmpty()) {
|
2010-07-15 10:29:38 +02:00
|
|
|
emit addOutput(QString::fromLocal8Bit(errorOut), BuildStep::ErrorOutput);
|
2010-07-01 11:55:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 17:49:07 +02:00
|
|
|
void MaemoPackageCreationStep::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();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-07 17:10:00 +02:00
|
|
|
const Qt4BuildConfiguration *MaemoPackageCreationStep::qt4BuildConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 13:39:30 +02:00
|
|
|
QString MaemoPackageCreationStep::buildDirectory() const
|
|
|
|
|
{
|
2010-07-07 14:50:37 +02:00
|
|
|
return qt4BuildConfiguration()->buildDirectory();
|
2010-06-29 13:39:30 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-07 14:50:37 +02:00
|
|
|
QString MaemoPackageCreationStep::projectName() const
|
2010-04-07 17:10:00 +02:00
|
|
|
{
|
2010-07-07 14:50:37 +02:00
|
|
|
return qt4BuildConfiguration()->qt4Target()->qt4Project()
|
|
|
|
|
->rootProjectNode()->displayName().toLower();
|
2010-04-07 17:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 12:21:35 +02:00
|
|
|
MaemoDeployStep *MaemoPackageCreationStep::deployStep() const
|
|
|
|
|
{
|
|
|
|
|
MaemoDeployStep * const deployStep
|
2010-08-02 16:01:02 +02:00
|
|
|
= MaemoGlobal::buildStep<MaemoDeployStep>(target()->activeDeployConfiguration());
|
2010-07-14 12:21:35 +02:00
|
|
|
Q_ASSERT(deployStep &&
|
|
|
|
|
"Fatal error: Maemo build configuration without deploy step.");
|
|
|
|
|
return deployStep;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-07 17:10:00 +02:00
|
|
|
bool MaemoPackageCreationStep::packagingNeeded() const
|
|
|
|
|
{
|
2010-10-27 10:50:52 +02:00
|
|
|
const QSharedPointer<MaemoDeployables> &deployables
|
|
|
|
|
= deployStep()->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) {
|
2010-10-28 10:45:01 +02:00
|
|
|
if (isFileNewerThan(deployables->deployableAt(i).localFilePath,
|
|
|
|
|
packageInfo.lastModified()))
|
2010-04-20 17:02:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 16:53:29 +02:00
|
|
|
const ProjectExplorer::Project * const project = target()->project();
|
|
|
|
|
const MaemoTemplatesManager * const templatesManager
|
|
|
|
|
= MaemoTemplatesManager::instance();
|
|
|
|
|
const QString debianPath = templatesManager->debianDirPath(project);
|
|
|
|
|
if (packageInfo.lastModified() <= QFileInfo(debianPath).lastModified())
|
|
|
|
|
return true;
|
|
|
|
|
const QStringList debianFiles = templatesManager->debianFiles(project);
|
|
|
|
|
foreach (const QString &debianFile, debianFiles) {
|
|
|
|
|
const QString absFilePath = debianPath + QLatin1Char('/') + debianFile;
|
|
|
|
|
if (packageInfo.lastModified() <= QFileInfo(absFilePath).lastModified())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:02:31 +02:00
|
|
|
return false;
|
2010-04-07 17:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-28 10:45:01 +02:00
|
|
|
bool MaemoPackageCreationStep::isFileNewerThan(const QString &filePath,
|
|
|
|
|
const QDateTime &timeStamp) const
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if (!fileInfo.exists() || fileInfo.lastModified() >= timeStamp)
|
|
|
|
|
return true;
|
|
|
|
|
if (fileInfo.isDir()) {
|
|
|
|
|
const QStringList dirContents = QDir(filePath)
|
|
|
|
|
.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
foreach (const QString &curFileName, dirContents) {
|
|
|
|
|
const QString curFilePath
|
|
|
|
|
= filePath + QLatin1Char('/') + curFileName;
|
|
|
|
|
if (isFileNewerThan(curFilePath, timeStamp))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-15 12:47:02 +02:00
|
|
|
QString MaemoPackageCreationStep::packageFilePath() const
|
|
|
|
|
{
|
2010-08-03 16:27:34 +02:00
|
|
|
QString error;
|
|
|
|
|
const QString &version = versionString(&error);
|
|
|
|
|
if (version.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
return buildDirectory() % '/'
|
|
|
|
|
% packageFileName(buildConfiguration()->target()->project(), version);
|
2010-04-15 12:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-23 15:37:17 +02:00
|
|
|
bool MaemoPackageCreationStep::isPackagingEnabled() const
|
|
|
|
|
{
|
2011-01-04 14:14:12 +01:00
|
|
|
return m_packagingEnabled
|
|
|
|
|
|| !MaemoGlobal::allowsPackagingDisabling(qt4BuildConfiguration()->qtVersion());
|
2010-08-23 15:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-03 16:27:34 +02:00
|
|
|
QString MaemoPackageCreationStep::versionString(QString *error) const
|
2010-04-14 14:45:04 +02:00
|
|
|
{
|
2010-08-03 16:27:34 +02:00
|
|
|
return MaemoTemplatesManager::instance()
|
|
|
|
|
->version(buildConfiguration()->target()->project(), error);
|
|
|
|
|
|
2010-06-28 11:59:36 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-03 16:27:34 +02:00
|
|
|
bool MaemoPackageCreationStep::setVersionString(const QString &version,
|
|
|
|
|
QString *error)
|
2010-06-28 11:59:36 +02:00
|
|
|
{
|
2010-08-03 16:27:34 +02:00
|
|
|
const bool success = MaemoTemplatesManager::instance()
|
|
|
|
|
->setVersion(buildConfiguration()->target()->project(), version, error);
|
|
|
|
|
if (success)
|
|
|
|
|
emit packageFilePathChanged();
|
|
|
|
|
return success;
|
2010-04-14 14:45:04 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-03 16:27:34 +02:00
|
|
|
QString MaemoPackageCreationStep::nativePath(const QFile &file)
|
2010-04-15 14:46:15 +02:00
|
|
|
{
|
|
|
|
|
return QDir::toNativeSeparators(QFileInfo(file).filePath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoPackageCreationStep::raiseError(const QString &shortMsg,
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-03 16:27:34 +02:00
|
|
|
bool MaemoPackageCreationStep::preparePackagingProcess(QProcess *proc,
|
2010-11-02 16:15:56 +01:00
|
|
|
const Qt4BuildConfiguration *bc, const QString &workingDir, QString *error)
|
2010-08-03 16:27:34 +02:00
|
|
|
{
|
2011-01-04 14:14:12 +01:00
|
|
|
const QString targetRoot = MaemoGlobal::targetRoot(bc->qtVersion());
|
|
|
|
|
QFile configFile(targetRoot % QLatin1String("/config.sh"));
|
2010-08-03 16:27:34 +02:00
|
|
|
if (!configFile.open(QIODevice::ReadOnly)) {
|
|
|
|
|
*error = tr("Cannot open MADDE config file '%1'.")
|
|
|
|
|
.arg(nativePath(configFile));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-17 11:09:40 +01:00
|
|
|
Utils::Environment env = bc->environment();
|
2010-08-03 16:27:34 +02:00
|
|
|
const QString &path
|
2011-01-04 14:14:12 +01:00
|
|
|
= QDir::toNativeSeparators(MaemoGlobal::maddeRoot(bc->qtVersion())
|
|
|
|
|
+ QLatin1Char('/'));
|
2010-08-03 16:27:34 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2010-11-17 11:09:40 +01:00
|
|
|
env.prependOrSetPath(path % QLatin1String("bin"));
|
2010-08-03 16:27:34 +02:00
|
|
|
#endif
|
2011-01-04 14:14:12 +01:00
|
|
|
env.prependOrSetPath(targetRoot % QLatin1String("/bin"));
|
2010-11-17 11:09:40 +01:00
|
|
|
env.prependOrSetPath(path % QLatin1String("madbin"));
|
2010-08-03 16:27:34 +02:00
|
|
|
|
2010-11-02 16:15:56 +01:00
|
|
|
if (bc->qmakeBuildConfiguration() & QtVersion::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-08-03 16:27:34 +02:00
|
|
|
QString perlLib
|
|
|
|
|
= QDir::fromNativeSeparators(path % QLatin1String("madlib/perl5"));
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
perlLib = perlLib.remove(QLatin1Char(':'));
|
|
|
|
|
perlLib = perlLib.prepend(QLatin1Char('/'));
|
|
|
|
|
#endif
|
2010-11-17 11:09:40 +01:00
|
|
|
env.set(QLatin1String("PERL5LIB"), perlLib);
|
|
|
|
|
env.set(QLatin1String("PWD"), workingDir);
|
2010-08-03 16:27:34 +02:00
|
|
|
|
|
|
|
|
const QRegExp envPattern(QLatin1String("([^=]+)=[\"']?([^;\"']+)[\"']? ;.*"));
|
|
|
|
|
QByteArray line;
|
|
|
|
|
do {
|
|
|
|
|
line = configFile.readLine(200);
|
|
|
|
|
if (envPattern.exactMatch(line))
|
2010-11-17 11:09:40 +01:00
|
|
|
env.set(envPattern.cap(1), envPattern.cap(2));
|
2010-08-03 16:27:34 +02:00
|
|
|
} while (!line.isEmpty());
|
|
|
|
|
|
2010-11-17 11:09:40 +01:00
|
|
|
proc->setEnvironment(env.toStringList());
|
2010-08-03 16:27:34 +02:00
|
|
|
proc->setWorkingDirectory(workingDir);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 14:14:12 +01:00
|
|
|
QString MaemoPackageCreationStep::packagingCommand(const Qt4BuildConfiguration *bc,
|
2010-08-03 16:27:34 +02:00
|
|
|
const QString &commandName)
|
|
|
|
|
{
|
|
|
|
|
QString perl;
|
2011-01-04 15:56:28 +01:00
|
|
|
const QString maddeRoot = MaemoGlobal::maddeRoot(bc->qtVersion());
|
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
|
|
|
}
|
|
|
|
|
|
2010-08-06 12:57:01 +02:00
|
|
|
void MaemoPackageCreationStep::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.\n"
|
|
|
|
|
"They 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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoPackageCreationStep::packageName(const ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
QString packageName = project->displayName().toLower();
|
|
|
|
|
const QRegExp legalLetter(QLatin1String("[a-z0-9+-.]"), Qt::CaseSensitive,
|
|
|
|
|
QRegExp::WildcardUnix);
|
|
|
|
|
for (int i = 0; i < packageName.length(); ++i) {
|
|
|
|
|
if (!legalLetter.exactMatch(packageName.mid(i, 1)))
|
|
|
|
|
packageName[i] = QLatin1Char('-');
|
|
|
|
|
}
|
|
|
|
|
return packageName;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-03 16:27:34 +02:00
|
|
|
QString MaemoPackageCreationStep::packageFileName(const ProjectExplorer::Project *project,
|
|
|
|
|
const QString &version)
|
|
|
|
|
{
|
2010-08-06 12:57:01 +02:00
|
|
|
return packageName(project) % QLatin1Char('_') % version
|
2010-08-03 16:27:34 +02:00
|
|
|
% QLatin1String("_armel.deb");
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 15:51:48 +01:00
|
|
|
void MaemoPackageCreationStep::updateDesktopFiles(const QString &rulesFilePath)
|
2010-09-23 15:01:19 +02:00
|
|
|
{
|
|
|
|
|
QFile rulesFile(rulesFilePath);
|
2010-12-08 10:57:21 +01:00
|
|
|
rulesFile.setPermissions(rulesFile.permissions() | QFile::ExeUser);
|
2010-09-23 15:01:19 +02:00
|
|
|
if (!rulesFile.open(QIODevice::ReadWrite)) {
|
|
|
|
|
qWarning("Cannot open rules file for Maemo6 icon path adaptation.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QByteArray content = rulesFile.readAll();
|
|
|
|
|
const int makeInstallLine = content.indexOf("\t$(MAKE) INSTALL_ROOT");
|
|
|
|
|
if (makeInstallLine == -1)
|
|
|
|
|
return;
|
|
|
|
|
const int makeInstallEol = content.indexOf('\n', makeInstallLine);
|
|
|
|
|
if (makeInstallEol == -1)
|
|
|
|
|
return;
|
2010-09-27 14:54:08 +02:00
|
|
|
QString desktopFileDir = QFileInfo(rulesFile).dir().path()
|
2010-09-23 15:01:19 +02:00
|
|
|
+ QLatin1Char('/') + projectName()
|
2010-09-27 14:54:08 +02:00
|
|
|
+ QLatin1String("/usr/share/applications/");
|
2011-01-04 14:14:12 +01:00
|
|
|
const MaemoGlobal::MaemoVersion version
|
|
|
|
|
= MaemoGlobal::version(qt4BuildConfiguration()->qtVersion());
|
|
|
|
|
if (version == MaemoGlobal::Maemo5)
|
2010-11-24 15:51:48 +01:00
|
|
|
desktopFileDir += QLatin1String("hildon/");
|
2010-09-23 15:01:19 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2010-09-27 14:54:08 +02:00
|
|
|
desktopFileDir.remove(QLatin1Char(':'));
|
|
|
|
|
desktopFileDir.prepend(QLatin1Char('/'));
|
2010-09-23 15:01:19 +02:00
|
|
|
#endif
|
2010-11-26 10:41:39 +01:00
|
|
|
int insertPos = makeInstallEol + 1;
|
2010-11-26 09:45:10 +01:00
|
|
|
for (int i = 0; i < deployStep()->deployables()->modelCount(); ++i) {
|
|
|
|
|
const MaemoDeployableListModel * const model
|
|
|
|
|
= deployStep()->deployables()->modelAt(i);
|
2010-11-26 09:56:05 +01:00
|
|
|
if (!model->hasDesktopFile())
|
2010-11-26 09:45:10 +01:00
|
|
|
continue;
|
2011-01-04 14:14:12 +01:00
|
|
|
if (version == MaemoGlobal::Maemo6) {
|
2010-11-24 15:51:48 +01:00
|
|
|
addWorkaroundForHarmattanBug(content, insertPos,
|
2010-11-26 10:37:32 +01:00
|
|
|
model, desktopFileDir);
|
2010-11-24 15:51:48 +01:00
|
|
|
}
|
2010-11-26 09:45:10 +01:00
|
|
|
const QString executableFilePath = model->remoteExecutableFilePath();
|
2010-11-24 15:51:48 +01:00
|
|
|
if (executableFilePath.isEmpty()) {
|
|
|
|
|
qDebug("%s: Skipping subproject %s with missing deployment information.",
|
2010-11-26 09:45:10 +01:00
|
|
|
Q_FUNC_INFO, qPrintable(model->proFilePath()));
|
2010-11-24 15:51:48 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const QByteArray lineBefore("Exec=.*");
|
|
|
|
|
const QByteArray lineAfter("Exec=" + executableFilePath.toUtf8());
|
2010-11-26 10:37:32 +01:00
|
|
|
const QString desktopFilePath = desktopFileDir
|
|
|
|
|
+ model->applicationName() + QLatin1String(".desktop");
|
2010-11-24 15:51:48 +01:00
|
|
|
addSedCmdToRulesFile(content, insertPos, desktopFilePath, lineBefore,
|
|
|
|
|
lineAfter);
|
2010-09-27 14:54:08 +02:00
|
|
|
}
|
2010-09-23 15:01:19 +02:00
|
|
|
rulesFile.resize(0);
|
|
|
|
|
rulesFile.write(content);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 15:51:48 +01:00
|
|
|
void MaemoPackageCreationStep::addWorkaroundForHarmattanBug(QByteArray &rulesFileContent,
|
2010-11-26 10:37:32 +01:00
|
|
|
int &insertPos, const MaemoDeployableListModel *model,
|
|
|
|
|
const QString &desktopFileDir)
|
2010-11-24 15:51:48 +01:00
|
|
|
{
|
2010-11-26 10:37:32 +01:00
|
|
|
const QString iconFilePath = model->remoteIconFilePath();
|
|
|
|
|
if (iconFilePath.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
const QByteArray lineBefore("^Icon=.*");
|
|
|
|
|
const QByteArray lineAfter("Icon=" + iconFilePath.toUtf8());
|
2010-11-24 15:51:48 +01:00
|
|
|
const QString desktopFilePath
|
2010-11-26 10:37:32 +01:00
|
|
|
= desktopFileDir + model->applicationName() + QLatin1String(".desktop");
|
2010-11-24 15:51:48 +01:00
|
|
|
addSedCmdToRulesFile(rulesFileContent, insertPos, desktopFilePath,
|
|
|
|
|
lineBefore, lineAfter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoPackageCreationStep::addSedCmdToRulesFile(QByteArray &rulesFileContent,
|
|
|
|
|
int &insertPos, const QString &desktopFilePath, const QByteArray &oldString,
|
|
|
|
|
const QByteArray &newString)
|
|
|
|
|
{
|
|
|
|
|
const QString tmpFilePath = desktopFilePath + QLatin1String(".sed");
|
|
|
|
|
const QByteArray sedCmd = "\tsed 's:" + oldString + ':' + newString
|
|
|
|
|
+ ":' " + desktopFilePath.toLocal8Bit() + " > "
|
|
|
|
|
+ tmpFilePath.toLocal8Bit() + " || echo -n\n";
|
|
|
|
|
const QByteArray mvCmd = "\tmv " + tmpFilePath.toLocal8Bit() + ' '
|
|
|
|
|
+ desktopFilePath.toLocal8Bit() + " || echo -n\n";
|
|
|
|
|
rulesFileContent.insert(insertPos, sedCmd);
|
|
|
|
|
insertPos += sedCmd.length();
|
|
|
|
|
rulesFileContent.insert(insertPos, mvCmd);
|
|
|
|
|
insertPos += mvCmd.length();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-06 16:56:47 +02:00
|
|
|
const QLatin1String MaemoPackageCreationStep::CreatePackageId("Qt4ProjectManager.MaemoPackageCreationStep");
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|