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:
Jarek Kobus
2023-07-07 11:40:12 +02:00
parent c1c62d0d9e
commit 243341df46
6 changed files with 24 additions and 39 deletions

View File

@@ -30,7 +30,7 @@ class AbstractRemoteLinuxDeployStepPrivate
{
public:
bool hasError;
std::function<CheckResult()> internalInit;
std::function<expected_str<void>()> internalInit;
std::function<void()> runPreparer;
DeploymentTimeInfo deployTimes;
@@ -73,14 +73,15 @@ bool AbstractRemoteLinuxDeployStep::hasRemoteFileChanged(
return d->deployTimes.hasRemoteFileChanged(deployableFile, kit(), remoteTimestamp);
}
CheckResult AbstractRemoteLinuxDeployStep::isDeploymentPossible() const
expected_str<void> AbstractRemoteLinuxDeployStep::isDeploymentPossible() const
{
if (!deviceConfiguration())
return CheckResult::failure(Tr::tr("No device configuration set."));
return CheckResult::success();
return make_unexpected(Tr::tr("No device configuration set."));
return {};
}
void AbstractRemoteLinuxDeployStep::setInternalInitializer(const std::function<CheckResult ()> &init)
void AbstractRemoteLinuxDeployStep::setInternalInitializer(
const std::function<expected_str<void>()> &init)
{
d->internalInit = init;
}
@@ -108,12 +109,12 @@ QVariantMap AbstractRemoteLinuxDeployStep::toMap() const
bool AbstractRemoteLinuxDeployStep::init()
{
QTC_ASSERT(d->internalInit, return false);
const CheckResult canDeploy = d->internalInit();
const auto canDeploy = d->internalInit();
if (!canDeploy) {
emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.errorMessage()),
emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.error()),
OutputFormat::ErrorMessage);
}
return canDeploy;
return bool(canDeploy);
}
void AbstractRemoteLinuxDeployStep::doRun()
@@ -125,9 +126,9 @@ void AbstractRemoteLinuxDeployStep::doRun()
QTC_ASSERT(!d->m_taskTree, return);
const CheckResult check = isDeploymentPossible();
if (!check) {
addErrorMessage(check.errorMessage());
const auto canDeploy = isDeploymentPossible();
if (!canDeploy) {
addErrorMessage(canDeploy.error());
handleFinished();
return;
}

View File

@@ -17,22 +17,6 @@ namespace RemoteLinux {
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
{
public:
@@ -41,7 +25,7 @@ public:
ProjectExplorer::IDeviceConstPtr deviceConfiguration() const;
virtual CheckResult isDeploymentPossible() const;
virtual Utils::expected_str<void> isDeploymentPossible() const;
void handleStdOutData(const QString &data);
void handleStdErrData(const QString &data);
@@ -53,7 +37,7 @@ protected:
void doRun() final;
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 saveDeploymentTimeStamp(const ProjectExplorer::DeployableFile &deployableFile,

View File

@@ -35,7 +35,7 @@ public:
addMacroExpander();
}
CheckResult isDeploymentPossible() const final;
expected_str<void> isDeploymentPossible() const final;
private:
Group deployRecipe() final;
@@ -43,10 +43,10 @@ private:
StringAspect commandLine{this};
};
CheckResult CustomCommandDeployStep::isDeploymentPossible() const
expected_str<void> CustomCommandDeployStep::isDeploymentPossible() const
{
if (commandLine().isEmpty())
return CheckResult::failure(Tr::tr("No command line given."));
return make_unexpected(Tr::tr("No command line given."));
return AbstractRemoteLinuxDeployStep::isDeploymentPossible();
}

View File

@@ -27,12 +27,12 @@ public:
{
setWidgetExpandedByDefault(false);
setInternalInitializer([this] {
setInternalInitializer([this]() -> expected_str<void> {
Target * const theTarget = target();
QTC_ASSERT(theTarget, return CheckResult::failure());
QTC_ASSERT(theTarget, return make_unexpected(QString()));
RunConfiguration * const rc = theTarget->activeRunConfiguration();
m_remoteExecutable = rc ? rc->runnable().command.executable() : FilePath();
return CheckResult::success();
return {};
});
}

View File

@@ -51,11 +51,11 @@ public:
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."));
setInternalInitializer([this] {
setInternalInitializer([this]() -> expected_str<void> {
if (BuildDeviceKitAspect::device(kit()) == DeviceKitAspect::device(kit())) {
// rsync transfer on the same device currently not implemented
// and typically not wanted.
return CheckResult::failure(
return make_unexpected(
Tr::tr("rsync is only supported for transfers between different devices."));
}
return isDeploymentPossible();

View File

@@ -31,7 +31,7 @@ public:
{
setWidgetExpandedByDefault(false);
setInternalInitializer([this] {
setInternalInitializer([this]() -> expected_str<void> {
const BuildStep *tarCreationStep = nullptr;
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
@@ -43,7 +43,7 @@ public:
}
}
if (!tarCreationStep)
return CheckResult::failure(Tr::tr("No tarball creation step found."));
return make_unexpected(Tr::tr("No tarball creation step found."));
m_packageFilePath =
FilePath::fromVariant(tarCreationStep->data(Constants::TarPackageFilePathId));