2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-15 16:57:25 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-07-15 16:57:25 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-15 16:57:25 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-07-15 16:57:25 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-07-15 16:57:25 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
#include "tarpackagecreationstep.h"
|
|
|
|
|
|
2020-09-16 12:08:11 +02:00
|
|
|
#include "remotelinux_constants.h"
|
|
|
|
|
|
2016-12-25 12:31:12 -05:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2012-08-22 16:52:38 +02:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
2011-07-15 16:57:25 +02:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2019-08-09 13:55:15 +02:00
|
|
|
|
2016-12-25 12:31:12 -05:00
|
|
|
#include <ssh/sshconnection.h>
|
|
|
|
|
#include <ssh/sshconnectionmanager.h>
|
2011-07-15 16:57:25 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
2011-07-15 16:57:25 +02:00
|
|
|
|
2012-09-20 14:25:01 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace {
|
2013-09-16 15:52:25 +02:00
|
|
|
const char IgnoreMissingFilesKey[] = "RemoteLinux.TarPackageCreationStep.IgnoreMissingFiles";
|
2016-12-25 12:31:12 -05:00
|
|
|
const char IncrementalDeploymentKey[] = "RemoteLinux.TarPackageCreationStep.IncrementalDeployment";
|
2011-07-15 16:57:25 +02:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
TarPackageCreationStep::TarPackageCreationStep(BuildStepList *bsl, Utils::Id id)
|
2019-12-20 17:05:30 +01:00
|
|
|
: AbstractPackagingStep(bsl, id)
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
|
|
|
|
setDefaultDisplayName(displayName());
|
2018-10-17 09:14:51 +02:00
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
m_ignoreMissingFilesAspect = addAspect<BoolAspect>();
|
2019-11-26 17:11:01 +01:00
|
|
|
m_ignoreMissingFilesAspect->setLabel(tr("Ignore missing files"),
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::LabelPlacement::AtCheckBox);
|
2018-10-17 09:14:51 +02:00
|
|
|
m_ignoreMissingFilesAspect->setSettingsKey(IgnoreMissingFilesKey);
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
m_incrementalDeploymentAspect = addAspect<BoolAspect>();
|
2019-11-26 17:11:01 +01:00
|
|
|
m_incrementalDeploymentAspect->setLabel(tr("Package modified files only"),
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::LabelPlacement::AtCheckBox);
|
2018-10-17 09:14:51 +02:00
|
|
|
m_incrementalDeploymentAspect->setSettingsKey(IncrementalDeploymentKey);
|
2019-06-25 16:53:40 +02:00
|
|
|
|
|
|
|
|
setSummaryUpdater([this] {
|
|
|
|
|
QString path = packageFilePath();
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return QString("<font color=\"red\">" + tr("Tarball creation not possible.")
|
|
|
|
|
+ "</font>");
|
|
|
|
|
return QString("<b>" + tr("Create tarball:") + "</b> " + path);
|
|
|
|
|
});
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:31:44 +01:00
|
|
|
bool TarPackageCreationStep::init()
|
2011-10-13 18:53:49 +02:00
|
|
|
{
|
2019-01-10 15:31:44 +01:00
|
|
|
if (!AbstractPackagingStep::init())
|
2011-10-13 18:53:49 +02:00
|
|
|
return false;
|
2016-12-25 12:31:12 -05:00
|
|
|
|
2011-10-13 18:53:49 +02:00
|
|
|
m_packagingNeeded = isPackagingNeeded();
|
2016-12-25 12:31:12 -05:00
|
|
|
|
2011-10-13 18:53:49 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
void TarPackageCreationStep::doRun()
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
runInThread([this] { return runImpl(); });
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-25 12:31:12 -05:00
|
|
|
void TarPackageCreationStep::addNeededDeploymentFiles(
|
|
|
|
|
const ProjectExplorer::DeployableFile &deployable,
|
|
|
|
|
const ProjectExplorer::Kit *kit)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fileInfo = deployable.localFilePath().toFileInfo();
|
|
|
|
|
if (!fileInfo.isDir()) {
|
2018-10-11 11:08:50 +02:00
|
|
|
if (m_deployTimes.hasLocalFileChanged(deployable, kit))
|
2016-12-25 12:31:12 -05:00
|
|
|
m_files << deployable;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList files = QDir(deployable.localFilePath().toString())
|
|
|
|
|
.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
|
|
if (files.isEmpty()) {
|
|
|
|
|
m_files << deployable;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const QString &fileName : files) {
|
2019-05-17 12:32:05 +02:00
|
|
|
const QString localFilePath = deployable.localFilePath().pathAppended(fileName).toString();
|
2016-12-25 12:31:12 -05:00
|
|
|
|
|
|
|
|
const QString remoteDir = deployable.remoteDirectory() + '/' + fileInfo.fileName();
|
|
|
|
|
|
|
|
|
|
// Recurse through the subdirectories
|
|
|
|
|
addNeededDeploymentFiles(DeployableFile(localFilePath, remoteDir), kit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
bool TarPackageCreationStep::doPackage()
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(tr("Creating tarball..."), OutputFormat::NormalMessage);
|
2011-10-13 18:53:49 +02:00
|
|
|
if (!m_packagingNeeded) {
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(tr("Tarball up to date, skipping packaging."), OutputFormat::NormalMessage);
|
2011-07-15 16:57:25 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Optimization: Only package changed files
|
2011-10-13 18:53:49 +02:00
|
|
|
QFile tarFile(cachedPackageFilePath());
|
2011-07-15 16:57:25 +02:00
|
|
|
|
|
|
|
|
if (!tarFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
|
|
|
|
raiseError(tr("Error: tar file %1 cannot be opened (%2).")
|
2011-10-13 18:53:49 +02:00
|
|
|
.arg(QDir::toNativeSeparators(cachedPackageFilePath()), tarFile.errorString()));
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-13 18:53:49 +02:00
|
|
|
foreach (const DeployableFile &d, m_files) {
|
2012-08-22 16:52:38 +02:00
|
|
|
if (d.remoteDirectory().isEmpty()) {
|
2014-04-17 14:09:47 +02:00
|
|
|
emit addOutput(tr("No remote path specified for file \"%1\", skipping.")
|
2017-01-12 10:59:12 +01:00
|
|
|
.arg(d.localFilePath().toUserOutput()), OutputFormat::ErrorMessage);
|
2011-10-24 17:58:53 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2012-08-22 16:52:38 +02:00
|
|
|
QFileInfo fileInfo = d.localFilePath().toFileInfo();
|
|
|
|
|
if (!appendFile(tarFile, fileInfo, d.remoteDirectory() + QLatin1Char('/')
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
+ fileInfo.fileName())) {
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QByteArray eofIndicator(2*sizeof(TarFileHeader), 0);
|
|
|
|
|
if (tarFile.write(eofIndicator) != eofIndicator.length()) {
|
2014-04-17 14:09:47 +02:00
|
|
|
raiseError(tr("Error writing tar file \"%1\": %2.")
|
2011-07-15 16:57:25 +02:00
|
|
|
.arg(QDir::toNativeSeparators(tarFile.fileName()), tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TarPackageCreationStep::appendFile(QFile &tarFile, const QFileInfo &fileInfo,
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
const QString &remoteFilePath)
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
|
|
|
|
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;
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
if (!appendFile(tarFile, QFileInfo(thisLocalFilePath), thisRemoteFilePath))
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString nativePath = QDir::toNativeSeparators(fileInfo.filePath());
|
|
|
|
|
QFile file(fileInfo.filePath());
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
2014-04-17 14:09:47 +02:00
|
|
|
const QString message = tr("Error reading file \"%1\": %2.")
|
2013-09-16 15:52:25 +02:00
|
|
|
.arg(nativePath, file.errorString());
|
2018-10-17 09:14:51 +02:00
|
|
|
if (m_ignoreMissingFilesAspect->value()) {
|
2013-09-16 15:52:25 +02:00
|
|
|
raiseWarning(message);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
raiseError(message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int chunkSize = 1024*1024;
|
|
|
|
|
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(tr("Adding file \"%1\" to tarball...").arg(nativePath),
|
|
|
|
|
OutputFormat::NormalMessage);
|
2011-07-15 16:57:25 +02:00
|
|
|
|
|
|
|
|
// TODO: Wasteful. Work with fixed-size buffer.
|
2013-08-09 14:05:13 +02:00
|
|
|
while (!file.atEnd() && file.error() == QFile::NoError && tarFile.error() == QFile::NoError) {
|
2011-07-15 16:57:25 +02:00
|
|
|
const QByteArray data = file.read(chunkSize);
|
|
|
|
|
tarFile.write(data);
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
if (isCanceled())
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (file.error() != QFile::NoError) {
|
2014-04-17 14:09:47 +02:00
|
|
|
raiseError(tr("Error reading file \"%1\": %2.").arg(nativePath, file.errorString()));
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int blockModulo = file.size() % TarBlockSize;
|
|
|
|
|
if (blockModulo != 0)
|
|
|
|
|
tarFile.write(QByteArray(TarBlockSize - blockModulo, 0));
|
|
|
|
|
|
|
|
|
|
if (tarFile.error() != QFile::NoError) {
|
2014-04-17 14:09:47 +02:00
|
|
|
raiseError(tr("Error writing tar file \"%1\": %2.")
|
2011-07-15 16:57:25 +02:00
|
|
|
.arg(QDir::toNativeSeparators(tarFile.fileName()), tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 14:37:24 +02:00
|
|
|
static bool setFilePath(TarFileHeader &header, const QByteArray &filePath)
|
|
|
|
|
{
|
|
|
|
|
if (filePath.length() <= int(sizeof header.fileName)) {
|
|
|
|
|
std::memcpy(&header.fileName, filePath.data(), filePath.length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
int sepIndex = filePath.indexOf('/');
|
|
|
|
|
while (sepIndex != -1) {
|
|
|
|
|
const int fileNamePart = filePath.length() - sepIndex;
|
|
|
|
|
if (sepIndex <= int(sizeof header.fileNamePrefix)
|
|
|
|
|
&& fileNamePart <= int(sizeof header.fileName)) {
|
|
|
|
|
std::memcpy(&header.fileNamePrefix, filePath.data(), sepIndex);
|
|
|
|
|
std::memcpy(&header.fileName, filePath.data() + sepIndex + 1, fileNamePart);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
sepIndex = filePath.indexOf('/', sepIndex + 1);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
bool TarPackageCreationStep::writeHeader(QFile &tarFile, const QFileInfo &fileInfo,
|
|
|
|
|
const QString &remoteFilePath)
|
|
|
|
|
{
|
|
|
|
|
TarFileHeader header;
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memset(&header, '\0', sizeof header);
|
2019-08-08 14:37:24 +02:00
|
|
|
if (!setFilePath(header, remoteFilePath.toUtf8())) {
|
|
|
|
|
raiseError(tr("Cannot add file \"%1\" to tar-archive: path too long.").arg(remoteFilePath));
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
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));
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray permissionString = QString::fromLatin1("%1").arg(permissions,
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.fileMode - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.fileMode, permissionString.data(), permissionString.length());
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray uidString = QString::fromLatin1("%1").arg(fileInfo.ownerId(),
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.uid - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.uid, uidString.data(), uidString.length());
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray gidString = QString::fromLatin1("%1").arg(fileInfo.groupId(),
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.gid - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.gid, gidString.data(), gidString.length());
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray sizeString = QString::fromLatin1("%1").arg(fileInfo.size(),
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.length - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.length, sizeString.data(), sizeString.length());
|
2018-09-21 02:09:11 +03:00
|
|
|
const QByteArray mtimeString = QString::fromLatin1("%1").arg(
|
|
|
|
|
fileInfo.lastModified().toSecsSinceEpoch(),
|
|
|
|
|
sizeof header.mtime - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.mtime, mtimeString.data(), mtimeString.length());
|
2011-07-15 16:57:25 +02:00
|
|
|
if (fileInfo.isDir())
|
|
|
|
|
header.typeflag = '5';
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.magic, "ustar", sizeof "ustar");
|
|
|
|
|
std::memcpy(&header.version, "00", 2);
|
2011-07-15 16:57:25 +02:00
|
|
|
const QByteArray &owner = fileInfo.owner().toUtf8();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.uname, owner.data(), qMin<int>(owner.length(), sizeof header.uname - 1));
|
2011-07-15 16:57:25 +02:00
|
|
|
const QByteArray &group = fileInfo.group().toUtf8();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.gname, group.data(), qMin<int>(group.length(), sizeof header.gname - 1));
|
|
|
|
|
std::memset(&header.chksum, ' ', sizeof header.chksum);
|
2011-07-15 16:57:25 +02:00
|
|
|
quint64 checksum = 0;
|
|
|
|
|
for (size_t i = 0; i < sizeof header; ++i)
|
|
|
|
|
checksum += reinterpret_cast<char *>(&header)[i];
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray checksumString = QString::fromLatin1("%1").arg(checksum,
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.chksum - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.chksum, checksumString.data(), checksumString.length());
|
2011-07-15 16:57:25 +02:00
|
|
|
header.chksum[sizeof header.chksum-1] = 0;
|
|
|
|
|
if (!tarFile.write(reinterpret_cast<char *>(&header), sizeof header)) {
|
2014-04-17 14:09:47 +02:00
|
|
|
raiseError(tr("Error writing tar file \"%1\": %2")
|
2011-10-13 18:53:49 +02:00
|
|
|
.arg(QDir::toNativeSeparators(cachedPackageFilePath()), tarFile.errorString()));
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-25 12:31:12 -05:00
|
|
|
void TarPackageCreationStep::deployFinished(bool success)
|
|
|
|
|
{
|
|
|
|
|
disconnect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
|
|
|
|
this, &TarPackageCreationStep::deployFinished);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const Kit *kit = target()->kit();
|
|
|
|
|
|
|
|
|
|
// Store files that have been tar'd and successfully deployed
|
|
|
|
|
const auto files = m_files;
|
|
|
|
|
for (const DeployableFile &file : files)
|
2018-10-11 11:08:50 +02:00
|
|
|
m_deployTimes.saveDeploymentTimeStamp(file, kit, QDateTime());
|
2016-12-25 12:31:12 -05:00
|
|
|
}
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
QString TarPackageCreationStep::packageFileName() const
|
|
|
|
|
{
|
2011-10-21 13:06:26 +00:00
|
|
|
return project()->displayName() + QLatin1String(".tar");
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
bool TarPackageCreationStep::runImpl()
|
|
|
|
|
{
|
|
|
|
|
setPackagingStarted();
|
|
|
|
|
|
|
|
|
|
const QList<DeployableFile> &files = target()->deploymentData().allFiles();
|
|
|
|
|
|
|
|
|
|
if (m_incrementalDeploymentAspect->value()) {
|
|
|
|
|
m_files.clear();
|
|
|
|
|
for (const DeployableFile &file : files)
|
2020-09-07 15:56:18 +02:00
|
|
|
addNeededDeploymentFiles(file, kit());
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
} else {
|
|
|
|
|
m_files = files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool success = doPackage();
|
|
|
|
|
|
|
|
|
|
setPackagingFinished(success);
|
|
|
|
|
if (success)
|
|
|
|
|
emit addOutput(tr("Packaging finished successfully."), OutputFormat::NormalMessage);
|
|
|
|
|
else
|
|
|
|
|
emit addOutput(tr("Packaging failed."), OutputFormat::ErrorMessage);
|
|
|
|
|
|
|
|
|
|
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
|
|
|
|
this, &TarPackageCreationStep::deployFinished);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 15:52:25 +02:00
|
|
|
bool TarPackageCreationStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
if (!AbstractPackagingStep::fromMap(map))
|
|
|
|
|
return false;
|
2016-12-25 12:31:12 -05:00
|
|
|
m_deployTimes.importDeployTimes(map);
|
2013-09-16 15:52:25 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap TarPackageCreationStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = AbstractPackagingStep::toMap();
|
2020-08-20 11:25:35 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
|
map.insert(m_deployTimes.exportDeployTimes());
|
|
|
|
|
#else
|
2016-12-25 12:31:12 -05:00
|
|
|
map.unite(m_deployTimes.exportDeployTimes());
|
2020-08-20 11:25:35 +02:00
|
|
|
#endif
|
2013-09-16 15:52:25 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id TarPackageCreationStep::stepId()
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
2020-09-16 12:08:11 +02:00
|
|
|
return Constants::TarPackageCreationStepId;
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TarPackageCreationStep::displayName()
|
|
|
|
|
{
|
|
|
|
|
return tr("Create tarball");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|