forked from qt-creator/qt-creator
AbstractRemoteLinuxDeployStep: Get rid of CheckResult
Use expected_str<void> instead. Change-Id: I93518da9ba9393a3db84aefeb9edd164cd830d42 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -30,7 +30,7 @@ class AbstractRemoteLinuxDeployStepPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool hasError;
|
bool hasError;
|
||||||
std::function<CheckResult()> internalInit;
|
std::function<expected_str<void>()> internalInit;
|
||||||
std::function<void()> runPreparer;
|
std::function<void()> runPreparer;
|
||||||
|
|
||||||
DeploymentTimeInfo deployTimes;
|
DeploymentTimeInfo deployTimes;
|
||||||
@@ -73,14 +73,15 @@ bool AbstractRemoteLinuxDeployStep::hasRemoteFileChanged(
|
|||||||
return d->deployTimes.hasRemoteFileChanged(deployableFile, kit(), remoteTimestamp);
|
return d->deployTimes.hasRemoteFileChanged(deployableFile, kit(), remoteTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckResult AbstractRemoteLinuxDeployStep::isDeploymentPossible() const
|
expected_str<void> AbstractRemoteLinuxDeployStep::isDeploymentPossible() const
|
||||||
{
|
{
|
||||||
if (!deviceConfiguration())
|
if (!deviceConfiguration())
|
||||||
return CheckResult::failure(Tr::tr("No device configuration set."));
|
return make_unexpected(Tr::tr("No device configuration set."));
|
||||||
return CheckResult::success();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractRemoteLinuxDeployStep::setInternalInitializer(const std::function<CheckResult ()> &init)
|
void AbstractRemoteLinuxDeployStep::setInternalInitializer(
|
||||||
|
const std::function<expected_str<void>()> &init)
|
||||||
{
|
{
|
||||||
d->internalInit = init;
|
d->internalInit = init;
|
||||||
}
|
}
|
||||||
@@ -108,12 +109,12 @@ QVariantMap AbstractRemoteLinuxDeployStep::toMap() const
|
|||||||
bool AbstractRemoteLinuxDeployStep::init()
|
bool AbstractRemoteLinuxDeployStep::init()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->internalInit, return false);
|
QTC_ASSERT(d->internalInit, return false);
|
||||||
const CheckResult canDeploy = d->internalInit();
|
const auto canDeploy = d->internalInit();
|
||||||
if (!canDeploy) {
|
if (!canDeploy) {
|
||||||
emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.errorMessage()),
|
emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.error()),
|
||||||
OutputFormat::ErrorMessage);
|
OutputFormat::ErrorMessage);
|
||||||
}
|
}
|
||||||
return canDeploy;
|
return bool(canDeploy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractRemoteLinuxDeployStep::doRun()
|
void AbstractRemoteLinuxDeployStep::doRun()
|
||||||
@@ -125,9 +126,9 @@ void AbstractRemoteLinuxDeployStep::doRun()
|
|||||||
|
|
||||||
QTC_ASSERT(!d->m_taskTree, return);
|
QTC_ASSERT(!d->m_taskTree, return);
|
||||||
|
|
||||||
const CheckResult check = isDeploymentPossible();
|
const auto canDeploy = isDeploymentPossible();
|
||||||
if (!check) {
|
if (!canDeploy) {
|
||||||
addErrorMessage(check.errorMessage());
|
addErrorMessage(canDeploy.error());
|
||||||
handleFinished();
|
handleFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,22 +17,6 @@ namespace RemoteLinux {
|
|||||||
|
|
||||||
namespace Internal { class AbstractRemoteLinuxDeployStepPrivate; }
|
namespace Internal { class AbstractRemoteLinuxDeployStepPrivate; }
|
||||||
|
|
||||||
class REMOTELINUX_EXPORT CheckResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static CheckResult success() { return {true, {}}; }
|
|
||||||
static CheckResult failure(const QString &error = {}) { return {false, error}; }
|
|
||||||
|
|
||||||
operator bool() const { return m_ok; }
|
|
||||||
QString errorMessage() const { return m_error; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CheckResult(bool ok, const QString &error) : m_ok(ok), m_error(error) {}
|
|
||||||
|
|
||||||
bool m_ok = false;
|
|
||||||
QString m_error;
|
|
||||||
};
|
|
||||||
|
|
||||||
class REMOTELINUX_EXPORT AbstractRemoteLinuxDeployStep : public ProjectExplorer::BuildStep
|
class REMOTELINUX_EXPORT AbstractRemoteLinuxDeployStep : public ProjectExplorer::BuildStep
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -41,7 +25,7 @@ public:
|
|||||||
|
|
||||||
ProjectExplorer::IDeviceConstPtr deviceConfiguration() const;
|
ProjectExplorer::IDeviceConstPtr deviceConfiguration() const;
|
||||||
|
|
||||||
virtual CheckResult isDeploymentPossible() const;
|
virtual Utils::expected_str<void> isDeploymentPossible() const;
|
||||||
|
|
||||||
void handleStdOutData(const QString &data);
|
void handleStdOutData(const QString &data);
|
||||||
void handleStdErrData(const QString &data);
|
void handleStdErrData(const QString &data);
|
||||||
@@ -53,7 +37,7 @@ protected:
|
|||||||
void doRun() final;
|
void doRun() final;
|
||||||
void doCancel() override;
|
void doCancel() override;
|
||||||
|
|
||||||
void setInternalInitializer(const std::function<CheckResult()> &init);
|
void setInternalInitializer(const std::function<Utils::expected_str<void>()> &init);
|
||||||
void setRunPreparer(const std::function<void()> &prep);
|
void setRunPreparer(const std::function<void()> &prep);
|
||||||
|
|
||||||
void saveDeploymentTimeStamp(const ProjectExplorer::DeployableFile &deployableFile,
|
void saveDeploymentTimeStamp(const ProjectExplorer::DeployableFile &deployableFile,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
addMacroExpander();
|
addMacroExpander();
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckResult isDeploymentPossible() const final;
|
expected_str<void> isDeploymentPossible() const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Group deployRecipe() final;
|
Group deployRecipe() final;
|
||||||
@@ -43,10 +43,10 @@ private:
|
|||||||
StringAspect commandLine{this};
|
StringAspect commandLine{this};
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckResult CustomCommandDeployStep::isDeploymentPossible() const
|
expected_str<void> CustomCommandDeployStep::isDeploymentPossible() const
|
||||||
{
|
{
|
||||||
if (commandLine().isEmpty())
|
if (commandLine().isEmpty())
|
||||||
return CheckResult::failure(Tr::tr("No command line given."));
|
return make_unexpected(Tr::tr("No command line given."));
|
||||||
|
|
||||||
return AbstractRemoteLinuxDeployStep::isDeploymentPossible();
|
return AbstractRemoteLinuxDeployStep::isDeploymentPossible();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ public:
|
|||||||
{
|
{
|
||||||
setWidgetExpandedByDefault(false);
|
setWidgetExpandedByDefault(false);
|
||||||
|
|
||||||
setInternalInitializer([this] {
|
setInternalInitializer([this]() -> expected_str<void> {
|
||||||
Target * const theTarget = target();
|
Target * const theTarget = target();
|
||||||
QTC_ASSERT(theTarget, return CheckResult::failure());
|
QTC_ASSERT(theTarget, return make_unexpected(QString()));
|
||||||
RunConfiguration * const rc = theTarget->activeRunConfiguration();
|
RunConfiguration * const rc = theTarget->activeRunConfiguration();
|
||||||
m_remoteExecutable = rc ? rc->runnable().command.executable() : FilePath();
|
m_remoteExecutable = rc ? rc->runnable().command.executable() : FilePath();
|
||||||
return CheckResult::success();
|
return {};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ public:
|
|||||||
method.addOption(Tr::tr("SFTP"), Tr::tr("Use sftp if available."));
|
method.addOption(Tr::tr("SFTP"), Tr::tr("Use sftp if available."));
|
||||||
method.addOption(Tr::tr("Generic Copy"), Tr::tr("Use generic copy, most likely to succeed."));
|
method.addOption(Tr::tr("Generic Copy"), Tr::tr("Use generic copy, most likely to succeed."));
|
||||||
|
|
||||||
setInternalInitializer([this] {
|
setInternalInitializer([this]() -> expected_str<void> {
|
||||||
if (BuildDeviceKitAspect::device(kit()) == DeviceKitAspect::device(kit())) {
|
if (BuildDeviceKitAspect::device(kit()) == DeviceKitAspect::device(kit())) {
|
||||||
// rsync transfer on the same device currently not implemented
|
// rsync transfer on the same device currently not implemented
|
||||||
// and typically not wanted.
|
// and typically not wanted.
|
||||||
return CheckResult::failure(
|
return make_unexpected(
|
||||||
Tr::tr("rsync is only supported for transfers between different devices."));
|
Tr::tr("rsync is only supported for transfers between different devices."));
|
||||||
}
|
}
|
||||||
return isDeploymentPossible();
|
return isDeploymentPossible();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
{
|
{
|
||||||
setWidgetExpandedByDefault(false);
|
setWidgetExpandedByDefault(false);
|
||||||
|
|
||||||
setInternalInitializer([this] {
|
setInternalInitializer([this]() -> expected_str<void> {
|
||||||
const BuildStep *tarCreationStep = nullptr;
|
const BuildStep *tarCreationStep = nullptr;
|
||||||
|
|
||||||
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
|
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
|
||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tarCreationStep)
|
if (!tarCreationStep)
|
||||||
return CheckResult::failure(Tr::tr("No tarball creation step found."));
|
return make_unexpected(Tr::tr("No tarball creation step found."));
|
||||||
|
|
||||||
m_packageFilePath =
|
m_packageFilePath =
|
||||||
FilePath::fromVariant(tarCreationStep->data(Constants::TarPackageFilePathId));
|
FilePath::fromVariant(tarCreationStep->data(Constants::TarPackageFilePathId));
|
||||||
|
|||||||
Reference in New Issue
Block a user