2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "buildstep.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
#include "buildconfiguration.h"
|
|
|
|
|
#include "buildsteplist.h"
|
2011-02-21 17:38:12 +01:00
|
|
|
#include "deployconfiguration.h"
|
2010-07-16 14:00:41 +02:00
|
|
|
#include "target.h"
|
|
|
|
|
|
2016-05-18 12:37:29 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::BuildStep
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The BuildStep class provides build steps for projects.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
Build steps are the primary way plugin developers can customize
|
|
|
|
|
how their projects (or projects from other plugins) are built.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
Projects are built by taking the list of build steps
|
|
|
|
|
from the project and calling first \c init() and then \c run() on them.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
To change the way your project is built, reimplement
|
|
|
|
|
this class and add your build step to the build step list of the project.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\note The projects own the build step. Do not delete them yourself.
|
|
|
|
|
|
|
|
|
|
\c init() is called in the GUI thread and can be used to query the
|
2011-04-14 12:58:14 +02:00
|
|
|
project for any information you need.
|
|
|
|
|
|
2016-02-09 14:17:29 +01:00
|
|
|
\c run() is run via Utils::runAsync in a separate thread. If you need an
|
2013-06-05 14:29:24 +02:00
|
|
|
event loop, you need to create it yourself.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn bool ProjectExplorer::BuildStep::init()
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
This function is run in the GUI thread. Use it to retrieve any information
|
|
|
|
|
that you need in the run() function.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void ProjectExplorer::BuildStep::run(QFutureInterface<bool> &fi)
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Reimplement this function. It is called when the target is built.
|
|
|
|
|
By default, this function is NOT run in the GUI thread, but runs in its
|
2011-07-07 15:15:43 +02:00
|
|
|
own thread. If you need an event loop, you need to create one.
|
|
|
|
|
This function should block until the task is done
|
2011-04-14 12:58:14 +02:00
|
|
|
|
|
|
|
|
The absolute minimal implementation is:
|
|
|
|
|
\code
|
|
|
|
|
fi.reportResult(true);
|
|
|
|
|
\endcode
|
2011-07-07 15:15:43 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
By returning \c true from runInGuiThread(), this function is called in
|
|
|
|
|
the GUI thread. Then the function should not block and instead the
|
2011-07-07 15:15:43 +02:00
|
|
|
finished() signal should be emitted.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
\sa runInGuiThread()
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
\fn BuildStepConfigWidget *ProjectExplorer::BuildStep::createConfigWidget()
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Returns the Widget shown in the target settings dialog for this build step.
|
|
|
|
|
Ownership is transferred to the caller.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void ProjectExplorer::BuildStep::addTask(const ProjectExplorer::Task &task)
|
2013-09-10 17:16:10 +02:00
|
|
|
Adds \a task.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-05-23 16:13:55 +02:00
|
|
|
\fn void ProjectExplorer::BuildStep::addOutput(const QString &string, ProjectExplorer::BuildStep::OutputFormat format,
|
|
|
|
|
ProjectExplorer::BuildStep::OutputNewlineSetting newlineSetting = DoAppendNewline) const
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
The \a string is added to the generated output, usually in the output pane.
|
2011-04-14 12:58:14 +02:00
|
|
|
It should be in plain text, with the format in the parameter.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-07-07 15:15:43 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void ProjectExplorer::BuildStep::finished()
|
2013-09-10 17:16:10 +02:00
|
|
|
This signal needs to be emitted if the build step runs in the GUI thread.
|
2011-07-07 15:15:43 +02:00
|
|
|
*/
|
|
|
|
|
|
2012-01-23 14:55:58 +01:00
|
|
|
static const char buildStepEnabledKey[] = "ProjectExplorer.BuildStep.Enabled";
|
|
|
|
|
|
2009-04-20 16:29:46 +02:00
|
|
|
using namespace ProjectExplorer;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
BuildStep::BuildStep(BuildStepList *bsl, Core::Id id) :
|
2017-09-01 13:23:02 +02:00
|
|
|
ProjectConfiguration(bsl), m_enabled(true)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-09-01 13:23:02 +02:00
|
|
|
initialize(id);
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(bsl);
|
2017-03-17 00:27:13 +02:00
|
|
|
ctor();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
BuildStep::BuildStep(BuildStepList *bsl, BuildStep *bs) :
|
2017-09-01 13:23:02 +02:00
|
|
|
ProjectConfiguration(bsl), m_enabled(bs->m_enabled)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-09-01 13:23:02 +02:00
|
|
|
copyFrom(bs);
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(bsl);
|
2012-03-05 12:35:52 +01:00
|
|
|
setDisplayName(bs->displayName());
|
2017-03-17 00:27:13 +02:00
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildStep::ctor()
|
|
|
|
|
{
|
|
|
|
|
Utils::MacroExpander *expander = macroExpander();
|
|
|
|
|
expander->setDisplayName(tr("Build Step"));
|
|
|
|
|
expander->setAccumulating(true);
|
|
|
|
|
expander->registerSubProvider([this] { return projectConfiguration()->macroExpander(); });
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-23 14:55:58 +01:00
|
|
|
bool BuildStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2017-06-12 14:23:34 +02:00
|
|
|
m_enabled = map.value(buildStepEnabledKey, true).toBool();
|
2012-01-23 14:55:58 +01:00
|
|
|
return ProjectConfiguration::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap BuildStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = ProjectConfiguration::toMap();
|
2017-06-12 14:23:34 +02:00
|
|
|
map.insert(buildStepEnabledKey, m_enabled);
|
2012-01-23 14:55:58 +01:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-27 14:16:28 +01:00
|
|
|
BuildConfiguration *BuildStep::buildConfiguration() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-10-21 13:06:26 +00:00
|
|
|
return qobject_cast<BuildConfiguration *>(parent()->parent());
|
2010-07-16 14:00:41 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 17:38:12 +01:00
|
|
|
DeployConfiguration *BuildStep::deployConfiguration() const
|
|
|
|
|
{
|
2011-10-21 13:06:26 +00:00
|
|
|
return qobject_cast<DeployConfiguration *>(parent()->parent());
|
2011-02-21 17:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-24 13:10:38 +00:00
|
|
|
ProjectConfiguration *BuildStep::projectConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<ProjectConfiguration *>(parent()->parent());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
Target *BuildStep::target() const
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<Target *>(parent()->parent()->parent());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-21 13:06:26 +00:00
|
|
|
Project *BuildStep::project() const
|
|
|
|
|
{
|
|
|
|
|
return target()->project();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 12:49:25 +02:00
|
|
|
void BuildStep::reportRunResult(QFutureInterface<bool> &fi, bool success)
|
|
|
|
|
{
|
|
|
|
|
fi.reportResult(success);
|
|
|
|
|
fi.reportFinished();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 16:04:45 +02:00
|
|
|
bool BuildStep::isActive() const
|
|
|
|
|
{
|
|
|
|
|
return projectConfiguration()->isActive();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
/*!
|
|
|
|
|
If this function returns \c true, the user cannot delete this build step for
|
|
|
|
|
this target and the user is prevented from changing the order in which
|
|
|
|
|
immutable steps are run. The default implementation returns \c false.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool BuildStep::immutable() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 15:15:43 +02:00
|
|
|
bool BuildStep::runInGuiThread() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
/*!
|
|
|
|
|
This function needs to be reimplemented only for build steps that return
|
|
|
|
|
\c false from runInGuiThread().
|
|
|
|
|
|
|
|
|
|
\sa runInGuiThread()
|
|
|
|
|
*/
|
2011-07-07 15:15:43 +02:00
|
|
|
void BuildStep::cancel()
|
|
|
|
|
{
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-23 14:55:58 +01:00
|
|
|
void BuildStep::setEnabled(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (m_enabled == b)
|
|
|
|
|
return;
|
|
|
|
|
m_enabled = b;
|
|
|
|
|
emit enabledChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BuildStep::enabled() const
|
|
|
|
|
{
|
|
|
|
|
return m_enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 17:41:29 +01:00
|
|
|
IBuildStepFactory::IBuildStepFactory(QObject *parent) :
|
|
|
|
|
QObject(parent)
|
2010-07-16 14:00:41 +02:00
|
|
|
{ }
|
2016-05-18 12:37:29 +02:00
|
|
|
|
|
|
|
|
BuildStep *IBuildStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
const Core::Id id = idFromMap(map);
|
|
|
|
|
BuildStep *bs = create(parent, id);
|
|
|
|
|
if (bs->fromMap(map))
|
|
|
|
|
return bs;
|
|
|
|
|
delete bs;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|