forked from qt-creator/qt-creator
BuildManager: Simplify buildQueueAppend()
Pass QList<BuildItem> instead of two separate lists with build steps and their names. Use "continue" when disabled or when init succeeded. Move the "if (!init)" early return directly into the previous loop. Append directly the passed items into the m_buildQueue. Change-Id: Ie1bfc4e0695bf24d5bf25570523fed9b6b8c31e3 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -246,7 +246,9 @@ static int queue(const QList<Project *> &projects, const QList<Id> &stepIds,
|
|||||||
return stepLists.count();
|
return stepLists.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BuildItem {
|
class BuildItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
BuildStep *buildStep = nullptr;
|
BuildStep *buildStep = nullptr;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
QString name;
|
QString name;
|
||||||
@@ -800,7 +802,7 @@ void BuildManager::nextStep()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildManager::buildQueueAppend(const QList<BuildStep *> &steps, QStringList names, const QStringList &preambleMessage)
|
bool BuildManager::buildQueueAppend(const QList<BuildItem> &items, const QStringList &preambleMessage)
|
||||||
{
|
{
|
||||||
if (!d->m_running) {
|
if (!d->m_running) {
|
||||||
d->m_outputWindow->clearContents();
|
d->m_outputWindow->clearContents();
|
||||||
@@ -810,49 +812,37 @@ bool BuildManager::buildQueueAppend(const QList<BuildStep *> &steps, QStringList
|
|||||||
TaskHub::clearTasks(Constants::TASK_CATEGORY_DEPLOYMENT);
|
TaskHub::clearTasks(Constants::TASK_CATEGORY_DEPLOYMENT);
|
||||||
TaskHub::clearTasks(Constants::TASK_CATEGORY_AUTOTEST);
|
TaskHub::clearTasks(Constants::TASK_CATEGORY_AUTOTEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const QString &str : preambleMessage)
|
for (const QString &str : preambleMessage)
|
||||||
addToOutputWindow(str, BuildStep::OutputFormat::NormalMessage, BuildStep::DontAppendNewline);
|
addToOutputWindow(str, BuildStep::OutputFormat::NormalMessage, BuildStep::DontAppendNewline);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = steps.size();
|
QList<BuildStep *> connectedSteps;
|
||||||
bool init = true;
|
int enabledCount = 0;
|
||||||
int i = 0;
|
for (const BuildItem &item : items) {
|
||||||
for (; i < count; ++i) {
|
connect(item.buildStep, &BuildStep::addTask, m_instance, &BuildManager::addToTaskWindow);
|
||||||
BuildStep *bs = steps.at(i);
|
connect(item.buildStep, &BuildStep::addOutput, m_instance, &BuildManager::addToOutputWindow);
|
||||||
connect(bs, &BuildStep::addTask, m_instance, &BuildManager::addToTaskWindow);
|
connectedSteps.append(item.buildStep);
|
||||||
connect(bs, &BuildStep::addOutput, m_instance, &BuildManager::addToOutputWindow);
|
if (!item.enabled)
|
||||||
if (bs->enabled()) {
|
continue;
|
||||||
init = bs->init();
|
++enabledCount;
|
||||||
if (!init)
|
if (item.buildStep->init())
|
||||||
break;
|
continue;
|
||||||
}
|
// init() failed, print something for the user...
|
||||||
}
|
const QString projectName = item.buildStep->project()->displayName();
|
||||||
if (!init) {
|
const QString targetName = item.buildStep->target()->displayName();
|
||||||
BuildStep *bs = steps.at(i);
|
addToOutputWindow(Tr::tr("Error while building/deploying project %1 (kit: %2)")
|
||||||
|
.arg(projectName, targetName), BuildStep::OutputFormat::Stderr);
|
||||||
// cleaning up
|
addToOutputWindow(Tr::tr("When executing step \"%1\"")
|
||||||
// print something for the user
|
.arg(item.buildStep->displayName()), BuildStep::OutputFormat::Stderr);
|
||||||
const QString projectName = bs->project()->displayName();
|
for (BuildStep *buildStep : std::as_const(connectedSteps))
|
||||||
const QString targetName = bs->target()->displayName();
|
disconnectOutput(buildStep);
|
||||||
addToOutputWindow(Tr::tr("Error while building/deploying project %1 (kit: %2)").arg(projectName, targetName), BuildStep::OutputFormat::Stderr);
|
|
||||||
addToOutputWindow(Tr::tr("When executing step \"%1\"").arg(bs->displayName()), BuildStep::OutputFormat::Stderr);
|
|
||||||
|
|
||||||
// disconnect the buildsteps again
|
|
||||||
for (int j = 0; j <= i; ++j)
|
|
||||||
disconnectOutput(steps.at(j));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everthing init() well
|
d->m_buildQueue << items;
|
||||||
for (i = 0; i < count; ++i) {
|
d->m_maxProgress += enabledCount;
|
||||||
BuildStep *buildStep = steps.at(i);
|
for (const BuildItem &item : items)
|
||||||
const bool enabled = buildStep->enabled();
|
incrementActiveBuildSteps(item.buildStep);
|
||||||
d->m_buildQueue.append({buildStep, enabled, names.at(i)});
|
|
||||||
if (enabled)
|
|
||||||
++d->m_maxProgress;
|
|
||||||
incrementActiveBuildSteps(buildStep);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -861,25 +851,18 @@ bool BuildManager::buildList(BuildStepList *bsl)
|
|||||||
return buildLists({bsl});
|
return buildLists({bsl});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildManager::buildLists(const QList<BuildStepList *> bsls, const QStringList &preambelMessage)
|
bool BuildManager::buildLists(const QList<BuildStepList *> &bsls, const QStringList &preambleMessage)
|
||||||
{
|
{
|
||||||
QList<BuildStep *> steps;
|
QList<BuildItem> buildItems;
|
||||||
QStringList stepListNames;
|
|
||||||
for (BuildStepList *list : bsls) {
|
for (BuildStepList *list : bsls) {
|
||||||
steps.append(list->steps());
|
const QString name = displayNameForStepId(list->id());
|
||||||
stepListNames.append(displayNameForStepId(list->id()));
|
const QList<BuildStep *> steps = list->steps();
|
||||||
|
for (BuildStep *step : steps)
|
||||||
|
buildItems.append({step, step->enabled(), name});
|
||||||
d->m_isDeploying = d->m_isDeploying || list->id() == Constants::BUILDSTEPS_DEPLOY;
|
d->m_isDeploying = d->m_isDeploying || list->id() == Constants::BUILDSTEPS_DEPLOY;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList names;
|
if (!buildQueueAppend(buildItems, preambleMessage)) {
|
||||||
names.reserve(steps.size());
|
|
||||||
for (int i = 0; i < bsls.size(); ++i) {
|
|
||||||
for (int j = 0; j < bsls.at(i)->count(); ++j)
|
|
||||||
names.append(stepListNames.at(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success = buildQueueAppend(steps, names, preambelMessage);
|
|
||||||
if (!success) {
|
|
||||||
d->m_outputWindow->popup(IOutputPane::NoModeSwitch);
|
d->m_outputWindow->popup(IOutputPane::NoModeSwitch);
|
||||||
d->m_isDeploying = false;
|
d->m_isDeploying = false;
|
||||||
return false;
|
return false;
|
||||||
@@ -893,8 +876,7 @@ bool BuildManager::buildLists(const QList<BuildStepList *> bsls, const QStringLi
|
|||||||
|
|
||||||
void BuildManager::appendStep(BuildStep *step, const QString &name)
|
void BuildManager::appendStep(BuildStep *step, const QString &name)
|
||||||
{
|
{
|
||||||
bool success = buildQueueAppend({step}, {name});
|
if (!buildQueueAppend({{step, step->enabled(), name}})) {
|
||||||
if (!success) {
|
|
||||||
d->m_outputWindow->popup(IOutputPane::NoModeSwitch);
|
d->m_outputWindow->popup(IOutputPane::NoModeSwitch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
|
class BuildItem;
|
||||||
class Project;
|
class Project;
|
||||||
class RunConfiguration;
|
class RunConfiguration;
|
||||||
class Task;
|
class Task;
|
||||||
@@ -33,9 +34,7 @@ public:
|
|||||||
static void cleanProjectWithoutDependencies(Project *project);
|
static void cleanProjectWithoutDependencies(Project *project);
|
||||||
static void rebuildProjectWithoutDependencies(Project *project);
|
static void rebuildProjectWithoutDependencies(Project *project);
|
||||||
static void buildProjectWithDependencies(
|
static void buildProjectWithDependencies(
|
||||||
Project *project,
|
Project *project, ConfigSelection configSelection = ConfigSelection::Active);
|
||||||
ConfigSelection configSelection = ConfigSelection::Active
|
|
||||||
);
|
|
||||||
static void cleanProjectWithDependencies(Project *project, ConfigSelection configSelection);
|
static void cleanProjectWithDependencies(Project *project, ConfigSelection configSelection);
|
||||||
static void rebuildProjectWithDependencies(Project *project, ConfigSelection configSelection);
|
static void rebuildProjectWithDependencies(Project *project, ConfigSelection configSelection);
|
||||||
static void buildProjects(const QList<Project *> &projects, ConfigSelection configSelection);
|
static void buildProjects(const QList<Project *> &projects, ConfigSelection configSelection);
|
||||||
@@ -50,8 +49,8 @@ public:
|
|||||||
static bool isDeploying();
|
static bool isDeploying();
|
||||||
static bool tasksAvailable();
|
static bool tasksAvailable();
|
||||||
|
|
||||||
static bool buildLists(const QList<BuildStepList *> bsls,
|
static bool buildLists(const QList<BuildStepList *> &bsls,
|
||||||
const QStringList &preambelMessage = QStringList());
|
const QStringList &preambelMessage = {});
|
||||||
static bool buildList(BuildStepList *bsl);
|
static bool buildList(BuildStepList *bsl);
|
||||||
|
|
||||||
static bool isBuilding(const Project *p);
|
static bool isBuilding(const Project *p);
|
||||||
@@ -93,7 +92,8 @@ private:
|
|||||||
static void startBuildQueue();
|
static void startBuildQueue();
|
||||||
static void nextStep();
|
static void nextStep();
|
||||||
static void clearBuildQueue();
|
static void clearBuildQueue();
|
||||||
static bool buildQueueAppend(const QList<BuildStep *> &steps, QStringList names, const QStringList &preambleMessage = QStringList());
|
static bool buildQueueAppend(const QList<BuildItem> &items,
|
||||||
|
const QStringList &preambleMessage = {});
|
||||||
static void incrementActiveBuildSteps(BuildStep *bs);
|
static void incrementActiveBuildSteps(BuildStep *bs);
|
||||||
static void decrementActiveBuildSteps(BuildStep *bs);
|
static void decrementActiveBuildSteps(BuildStep *bs);
|
||||||
static void disconnectOutput(BuildStep *bs);
|
static void disconnectOutput(BuildStep *bs);
|
||||||
|
Reference in New Issue
Block a user