forked from qt-creator/qt-creator
TaskTree: Make it possible to invoke done handler only with DoneResult
Remove unused "const Task &" argument from done handlers. Task-number: QTCREATORBUG-29834 Change-Id: I0e69c1eba88d9fdb78de7ba1705ff3916999dc89 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -368,8 +368,8 @@ private:
|
||||
constexpr bool isVoid
|
||||
= std::is_same_v<void, std::invoke_result_t<std::decay_t<Handler>, Task &>>;
|
||||
static_assert(isDynamic || isVoid,
|
||||
"Task setup handler needs to take (Task &) as an argument (optionally) and has to "
|
||||
"return void or SetupResult. The passed handler doesn't fulfill these requirements.");
|
||||
"Task setup handler needs to take (Task &) as an argument and has to return "
|
||||
"void or SetupResult. The passed handler doesn't fulfill these requirements.");
|
||||
return [=](TaskInterface &taskInterface) {
|
||||
Adapter &adapter = static_cast<Adapter &>(taskInterface);
|
||||
if constexpr (isDynamic)
|
||||
@@ -383,37 +383,45 @@ private:
|
||||
static GroupItem::TaskDoneHandler wrapDone(Handler &&handler) {
|
||||
if constexpr (std::is_same_v<Handler, DoneFunction>)
|
||||
return {}; // When user passed {} for the done handler.
|
||||
static constexpr bool is2ArgDynamic
|
||||
static constexpr bool isBTD // stands for [B]ool, [T]ask, [D]oneWith
|
||||
= std::is_invocable_r_v<bool, std::decay_t<Handler>, const Task &, DoneWith>;
|
||||
static constexpr bool is1ArgDynamic
|
||||
static constexpr bool isBT
|
||||
= std::is_invocable_r_v<bool, std::decay_t<Handler>, const Task &>;
|
||||
static constexpr bool is0ArgDynamic
|
||||
static constexpr bool isBD
|
||||
= std::is_invocable_r_v<bool, std::decay_t<Handler>, DoneWith>;
|
||||
static constexpr bool isB
|
||||
= std::is_invocable_r_v<bool, std::decay_t<Handler>>;
|
||||
static constexpr bool is2ArgVoid
|
||||
static constexpr bool isVTD // stands for [V]oid, [T]ask, [D]oneWith
|
||||
= std::is_invocable_r_v<void, std::decay_t<Handler>, const Task &, DoneWith>;
|
||||
static constexpr bool is1ArgVoid
|
||||
static constexpr bool isVT
|
||||
= std::is_invocable_r_v<void, std::decay_t<Handler>, const Task &>;
|
||||
static constexpr bool is0ArgVoid
|
||||
static constexpr bool isVD
|
||||
= std::is_invocable_r_v<void, std::decay_t<Handler>, DoneWith>;
|
||||
static constexpr bool isV
|
||||
= std::is_invocable_r_v<void, std::decay_t<Handler>>;
|
||||
static constexpr bool isInvocable = is2ArgDynamic || is2ArgVoid
|
||||
|| is1ArgDynamic || is1ArgVoid
|
||||
|| is0ArgDynamic || is0ArgVoid;
|
||||
static constexpr bool isInvocable = isBTD || isBT || isBD || isB
|
||||
|| isVTD || isVT || isVD || isV;
|
||||
static_assert(isInvocable,
|
||||
"Task done handler needs to take (const Task &, bool) as arguments (optionally) and "
|
||||
"has to return void or bool. The passed handler doesn't fulfill these requirements.");
|
||||
"Task done handler needs to take (const Task &, DoneWith), (const Task &), "
|
||||
"(DoneWith) or (void) as arguments and has to return void or bool. "
|
||||
"The passed handler doesn't fulfill these requirements.");
|
||||
return [=](const TaskInterface &taskInterface, DoneWith result) {
|
||||
const Adapter &adapter = static_cast<const Adapter &>(taskInterface);
|
||||
if constexpr (is2ArgDynamic)
|
||||
if constexpr (isBTD)
|
||||
return std::invoke(handler, *adapter.task(), result);
|
||||
if constexpr (is1ArgDynamic)
|
||||
if constexpr (isBT)
|
||||
return std::invoke(handler, *adapter.task());
|
||||
if constexpr (is0ArgDynamic)
|
||||
if constexpr (isBD)
|
||||
return std::invoke(handler, result);
|
||||
if constexpr (isB)
|
||||
return std::invoke(handler);
|
||||
if constexpr (is2ArgVoid)
|
||||
if constexpr (isVTD)
|
||||
std::invoke(handler, *adapter.task(), result);
|
||||
else if constexpr (is1ArgVoid)
|
||||
else if constexpr (isVT)
|
||||
std::invoke(handler, *adapter.task());
|
||||
else if constexpr (is0ArgVoid)
|
||||
else if constexpr (isVD)
|
||||
std::invoke(handler, result);
|
||||
else if constexpr (isV)
|
||||
std::invoke(handler);
|
||||
return result == DoneWith::Success;
|
||||
};
|
||||
|
@@ -171,7 +171,7 @@ void AndroidSdkDownloader::downloadAndExtractSdk()
|
||||
unarchiver.setDestDir(sdkFileName.parentDir());
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onUnarchiverDone = [this, storage](const Unarchiver &, DoneWith result) {
|
||||
const auto onUnarchiverDone = [this, storage](DoneWith result) {
|
||||
if (result != DoneWith::Success) {
|
||||
logError(Tr::tr("Unarchiving error."));
|
||||
return;
|
||||
|
@@ -253,12 +253,12 @@ void AttachCoreDialog::accepted()
|
||||
AsyncTask<ResultType>{[this, copyFileAsync](auto &task) {
|
||||
task.setConcurrentCallData(copyFileAsync, coreFile());
|
||||
},
|
||||
[=](const auto &task) { d->coreFileResult = task.result(); },
|
||||
[=](const Async<ResultType> &task) { d->coreFileResult = task.result(); },
|
||||
CallDoneIf::Success},
|
||||
AsyncTask<ResultType>{[this, copyFileAsync](auto &task) {
|
||||
task.setConcurrentCallData(copyFileAsync, symbolFile());
|
||||
},
|
||||
[=](const auto &task) { d->symbolFileResult = task.result(); },
|
||||
[=](const Async<ResultType> &task) { d->symbolFileResult = task.result(); },
|
||||
CallDoneIf::Success}
|
||||
};
|
||||
|
||||
|
@@ -110,7 +110,7 @@ DiffFilesController::DiffFilesController(IDocument *document)
|
||||
|
||||
const TreeStorage<QList<std::optional<FileData>>> storage;
|
||||
|
||||
const auto setupTree = [this, storage](TaskTree &taskTree) {
|
||||
const auto onTreeSetup = [this, storage](TaskTree &taskTree) {
|
||||
QList<std::optional<FileData>> *outputList = storage.activeStorage();
|
||||
|
||||
const QList<ReloadInput> inputList = reloadInputList();
|
||||
@@ -147,7 +147,7 @@ DiffFilesController::DiffFilesController(IDocument *document)
|
||||
|
||||
const Group root = {
|
||||
Storage(storage),
|
||||
TaskTreeTask(setupTree),
|
||||
TaskTreeTask(onTreeSetup),
|
||||
onGroupDone(onTreeDone),
|
||||
onGroupError(onTreeError)
|
||||
};
|
||||
|
@@ -483,7 +483,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
updateDescription(*data);
|
||||
};
|
||||
|
||||
const auto setupFollows = [this, storage, updateDescription](TaskTree &taskTree) {
|
||||
const auto onFollowsSetup = [this, storage, updateDescription](TaskTree &taskTree) {
|
||||
ReloadStorage *data = storage.activeStorage();
|
||||
QStringList parents;
|
||||
QString errorMessage;
|
||||
@@ -536,7 +536,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
onGroupSetup(desciptionDetailsSetup),
|
||||
ProcessTask(onBranchesSetup, onBranchesDone, CallDoneIf::Success),
|
||||
ProcessTask(onPrecedesSetup, onPrecedesDone, CallDoneIf::Success),
|
||||
TaskTreeTask(setupFollows)
|
||||
TaskTreeTask(onFollowsSetup)
|
||||
}
|
||||
},
|
||||
Group {
|
||||
|
@@ -52,7 +52,7 @@ private:
|
||||
streamer.setDestination(m_target);
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onDone = [this](const FileStreamer &, DoneWith result) {
|
||||
const auto onDone = [this](DoneWith result) {
|
||||
if (result == DoneWith::Success)
|
||||
addOutput(Tr::tr("Copying finished."), OutputFormat::NormalMessage);
|
||||
else
|
||||
|
@@ -198,11 +198,11 @@ GroupItem QnxDeployQtLibrariesDialogPrivate::uploadTask()
|
||||
|
||||
GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTask(const DeployableFile &file)
|
||||
{
|
||||
const auto onSetup = [=](Process &process) {
|
||||
const auto onSetup = [this, file](Process &process) {
|
||||
process.setCommand({m_device->filePath("chmod"),
|
||||
{"a+x", Utils::ProcessArgs::quoteArgUnix(file.remoteFilePath())}});
|
||||
};
|
||||
const auto onError = [=](const Process &process) {
|
||||
const auto onError = [this, file](const Process &process) {
|
||||
const QString error = process.errorString();
|
||||
if (!error.isEmpty()) {
|
||||
emitWarningMessage(Tr::tr("Remote chmod failed for file \"%1\": %2")
|
||||
@@ -217,7 +217,7 @@ GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTask(const DeployableFile &fil
|
||||
|
||||
GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTree()
|
||||
{
|
||||
const auto setupChmodHandler = [=](TaskTree &tree) {
|
||||
const auto onSetup = [this](TaskTree &tree) {
|
||||
QList<DeployableFile> filesToChmod;
|
||||
for (const DeployableFile &file : std::as_const(m_deployableFiles)) {
|
||||
if (file.isExecutable())
|
||||
@@ -230,7 +230,7 @@ GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTree()
|
||||
}
|
||||
tree.setRecipe(chmodList);
|
||||
};
|
||||
return TaskTreeTask{setupChmodHandler};
|
||||
return TaskTreeTask(onSetup);
|
||||
}
|
||||
|
||||
Group QnxDeployQtLibrariesDialogPrivate::deployRecipe()
|
||||
|
@@ -37,7 +37,7 @@ void Slog2InfoRunner::start()
|
||||
const auto onTestSetup = [this](Process &process) {
|
||||
process.setCommand({device()->filePath("slog2info"), {}});
|
||||
};
|
||||
const auto onTestDone = [this](const Process &, DoneWith result) {
|
||||
const auto onTestDone = [this](DoneWith result) {
|
||||
if (result == DoneWith::Success) {
|
||||
m_found = true;
|
||||
return;
|
||||
|
@@ -151,7 +151,7 @@ GroupItem GenericDirectUploadStep::statTask(UploadStorage *storage,
|
||||
GroupItem GenericDirectUploadStep::statTree(const TreeStorage<UploadStorage> &storage,
|
||||
FilesToStat filesToStat, StatEndHandler statEndHandler)
|
||||
{
|
||||
const auto setupHandler = [=](TaskTree &tree) {
|
||||
const auto onSetup = [this, storage, filesToStat, statEndHandler](TaskTree &tree) {
|
||||
UploadStorage *storagePtr = storage.activeStorage();
|
||||
const QList<DeployableFile> files = filesToStat(storagePtr);
|
||||
QList<GroupItem> statList{finishAllAndDone, parallelLimit(MaxConcurrentStatCalls)};
|
||||
@@ -161,7 +161,7 @@ GroupItem GenericDirectUploadStep::statTree(const TreeStorage<UploadStorage> &st
|
||||
}
|
||||
tree.setRecipe({statList});
|
||||
};
|
||||
return TaskTreeTask(setupHandler);
|
||||
return TaskTreeTask(onSetup);
|
||||
}
|
||||
|
||||
GroupItem GenericDirectUploadStep::uploadTask(const TreeStorage<UploadStorage> &storage)
|
||||
@@ -225,7 +225,7 @@ GroupItem GenericDirectUploadStep::chmodTask(const DeployableFile &file)
|
||||
|
||||
GroupItem GenericDirectUploadStep::chmodTree(const TreeStorage<UploadStorage> &storage)
|
||||
{
|
||||
const auto setupChmodHandler = [=](TaskTree &tree) {
|
||||
const auto onSetup = [this, storage](TaskTree &tree) {
|
||||
QList<DeployableFile> filesToChmod;
|
||||
for (const DeployableFile &file : std::as_const(storage->filesToUpload)) {
|
||||
if (file.isExecutable())
|
||||
@@ -238,7 +238,7 @@ GroupItem GenericDirectUploadStep::chmodTree(const TreeStorage<UploadStorage> &s
|
||||
}
|
||||
tree.setRecipe({chmodList});
|
||||
};
|
||||
return TaskTreeTask(setupChmodHandler);
|
||||
return TaskTreeTask(onSetup);
|
||||
}
|
||||
|
||||
GroupItem GenericDirectUploadStep::deployRecipe()
|
||||
|
@@ -55,7 +55,7 @@ GroupItem KillAppStep::deployRecipe()
|
||||
.arg(m_remoteExecutable.path()));
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onDone = [this](const DeviceProcessKiller &, DoneWith result) {
|
||||
const auto onDone = [this](DoneWith result) {
|
||||
const QString message = result == DoneWith::Success ? Tr::tr("Remote application killed.")
|
||||
: Tr::tr("Failed to kill remote application. Assuming it was not running.");
|
||||
addProgressMessage(message);
|
||||
|
@@ -153,7 +153,7 @@ Tasking::GroupItem TarPackageCreationStep::runRecipe()
|
||||
async.setFutureSynchronizer(&m_synchronizer);
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onDone = [this](const Async<void> &, DoneWith result) {
|
||||
const auto onDone = [this](DoneWith result) {
|
||||
if (result != DoneWith::Success) {
|
||||
emit addOutput(Tr::tr("Packaging failed."), OutputFormat::ErrorMessage);
|
||||
return;
|
||||
|
@@ -80,14 +80,16 @@ void tst_Tasking::validConstructs()
|
||||
parallel,
|
||||
TestTask([](TaskObject &) {}, [](const TaskObject &, DoneWith) {}),
|
||||
TestTask([](TaskObject &) {}, [](const TaskObject &) {}),
|
||||
TestTask([](TaskObject &) {}, [](DoneWith) {}),
|
||||
TestTask([](TaskObject &) {}, [] {}),
|
||||
TestTask([](TaskObject &) {}, {}),
|
||||
TestTask([](TaskObject &) {}),
|
||||
TestTask({}, [](const TaskObject &, DoneWith) {}),
|
||||
TestTask({}, [](const TaskObject &) {}),
|
||||
TestTask({}, [](DoneWith) {}),
|
||||
TestTask({}, [] {}),
|
||||
TestTask({}, {}),
|
||||
TestTask({}),
|
||||
TestTask({})
|
||||
};
|
||||
|
||||
const Group group1 {
|
||||
@@ -232,7 +234,7 @@ void tst_Tasking::testTree_data()
|
||||
};
|
||||
|
||||
const auto setupDone = [storage](int taskId, bool success = true) {
|
||||
return [storage, taskId, success](const TaskObject &, DoneWith result) {
|
||||
return [storage, taskId, success](DoneWith result) {
|
||||
const Handler handler = result == DoneWith::Cancel ? Handler::Canceled
|
||||
: success ? Handler::Success : Handler::Error;
|
||||
storage->m_log.append({taskId, handler});
|
||||
|
Reference in New Issue
Block a user