buildstep.cpp 6 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://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
12 13 14
** 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.
15
**
16 17 18 19 20 21 22
** 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.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

con's avatar
con committed
26
#include "buildstep.h"
hjk's avatar
hjk committed
27

Tobias Hunger's avatar
Tobias Hunger committed
28 29
#include "buildconfiguration.h"
#include "buildsteplist.h"
30
#include "deployconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
31 32
#include "target.h"

33 34 35
/*!
    \class ProjectExplorer::BuildStep

36
    \brief The BuildStep class provides build steps for projects.
37

38 39
    Build steps are the primary way plugin developers can customize
    how their projects (or projects from other plugins) are built.
40

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

44 45
    To change the way your project is built, reimplement
    this class and add your build step to the build step list of the project.
46

47 48 49
    \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
50 51
    project for any information you need.

Eike Ziller's avatar
Eike Ziller committed
52
    \c run() is run via Utils::runAsync in a separate thread. If you need an
53
    event loop, you need to create it yourself.
54 55 56 57 58
*/

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

59 60
    This function is run in the GUI thread. Use it to retrieve any information
    that you need in the run() function.
61 62 63 64 65
*/

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

66 67
    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
68 69
    own thread. If you need an event loop, you need to create one.
    This function should block until the task is done
70 71 72 73 74

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

76 77
    By returning \c true from runInGuiThread(), this function is called in
    the GUI thread. Then the function should not block and instead the
78
    finished() signal should be emitted.
79

80
    \sa runInGuiThread()
81 82 83
*/

/*!
84
    \fn BuildStepConfigWidget *ProjectExplorer::BuildStep::createConfigWidget()
85

86 87
    Returns the Widget shown in the target settings dialog for this build step.
    Ownership is transferred to the caller.
88 89 90 91
*/

/*!
    \fn  void ProjectExplorer::BuildStep::addTask(const ProjectExplorer::Task &task)
92
    Adds \a task.
93 94 95
*/

/*!
96 97
    \fn  void ProjectExplorer::BuildStep::addOutput(const QString &string, ProjectExplorer::BuildStep::OutputFormat format,
              ProjectExplorer::BuildStep::OutputNewlineSetting newlineSetting = DoAppendNewline) const
98

99
    The \a string is added to the generated output, usually in the output pane.
100 101 102
    It should be in plain text, with the format in the parameter.
*/

103 104
/*!
    \fn  void ProjectExplorer::BuildStep::finished()
105
    This signal needs to be emitted if the build step runs in the GUI thread.
106 107
*/

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

110
using namespace ProjectExplorer;
con's avatar
con committed
111

112
BuildStep::BuildStep(BuildStepList *bsl, Core::Id id) :
Daniel Teske's avatar
Daniel Teske committed
113
    ProjectConfiguration(bsl, id), m_enabled(true)
con's avatar
con committed
114
{
Tobias Hunger's avatar
Tobias Hunger committed
115
    Q_ASSERT(bsl);
con's avatar
con committed
116 117
}

Tobias Hunger's avatar
Tobias Hunger committed
118
BuildStep::BuildStep(BuildStepList *bsl, BuildStep *bs) :
Daniel Teske's avatar
Daniel Teske committed
119
    ProjectConfiguration(bsl, bs), m_enabled(bs->m_enabled)
con's avatar
con committed
120
{
Tobias Hunger's avatar
Tobias Hunger committed
121
    Q_ASSERT(bsl);
122
    setDisplayName(bs->displayName());
con's avatar
con committed
123 124
}

Daniel Teske's avatar
Daniel Teske committed
125 126 127 128 129 130 131 132 133 134 135 136 137
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;
}

138
BuildConfiguration *BuildStep::buildConfiguration() const
con's avatar
con committed
139
{
140
    return qobject_cast<BuildConfiguration *>(parent()->parent());
Tobias Hunger's avatar
Tobias Hunger committed
141 142
}

143 144
DeployConfiguration *BuildStep::deployConfiguration() const
{
145
    return qobject_cast<DeployConfiguration *>(parent()->parent());
146 147
}

Daniel Teske's avatar
Daniel Teske committed
148 149 150 151 152
ProjectConfiguration *BuildStep::projectConfiguration() const
{
    return static_cast<ProjectConfiguration *>(parent()->parent());
}

Tobias Hunger's avatar
Tobias Hunger committed
153 154 155
Target *BuildStep::target() const
{
    return qobject_cast<Target *>(parent()->parent()->parent());
con's avatar
con committed
156 157
}

158 159 160 161 162
Project *BuildStep::project() const
{
    return target()->project();
}

163 164 165 166 167 168
void BuildStep::reportRunResult(QFutureInterface<bool> &fi, bool success)
{
    fi.reportResult(success);
    fi.reportFinished();
}

169 170 171 172 173 174
/*!
    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
175 176 177 178 179
bool BuildStep::immutable() const
{
    return false;
}

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

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

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

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

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

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