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:
Jarek Kobus
2023-11-03 14:42:55 +01:00
parent 35e03499f0
commit f84e3074cd
12 changed files with 50 additions and 40 deletions

View File

@@ -368,8 +368,8 @@ private:
constexpr bool isVoid constexpr bool isVoid
= std::is_same_v<void, std::invoke_result_t<std::decay_t<Handler>, Task &>>; = std::is_same_v<void, std::invoke_result_t<std::decay_t<Handler>, Task &>>;
static_assert(isDynamic || isVoid, static_assert(isDynamic || isVoid,
"Task setup handler needs to take (Task &) as an argument (optionally) and has to " "Task setup handler needs to take (Task &) as an argument and has to return "
"return void or SetupResult. The passed handler doesn't fulfill these requirements."); "void or SetupResult. The passed handler doesn't fulfill these requirements.");
return [=](TaskInterface &taskInterface) { return [=](TaskInterface &taskInterface) {
Adapter &adapter = static_cast<Adapter &>(taskInterface); Adapter &adapter = static_cast<Adapter &>(taskInterface);
if constexpr (isDynamic) if constexpr (isDynamic)
@@ -383,37 +383,45 @@ private:
static GroupItem::TaskDoneHandler wrapDone(Handler &&handler) { static GroupItem::TaskDoneHandler wrapDone(Handler &&handler) {
if constexpr (std::is_same_v<Handler, DoneFunction>) if constexpr (std::is_same_v<Handler, DoneFunction>)
return {}; // When user passed {} for the done handler. 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>; = 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 &>; = 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>>; = 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>; = 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 &>; = 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>>; = std::is_invocable_r_v<void, std::decay_t<Handler>>;
static constexpr bool isInvocable = is2ArgDynamic || is2ArgVoid static constexpr bool isInvocable = isBTD || isBT || isBD || isB
|| is1ArgDynamic || is1ArgVoid || isVTD || isVT || isVD || isV;
|| is0ArgDynamic || is0ArgVoid;
static_assert(isInvocable, static_assert(isInvocable,
"Task done handler needs to take (const Task &, bool) as arguments (optionally) and " "Task done handler needs to take (const Task &, DoneWith), (const Task &), "
"has to return void or bool. The passed handler doesn't fulfill these requirements."); "(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) { return [=](const TaskInterface &taskInterface, DoneWith result) {
const Adapter &adapter = static_cast<const Adapter &>(taskInterface); const Adapter &adapter = static_cast<const Adapter &>(taskInterface);
if constexpr (is2ArgDynamic) if constexpr (isBTD)
return std::invoke(handler, *adapter.task(), result); return std::invoke(handler, *adapter.task(), result);
if constexpr (is1ArgDynamic) if constexpr (isBT)
return std::invoke(handler, *adapter.task()); return std::invoke(handler, *adapter.task());
if constexpr (is0ArgDynamic) if constexpr (isBD)
return std::invoke(handler, result);
if constexpr (isB)
return std::invoke(handler); return std::invoke(handler);
if constexpr (is2ArgVoid) if constexpr (isVTD)
std::invoke(handler, *adapter.task(), result); std::invoke(handler, *adapter.task(), result);
else if constexpr (is1ArgVoid) else if constexpr (isVT)
std::invoke(handler, *adapter.task()); std::invoke(handler, *adapter.task());
else if constexpr (is0ArgVoid) else if constexpr (isVD)
std::invoke(handler, result);
else if constexpr (isV)
std::invoke(handler); std::invoke(handler);
return result == DoneWith::Success; return result == DoneWith::Success;
}; };

View File

@@ -171,7 +171,7 @@ void AndroidSdkDownloader::downloadAndExtractSdk()
unarchiver.setDestDir(sdkFileName.parentDir()); unarchiver.setDestDir(sdkFileName.parentDir());
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onUnarchiverDone = [this, storage](const Unarchiver &, DoneWith result) { const auto onUnarchiverDone = [this, storage](DoneWith result) {
if (result != DoneWith::Success) { if (result != DoneWith::Success) {
logError(Tr::tr("Unarchiving error.")); logError(Tr::tr("Unarchiving error."));
return; return;

View File

@@ -253,12 +253,12 @@ void AttachCoreDialog::accepted()
AsyncTask<ResultType>{[this, copyFileAsync](auto &task) { AsyncTask<ResultType>{[this, copyFileAsync](auto &task) {
task.setConcurrentCallData(copyFileAsync, coreFile()); task.setConcurrentCallData(copyFileAsync, coreFile());
}, },
[=](const auto &task) { d->coreFileResult = task.result(); }, [=](const Async<ResultType> &task) { d->coreFileResult = task.result(); },
CallDoneIf::Success}, CallDoneIf::Success},
AsyncTask<ResultType>{[this, copyFileAsync](auto &task) { AsyncTask<ResultType>{[this, copyFileAsync](auto &task) {
task.setConcurrentCallData(copyFileAsync, symbolFile()); task.setConcurrentCallData(copyFileAsync, symbolFile());
}, },
[=](const auto &task) { d->symbolFileResult = task.result(); }, [=](const Async<ResultType> &task) { d->symbolFileResult = task.result(); },
CallDoneIf::Success} CallDoneIf::Success}
}; };

View File

@@ -110,7 +110,7 @@ DiffFilesController::DiffFilesController(IDocument *document)
const TreeStorage<QList<std::optional<FileData>>> storage; 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(); QList<std::optional<FileData>> *outputList = storage.activeStorage();
const QList<ReloadInput> inputList = reloadInputList(); const QList<ReloadInput> inputList = reloadInputList();
@@ -147,7 +147,7 @@ DiffFilesController::DiffFilesController(IDocument *document)
const Group root = { const Group root = {
Storage(storage), Storage(storage),
TaskTreeTask(setupTree), TaskTreeTask(onTreeSetup),
onGroupDone(onTreeDone), onGroupDone(onTreeDone),
onGroupError(onTreeError) onGroupError(onTreeError)
}; };

View File

@@ -483,7 +483,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
updateDescription(*data); updateDescription(*data);
}; };
const auto setupFollows = [this, storage, updateDescription](TaskTree &taskTree) { const auto onFollowsSetup = [this, storage, updateDescription](TaskTree &taskTree) {
ReloadStorage *data = storage.activeStorage(); ReloadStorage *data = storage.activeStorage();
QStringList parents; QStringList parents;
QString errorMessage; QString errorMessage;
@@ -536,7 +536,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
onGroupSetup(desciptionDetailsSetup), onGroupSetup(desciptionDetailsSetup),
ProcessTask(onBranchesSetup, onBranchesDone, CallDoneIf::Success), ProcessTask(onBranchesSetup, onBranchesDone, CallDoneIf::Success),
ProcessTask(onPrecedesSetup, onPrecedesDone, CallDoneIf::Success), ProcessTask(onPrecedesSetup, onPrecedesDone, CallDoneIf::Success),
TaskTreeTask(setupFollows) TaskTreeTask(onFollowsSetup)
} }
}, },
Group { Group {

View File

@@ -52,7 +52,7 @@ private:
streamer.setDestination(m_target); streamer.setDestination(m_target);
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onDone = [this](const FileStreamer &, DoneWith result) { const auto onDone = [this](DoneWith result) {
if (result == DoneWith::Success) if (result == DoneWith::Success)
addOutput(Tr::tr("Copying finished."), OutputFormat::NormalMessage); addOutput(Tr::tr("Copying finished."), OutputFormat::NormalMessage);
else else

View File

@@ -198,11 +198,11 @@ GroupItem QnxDeployQtLibrariesDialogPrivate::uploadTask()
GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTask(const DeployableFile &file) GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTask(const DeployableFile &file)
{ {
const auto onSetup = [=](Process &process) { const auto onSetup = [this, file](Process &process) {
process.setCommand({m_device->filePath("chmod"), process.setCommand({m_device->filePath("chmod"),
{"a+x", Utils::ProcessArgs::quoteArgUnix(file.remoteFilePath())}}); {"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(); const QString error = process.errorString();
if (!error.isEmpty()) { if (!error.isEmpty()) {
emitWarningMessage(Tr::tr("Remote chmod failed for file \"%1\": %2") emitWarningMessage(Tr::tr("Remote chmod failed for file \"%1\": %2")
@@ -217,7 +217,7 @@ GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTask(const DeployableFile &fil
GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTree() GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTree()
{ {
const auto setupChmodHandler = [=](TaskTree &tree) { const auto onSetup = [this](TaskTree &tree) {
QList<DeployableFile> filesToChmod; QList<DeployableFile> filesToChmod;
for (const DeployableFile &file : std::as_const(m_deployableFiles)) { for (const DeployableFile &file : std::as_const(m_deployableFiles)) {
if (file.isExecutable()) if (file.isExecutable())
@@ -230,7 +230,7 @@ GroupItem QnxDeployQtLibrariesDialogPrivate::chmodTree()
} }
tree.setRecipe(chmodList); tree.setRecipe(chmodList);
}; };
return TaskTreeTask{setupChmodHandler}; return TaskTreeTask(onSetup);
} }
Group QnxDeployQtLibrariesDialogPrivate::deployRecipe() Group QnxDeployQtLibrariesDialogPrivate::deployRecipe()

View File

@@ -37,7 +37,7 @@ void Slog2InfoRunner::start()
const auto onTestSetup = [this](Process &process) { const auto onTestSetup = [this](Process &process) {
process.setCommand({device()->filePath("slog2info"), {}}); process.setCommand({device()->filePath("slog2info"), {}});
}; };
const auto onTestDone = [this](const Process &, DoneWith result) { const auto onTestDone = [this](DoneWith result) {
if (result == DoneWith::Success) { if (result == DoneWith::Success) {
m_found = true; m_found = true;
return; return;

View File

@@ -151,7 +151,7 @@ GroupItem GenericDirectUploadStep::statTask(UploadStorage *storage,
GroupItem GenericDirectUploadStep::statTree(const TreeStorage<UploadStorage> &storage, GroupItem GenericDirectUploadStep::statTree(const TreeStorage<UploadStorage> &storage,
FilesToStat filesToStat, StatEndHandler statEndHandler) FilesToStat filesToStat, StatEndHandler statEndHandler)
{ {
const auto setupHandler = [=](TaskTree &tree) { const auto onSetup = [this, storage, filesToStat, statEndHandler](TaskTree &tree) {
UploadStorage *storagePtr = storage.activeStorage(); UploadStorage *storagePtr = storage.activeStorage();
const QList<DeployableFile> files = filesToStat(storagePtr); const QList<DeployableFile> files = filesToStat(storagePtr);
QList<GroupItem> statList{finishAllAndDone, parallelLimit(MaxConcurrentStatCalls)}; QList<GroupItem> statList{finishAllAndDone, parallelLimit(MaxConcurrentStatCalls)};
@@ -161,7 +161,7 @@ GroupItem GenericDirectUploadStep::statTree(const TreeStorage<UploadStorage> &st
} }
tree.setRecipe({statList}); tree.setRecipe({statList});
}; };
return TaskTreeTask(setupHandler); return TaskTreeTask(onSetup);
} }
GroupItem GenericDirectUploadStep::uploadTask(const TreeStorage<UploadStorage> &storage) GroupItem GenericDirectUploadStep::uploadTask(const TreeStorage<UploadStorage> &storage)
@@ -225,7 +225,7 @@ GroupItem GenericDirectUploadStep::chmodTask(const DeployableFile &file)
GroupItem GenericDirectUploadStep::chmodTree(const TreeStorage<UploadStorage> &storage) GroupItem GenericDirectUploadStep::chmodTree(const TreeStorage<UploadStorage> &storage)
{ {
const auto setupChmodHandler = [=](TaskTree &tree) { const auto onSetup = [this, storage](TaskTree &tree) {
QList<DeployableFile> filesToChmod; QList<DeployableFile> filesToChmod;
for (const DeployableFile &file : std::as_const(storage->filesToUpload)) { for (const DeployableFile &file : std::as_const(storage->filesToUpload)) {
if (file.isExecutable()) if (file.isExecutable())
@@ -238,7 +238,7 @@ GroupItem GenericDirectUploadStep::chmodTree(const TreeStorage<UploadStorage> &s
} }
tree.setRecipe({chmodList}); tree.setRecipe({chmodList});
}; };
return TaskTreeTask(setupChmodHandler); return TaskTreeTask(onSetup);
} }
GroupItem GenericDirectUploadStep::deployRecipe() GroupItem GenericDirectUploadStep::deployRecipe()

View File

@@ -55,7 +55,7 @@ GroupItem KillAppStep::deployRecipe()
.arg(m_remoteExecutable.path())); .arg(m_remoteExecutable.path()));
return SetupResult::Continue; 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.") const QString message = result == DoneWith::Success ? Tr::tr("Remote application killed.")
: Tr::tr("Failed to kill remote application. Assuming it was not running."); : Tr::tr("Failed to kill remote application. Assuming it was not running.");
addProgressMessage(message); addProgressMessage(message);

View File

@@ -153,7 +153,7 @@ Tasking::GroupItem TarPackageCreationStep::runRecipe()
async.setFutureSynchronizer(&m_synchronizer); async.setFutureSynchronizer(&m_synchronizer);
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onDone = [this](const Async<void> &, DoneWith result) { const auto onDone = [this](DoneWith result) {
if (result != DoneWith::Success) { if (result != DoneWith::Success) {
emit addOutput(Tr::tr("Packaging failed."), OutputFormat::ErrorMessage); emit addOutput(Tr::tr("Packaging failed."), OutputFormat::ErrorMessage);
return; return;

View File

@@ -80,14 +80,16 @@ void tst_Tasking::validConstructs()
parallel, parallel,
TestTask([](TaskObject &) {}, [](const TaskObject &, DoneWith) {}), TestTask([](TaskObject &) {}, [](const TaskObject &, DoneWith) {}),
TestTask([](TaskObject &) {}, [](const TaskObject &) {}), TestTask([](TaskObject &) {}, [](const TaskObject &) {}),
TestTask([](TaskObject &) {}, [](DoneWith) {}),
TestTask([](TaskObject &) {}, [] {}), TestTask([](TaskObject &) {}, [] {}),
TestTask([](TaskObject &) {}, {}), TestTask([](TaskObject &) {}, {}),
TestTask([](TaskObject &) {}), TestTask([](TaskObject &) {}),
TestTask({}, [](const TaskObject &, DoneWith) {}), TestTask({}, [](const TaskObject &, DoneWith) {}),
TestTask({}, [](const TaskObject &) {}), TestTask({}, [](const TaskObject &) {}),
TestTask({}, [](DoneWith) {}),
TestTask({}, [] {}), TestTask({}, [] {}),
TestTask({}, {}), TestTask({}, {}),
TestTask({}), TestTask({})
}; };
const Group group1 { const Group group1 {
@@ -232,7 +234,7 @@ void tst_Tasking::testTree_data()
}; };
const auto setupDone = [storage](int taskId, bool success = true) { 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 const Handler handler = result == DoneWith::Cancel ? Handler::Canceled
: success ? Handler::Success : Handler::Error; : success ? Handler::Success : Handler::Error;
storage->m_log.append({taskId, handler}); storage->m_log.append({taskId, handler});