TaskTree: Introduce DoneResult, use it for Sync setup

Instead of using ambiguous bool.

Change-Id: Iec45b920a839ac3383abc2d0676e5834f282dddf
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-11-06 17:48:56 +01:00
parent 88ac19f188
commit 7ff13f1eaa
4 changed files with 33 additions and 21 deletions

View File

@@ -159,6 +159,13 @@ enum class SetupResult
}; };
Q_ENUM_NS(SetupResult); Q_ENUM_NS(SetupResult);
enum class DoneResult
{
Success,
Error
};
Q_ENUM_NS(DoneResult);
enum class DoneWith enum class DoneWith
{ {
Success, Success,
@@ -374,15 +381,15 @@ public:
private: private:
template <typename Handler> template <typename Handler>
static GroupSetupHandler wrapHandler(Handler &&handler) { static GroupSetupHandler wrapHandler(Handler &&handler) {
// B, V stands for: [B]ool, [V]oid // D, V stands for: [D]oneResult, [V]oid
static constexpr bool isB = isInvocable<bool, Handler>(); static constexpr bool isB = isInvocable<DoneResult, Handler>();
static constexpr bool isV = isInvocable<void, Handler>(); static constexpr bool isV = isInvocable<void, Handler>();
static_assert(isB || isV, static_assert(isB || isV,
"Sync handler needs to take no arguments and has to return void or bool. " "Sync handler needs to take no arguments and has to return void or DoneResult. "
"The passed handler doesn't fulfill these requirements."); "The passed handler doesn't fulfill these requirements.");
return [=] { return [=] {
if constexpr (isB) { if constexpr (isB) {
return std::invoke(handler) ? SetupResult::StopWithSuccess return std::invoke(handler) == DoneResult::Success ? SetupResult::StopWithSuccess
: SetupResult::StopWithError; : SetupResult::StopWithError;
} }
std::invoke(handler); std::invoke(handler);

View File

@@ -59,7 +59,7 @@ CppIncludesFilter::CppIncludesFilter()
setDefaultShortcutString("ai"); setDefaultShortcutString("ai");
setDefaultIncludedByDefault(true); setDefaultIncludedByDefault(true);
const auto invalidate = [this] { m_cache.invalidate(); }; const auto invalidate = [this] { m_cache.invalidate(); };
setRefreshRecipe(Tasking::Sync([invalidate] { invalidate(); return true; })); setRefreshRecipe(Tasking::Sync([invalidate] { invalidate(); }));
setPriority(ILocatorFilter::Low); setPriority(ILocatorFilter::Low);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged, connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged,

View File

@@ -63,19 +63,19 @@ GroupItem NimCompilerCleanStep::runRecipe()
if (!m_buildDir.exists()) { if (!m_buildDir.exists()) {
emit addOutput(Tr::tr("Build directory \"%1\" does not exist.") emit addOutput(Tr::tr("Build directory \"%1\" does not exist.")
.arg(m_buildDir.toUserOutput()), OutputFormat::ErrorMessage); .arg(m_buildDir.toUserOutput()), OutputFormat::ErrorMessage);
return false; return DoneResult::Error;
} }
if (!removeCacheDirectory()) { if (!removeCacheDirectory()) {
emit addOutput(Tr::tr("Failed to delete the cache directory."), emit addOutput(Tr::tr("Failed to delete the cache directory."),
OutputFormat::ErrorMessage); OutputFormat::ErrorMessage);
return false; return DoneResult::Error;
} }
if (!removeOutFilePath()) { if (!removeOutFilePath()) {
emit addOutput(Tr::tr("Failed to delete the out file."), OutputFormat::ErrorMessage); emit addOutput(Tr::tr("Failed to delete the out file."), OutputFormat::ErrorMessage);
return false; return DoneResult::Error;
} }
emit addOutput(Tr::tr("Clean step completed successfully."), OutputFormat::NormalMessage); emit addOutput(Tr::tr("Clean step completed successfully."), OutputFormat::NormalMessage);
return true; return DoneResult::Success;
}; };
return Sync(onSetup); return Sync(onSetup);
} }

View File

@@ -397,6 +397,11 @@ static Handler doneToTweakHandler(bool result)
return result ? Handler::TweakDoneToSuccess : Handler::TweakDoneToError; return result ? Handler::TweakDoneToSuccess : Handler::TweakDoneToError;
} }
static Handler doneToTweakHandler(DoneResult result)
{
return result == DoneResult::Success ? Handler::TweakDoneToSuccess : Handler::TweakDoneToError;
}
static TestData storageShadowing() static TestData storageShadowing()
{ {
// This test check if storage shadowing works OK. // This test check if storage shadowing works OK.
@@ -555,11 +560,11 @@ void tst_Tasking::testTree_data()
const auto createSync = [storage](int taskId) { const auto createSync = [storage](int taskId) {
return Sync([storage, taskId] { storage->m_log.append({taskId, Handler::Sync}); }); return Sync([storage, taskId] { storage->m_log.append({taskId, Handler::Sync}); });
}; };
const auto createSyncWithTweak = [storage](int taskId, bool desiredResult) { const auto createSyncWithTweak = [storage](int taskId, DoneResult result) {
return Sync([storage, taskId, desiredResult] { return Sync([storage, taskId, result] {
storage->m_log.append({taskId, Handler::Sync}); storage->m_log.append({taskId, Handler::Sync});
storage->m_log.append({taskId, doneToTweakHandler(desiredResult)}); storage->m_log.append({taskId, doneToTweakHandler(result)});
return desiredResult; return result;
}); });
}; };
@@ -2083,11 +2088,11 @@ void tst_Tasking::testTree_data()
{ {
const Group root { const Group root {
Storage(storage), Storage(storage),
createSyncWithTweak(1, true), createSyncWithTweak(1, DoneResult::Success),
createSyncWithTweak(2, true), createSyncWithTweak(2, DoneResult::Success),
createSyncWithTweak(3, true), createSyncWithTweak(3, DoneResult::Success),
createSyncWithTweak(4, true), createSyncWithTweak(4, DoneResult::Success),
createSyncWithTweak(5, true) createSyncWithTweak(5, DoneResult::Success)
}; };
const Log log { const Log log {
{1, Handler::Sync}, {1, Handler::Sync},
@@ -2130,7 +2135,7 @@ void tst_Tasking::testTree_data()
parallel, parallel,
createSync(1), createSync(1),
createSync(2), createSync(2),
createSyncWithTweak(3, false), createSyncWithTweak(3, DoneResult::Error),
createSync(4), createSync(4),
createSync(5) createSync(5)
}; };
@@ -2171,7 +2176,7 @@ void tst_Tasking::testTree_data()
Storage(storage), Storage(storage),
createSync(1), createSync(1),
createSuccessTask(2), createSuccessTask(2),
createSyncWithTweak(3, false), createSyncWithTweak(3, DoneResult::Error),
createSuccessTask(4), createSuccessTask(4),
createSync(5), createSync(5),
groupDone(0) groupDone(0)