1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "tarpackagedeploystep.h"
#include "abstractremotelinuxdeploystep.h"
#include "remotelinux_constants.h"
#include "remotelinuxtr.h"
#include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/devicesupport/filetransfer.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcprocess.h>
#include <utils/processinterface.h>
using namespace ProjectExplorer;
using namespace Tasking;
using namespace Utils;
namespace RemoteLinux::Internal {
// TarPackageDeployStep
class TarPackageDeployStep : public AbstractRemoteLinuxDeployStep
{
public:
TarPackageDeployStep(BuildStepList *bsl, Id id)
: AbstractRemoteLinuxDeployStep(bsl, id)
{
setWidgetExpandedByDefault(false);
setInternalInitializer([this]() -> Result<> {
const BuildStep *tarCreationStep = nullptr;
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
if (step == this)
break;
if (step->id() == Constants::TarPackageCreationStepId) {
tarCreationStep = step;
break;
}
}
if (!tarCreationStep)
return make_unexpected(Tr::tr("No tarball creation step found."));
m_packageFilePath =
FilePath::fromVariant(tarCreationStep->data(Constants::TarPackageFilePathId));
return isDeploymentPossible();
});
}
private:
QString remoteFilePath() const;
GroupItem deployRecipe() final;
GroupItem uploadTask();
GroupItem installTask();
FilePath m_packageFilePath;
};
QString TarPackageDeployStep::remoteFilePath() const
{
return QLatin1String("/tmp/") + m_packageFilePath.fileName();
}
GroupItem TarPackageDeployStep::uploadTask()
{
const auto onSetup = [this](FileTransfer &transfer) {
const FilesToTransfer files {{m_packageFilePath,
deviceConfiguration()->filePath(remoteFilePath())}};
transfer.setFilesToTransfer(files);
connect(&transfer, &FileTransfer::progress, this, &TarPackageDeployStep::addProgressMessage);
addProgressMessage(Tr::tr("Uploading package to device..."));
};
const auto onDone = [this](const FileTransfer &transfer, DoneWith result) {
if (result == DoneWith::Success)
addProgressMessage(Tr::tr("Successfully uploaded package file."));
else
addErrorMessage(transfer.resultData().m_errorString);
};
return FileTransferTask(onSetup, onDone);
}
GroupItem TarPackageDeployStep::installTask()
{
const auto onSetup = [this](Process &process) {
const QString cmdLine = QLatin1String("cd / && tar xvf ") + remoteFilePath()
+ " && (rm " + remoteFilePath() + " || :)";
process.setCommand({deviceConfiguration()->filePath("/bin/sh"), {"-c", cmdLine}});
Process *proc = &process;
connect(proc, &Process::readyReadStandardOutput, this, [this, proc] {
handleStdOutData(proc->readAllStandardOutput());
});
connect(proc, &Process::readyReadStandardError, this, [this, proc] {
handleStdErrData(proc->readAllStandardError());
});
addProgressMessage(Tr::tr("Installing package to device..."));
};
const auto onDone = [this](const Process &process, DoneWith result) {
if (result == DoneWith::Success) {
saveDeploymentTimeStamp(DeployableFile(m_packageFilePath, {}), {});
addProgressMessage(Tr::tr("Successfully installed package file."));
return;
}
addErrorMessage(Tr::tr("Installing package failed.") + process.errorString());
};
return ProcessTask(onSetup, onDone);
}
GroupItem TarPackageDeployStep::deployRecipe()
{
const auto onSetup = [this] {
if (hasLocalFileChanged(DeployableFile(m_packageFilePath, {})))
return SetupResult::Continue;
addSkipDeploymentMessage();
return SetupResult::StopWithSuccess;
};
return Group { onGroupSetup(onSetup), uploadTask(), installTask() };
}
// TarPackageDeployStepFactory
class TarPackageDeployStepFactory final : public BuildStepFactory
{
public:
TarPackageDeployStepFactory()
{
registerStep<TarPackageDeployStep>(Constants::TarPackageDeployStepId);
setDisplayName(Tr::tr("Deploy tarball via SFTP upload"));
setSupportedConfiguration(RemoteLinux::Constants::DeployToGenericLinux);
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
}
};
void setupTarPackageDeployStep()
{
static TarPackageDeployStepFactory theTarPackageDeployStepFactory;
}
} // RemoteLinux::Internal
|