forked from qt-creator/qt-creator
TaskTree: Merge DynamicSetup with OnGroupSetup
Don't define 2 separate group setup items. Make OnGroupSetup be able to handle also dynamic setup - like it's done with CustomTask's setup handler. Change-Id: I43e135f268ea96419b44ef5a4325707a124b4921 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -119,17 +119,12 @@ void TaskItem::addChildren(const QList<TaskItem> &children)
|
||||
QTC_ASSERT(!child.m_groupHandler.m_errorHandler
|
||||
|| !m_groupHandler.m_errorHandler,
|
||||
qWarning("Group Error Handler redefinition, overriding..."));
|
||||
QTC_ASSERT(!child.m_groupHandler.m_dynamicSetupHandler
|
||||
|| !m_groupHandler.m_dynamicSetupHandler,
|
||||
qWarning("Dynamic Setup Handler redefinition, overriding..."));
|
||||
if (child.m_groupHandler.m_setupHandler)
|
||||
m_groupHandler.m_setupHandler = child.m_groupHandler.m_setupHandler;
|
||||
if (child.m_groupHandler.m_doneHandler)
|
||||
m_groupHandler.m_doneHandler = child.m_groupHandler.m_doneHandler;
|
||||
if (child.m_groupHandler.m_errorHandler)
|
||||
m_groupHandler.m_errorHandler = child.m_groupHandler.m_errorHandler;
|
||||
if (child.m_groupHandler.m_dynamicSetupHandler)
|
||||
m_groupHandler.m_dynamicSetupHandler = child.m_groupHandler.m_dynamicSetupHandler;
|
||||
break;
|
||||
case Type::Storage:
|
||||
m_storageList.append(child.m_storageList);
|
||||
@@ -353,13 +348,10 @@ TaskAction TaskContainer::start()
|
||||
|
||||
createStorages();
|
||||
TaskAction groupAction = TaskAction::Continue;
|
||||
if (m_groupHandler.m_setupHandler || m_groupHandler.m_dynamicSetupHandler) {
|
||||
if (m_groupHandler.m_setupHandler) {
|
||||
StorageActivator activator(*this);
|
||||
GuardLocker locker(m_taskTreePrivate->m_guard);
|
||||
if (m_groupHandler.m_setupHandler)
|
||||
m_groupHandler.m_setupHandler();
|
||||
if (m_groupHandler.m_dynamicSetupHandler)
|
||||
groupAction = m_groupHandler.m_dynamicSetupHandler();
|
||||
groupAction = m_groupHandler.m_setupHandler();
|
||||
}
|
||||
|
||||
if (groupAction == TaskAction::StopWithDone || groupAction == TaskAction::StopWithError) {
|
||||
|
@@ -117,10 +117,10 @@ public:
|
||||
using TaskSetupHandler = std::function<TaskAction(TaskInterface &)>;
|
||||
// Called on task done / error
|
||||
using TaskEndHandler = std::function<void(const TaskInterface &)>;
|
||||
// Called when group entered / after group ended with success or failure
|
||||
using GroupSimpleHandler = std::function<void()>;
|
||||
// Called when group entered
|
||||
using GroupSetupHandler = std::function<TaskAction()>;
|
||||
// Called when group done / error
|
||||
using GroupEndHandler = std::function<void()>;
|
||||
|
||||
struct TaskHandler {
|
||||
TaskCreateHandler m_createHandler;
|
||||
@@ -130,10 +130,9 @@ public:
|
||||
};
|
||||
|
||||
struct GroupHandler {
|
||||
GroupSimpleHandler m_setupHandler;
|
||||
GroupSimpleHandler m_doneHandler = {};
|
||||
GroupSimpleHandler m_errorHandler = {};
|
||||
GroupSetupHandler m_dynamicSetupHandler = {};
|
||||
GroupSetupHandler m_setupHandler;
|
||||
GroupEndHandler m_doneHandler = {};
|
||||
GroupEndHandler m_errorHandler = {};
|
||||
};
|
||||
|
||||
int parallelLimit() const { return m_parallelLimit; }
|
||||
@@ -209,25 +208,39 @@ public:
|
||||
class QTCREATOR_UTILS_EXPORT OnGroupSetup : public TaskItem
|
||||
{
|
||||
public:
|
||||
OnGroupSetup(const GroupSimpleHandler &handler) : TaskItem({handler}) {}
|
||||
template <typename SetupFunction>
|
||||
OnGroupSetup(SetupFunction &&function)
|
||||
: TaskItem({wrapSetup(std::forward<SetupFunction>(function))}) {}
|
||||
|
||||
private:
|
||||
template<typename SetupFunction>
|
||||
static TaskItem::GroupSetupHandler wrapSetup(SetupFunction &&function) {
|
||||
constexpr bool isDynamic = std::is_same_v<TaskAction,
|
||||
std::invoke_result_t<std::decay_t<SetupFunction>>>;
|
||||
constexpr bool isVoid = std::is_same_v<void,
|
||||
std::invoke_result_t<std::decay_t<SetupFunction>>>;
|
||||
static_assert(isDynamic || isVoid,
|
||||
"Group setup handler needs to take no arguments and has to return "
|
||||
"void or TaskAction. The passed handler doesn't fulfill these requirements.");
|
||||
return [=] {
|
||||
if constexpr (isDynamic)
|
||||
return std::invoke(function);
|
||||
std::invoke(function);
|
||||
return TaskAction::Continue;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT OnGroupDone : public TaskItem
|
||||
{
|
||||
public:
|
||||
OnGroupDone(const GroupSimpleHandler &handler) : TaskItem({{}, handler}) {}
|
||||
OnGroupDone(const GroupEndHandler &handler) : TaskItem({{}, handler}) {}
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT OnGroupError : public TaskItem
|
||||
{
|
||||
public:
|
||||
OnGroupError(const GroupSimpleHandler &handler) : TaskItem({{}, {}, handler}) {}
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT DynamicSetup : public TaskItem
|
||||
{
|
||||
public:
|
||||
DynamicSetup(const GroupSetupHandler &handler) : TaskItem({{}, {}, {}, handler}) {}
|
||||
OnGroupError(const GroupEndHandler &handler) : TaskItem({{}, {}, handler}) {}
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT extern ParallelLimit sequential;
|
||||
|
@@ -184,7 +184,7 @@ TaskItem clangToolTask(const AnalyzeInputData &input,
|
||||
|
||||
const Group group {
|
||||
Storage(storage),
|
||||
DynamicSetup(onGroupSetup),
|
||||
OnGroupSetup(onGroupSetup),
|
||||
Group {
|
||||
optional,
|
||||
Process(onProcessSetup, onProcessDone, onProcessError)
|
||||
|
@@ -469,7 +469,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
Group {
|
||||
parallel,
|
||||
optional,
|
||||
DynamicSetup(desciptionDetailsSetup),
|
||||
OnGroupSetup(desciptionDetailsSetup),
|
||||
Process(setupBranches, onBranchesDone, onBranchesError),
|
||||
Process(setupPrecedes, onPrecedesDone, onPrecedesError),
|
||||
Tree(setupFollows)
|
||||
|
@@ -250,7 +250,7 @@ void tst_TaskTree::processTree_data()
|
||||
Process(std::bind(setupDynamicProcess, _1, 1, TaskAction::Continue), readResult, readError),
|
||||
Process(std::bind(setupDynamicProcess, _1, 2, TaskAction::Continue), readResult, readError),
|
||||
Group {
|
||||
DynamicSetup([storage] { storage->m_log.append({0, Handler::GroupSetup});
|
||||
OnGroupSetup([storage] { storage->m_log.append({0, Handler::GroupSetup});
|
||||
return TaskAction::StopWithError; }),
|
||||
Process(std::bind(setupDynamicProcess, _1, 3, TaskAction::Continue), readResult, readError)
|
||||
},
|
||||
@@ -523,7 +523,7 @@ void tst_TaskTree::processTree_data()
|
||||
const auto stopWithDoneSetup = [] { return TaskAction::StopWithDone; };
|
||||
const auto stopWithErrorSetup = [] { return TaskAction::StopWithError; };
|
||||
const auto continueSetup = [] { return TaskAction::Continue; };
|
||||
const auto constructDynamicSetup = [=](const DynamicSetup &dynamicSetup) {
|
||||
const auto constructDynamicSetup = [=](const OnGroupSetup &dynamicSetup) {
|
||||
return Group {
|
||||
Storage(storage),
|
||||
Group {
|
||||
|
Reference in New Issue
Block a user