buildstep.cpp 6.23 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31
#include "buildstep.h"
hjk's avatar
hjk committed
32

Tobias Hunger's avatar
Tobias Hunger committed
33 34
#include "buildconfiguration.h"
#include "buildsteplist.h"
35
#include "deployconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
36 37
#include "target.h"

38 39 40
/*!
    \class ProjectExplorer::BuildStep

41
    \brief The BuildStep class provides build steps for projects.
42

43 44
    Build steps are the primary way plugin developers can customize
    how their projects (or projects from other plugins) are built.
45

46 47
    Projects are built by taking the list of build steps
    from the project and calling first \c init() and then \c run() on them.
48

49 50
    To change the way your project is built, reimplement
    this class and add your build step to the build step list of the project.
51

52 53 54
    \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
55 56
    project for any information you need.

57 58
    \c run() is run via QtConcurrent in a separate thread. If you need an
    event loop, you need to create it yourself.
59 60 61 62 63
*/

/*!
    \fn bool ProjectExplorer::BuildStep::init()

64 65
    This function is run in the GUI thread. Use it to retrieve any information
    that you need in the run() function.
66 67 68 69 70
*/

/*!
    \fn void ProjectExplorer::BuildStep::run(QFutureInterface<bool> &fi)

71 72
    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
73 74
    own thread. If you need an event loop, you need to create one.
    This function should block until the task is done
75 76 77 78 79

    The absolute minimal implementation is:
    \code
    fi.reportResult(true);
    \endcode
80

81 82
    By returning \c true from runInGuiThread(), this function is called in
    the GUI thread. Then the function should not block and instead the
83
    finished() signal should be emitted.
84

85
    \sa runInGuiThread()
86 87 88
*/

/*!
89
    \fn BuildStepConfigWidget *ProjectExplorer::BuildStep::createConfigWidget()
90

91 92
    Returns the Widget shown in the target settings dialog for this build step.
    Ownership is transferred to the caller.
93 94 95 96
*/

/*!
    \fn  void ProjectExplorer::BuildStep::addTask(const ProjectExplorer::Task &task)
97
    Adds \a task.
98 99 100
*/

/*!
101 102
    \fn  void ProjectExplorer::BuildStep::addOutput(const QString &string, ProjectExplorer::BuildStep::OutputFormat format,
              ProjectExplorer::BuildStep::OutputNewlineSetting newlineSetting = DoAppendNewline) const
103

104
    The \a string is added to the generated output, usually in the output pane.
105 106 107
    It should be in plain text, with the format in the parameter.
*/

108 109
/*!
    \fn  void ProjectExplorer::BuildStep::finished()
110
    This signal needs to be emitted if the build step runs in the GUI thread.
111 112
*/

Daniel Teske's avatar
Daniel Teske committed
113 114
static const char buildStepEnabledKey[] = "ProjectExplorer.BuildStep.Enabled";

115
using namespace ProjectExplorer;
con's avatar
con committed
116

117
BuildStep::BuildStep(BuildStepList *bsl, Core::Id id) :
Daniel Teske's avatar
Daniel Teske committed
118
    ProjectConfiguration(bsl, id), m_enabled(true)
con's avatar
con committed
119
{
Tobias Hunger's avatar
Tobias Hunger committed
120
    Q_ASSERT(bsl);
con's avatar
con committed
121 122
}

Tobias Hunger's avatar
Tobias Hunger committed
123
BuildStep::BuildStep(BuildStepList *bsl, BuildStep *bs) :
Daniel Teske's avatar
Daniel Teske committed
124
    ProjectConfiguration(bsl, bs), m_enabled(bs->m_enabled)
con's avatar
con committed
125
{
Tobias Hunger's avatar
Tobias Hunger committed
126
    Q_ASSERT(bsl);
127
    setDisplayName(bs->displayName());
con's avatar
con committed
128 129
}

Daniel Teske's avatar
Daniel Teske committed
130 131 132 133 134 135 136 137 138 139 140 141 142
bool BuildStep::fromMap(const QVariantMap &map)
{
    m_enabled = map.value(QLatin1String(buildStepEnabledKey), true).toBool();
    return ProjectConfiguration::fromMap(map);
}

QVariantMap BuildStep::toMap() const
{
    QVariantMap map = ProjectConfiguration::toMap();
    map.insert(QLatin1String(buildStepEnabledKey), m_enabled);
    return map;
}

143
BuildConfiguration *BuildStep::buildConfiguration() const
con's avatar
con committed
144
{
145
    return qobject_cast<BuildConfiguration *>(parent()->parent());
Tobias Hunger's avatar
Tobias Hunger committed
146 147
}

148 149
DeployConfiguration *BuildStep::deployConfiguration() const
{
150
    return qobject_cast<DeployConfiguration *>(parent()->parent());
151 152
}

Daniel Teske's avatar
Daniel Teske committed
153 154 155 156 157
ProjectConfiguration *BuildStep::projectConfiguration() const
{
    return static_cast<ProjectConfiguration *>(parent()->parent());
}

Tobias Hunger's avatar
Tobias Hunger committed
158 159 160
Target *BuildStep::target() const
{
    return qobject_cast<Target *>(parent()->parent()->parent());
con's avatar
con committed
161 162
}

163 164 165 166 167
Project *BuildStep::project() const
{
    return target()->project();
}

168 169 170 171 172 173
/*!
    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.
*/

con's avatar
con committed
174 175 176 177 178
bool BuildStep::immutable() const
{
    return false;
}

179 180 181 182 183
bool BuildStep::runInGuiThread() const
{
    return false;
}

184 185 186 187 188 189
/*!
    This function needs to be reimplemented only for build steps that return
    \c false from runInGuiThread().

    \sa runInGuiThread()
*/
190 191 192 193 194
void BuildStep::cancel()
{
    // Do nothing
}

Daniel Teske's avatar
Daniel Teske committed
195 196 197 198 199 200 201 202 203 204 205 206 207
void BuildStep::setEnabled(bool b)
{
    if (m_enabled == b)
        return;
    m_enabled = b;
    emit enabledChanged();
}

bool BuildStep::enabled() const
{
    return m_enabled;
}

208 209
IBuildStepFactory::IBuildStepFactory(QObject *parent) :
    QObject(parent)
Tobias Hunger's avatar
Tobias Hunger committed
210
{ }
con's avatar
con committed
211 212

IBuildStepFactory::~IBuildStepFactory()
Tobias Hunger's avatar
Tobias Hunger committed
213
{ }