autotoolsbuildconfiguration.cpp 8.45 KB
Newer Older
1
2
/**************************************************************************
**
hjk's avatar
hjk committed
3
4
5
6
** Copyright (C) 2012 Openismus GmbH.
** Authors: Peter Penz (ppenz@openismus.com)
**          Patricia Santana Cruz (patriciasantanacruz@gmail.com)
** Contact: http://www.qt-project.org/legal
7
**
hjk's avatar
hjk committed
8
** This file is part of Qt Creator.
9
**
hjk's avatar
hjk committed
10
11
12
13
14
15
16
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
17
18
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
19
20
21
22
23
24
25
26
27
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
28
29
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
30
****************************************************************************/
31
32

#include "autotoolsbuildconfiguration.h"
33
#include "autotoolsbuildsettingswidget.h"
34
35
36
37
38
39
40
41
#include "makestep.h"
#include "autotoolsproject.h"
#include "autotoolsprojectconstants.h"
#include "autogenstep.h"
#include "autoreconfstep.h"
#include "configurestep.h"

#include <projectexplorer/buildsteplist.h>
Tobias Hunger's avatar
Tobias Hunger committed
42
#include <projectexplorer/kitinformation.h>
43
#include <projectexplorer/projectexplorerconstants.h>
Tobias Hunger's avatar
Tobias Hunger committed
44
45
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
46
#include <qtsupport/customexecutablerunconfiguration.h>
47
48
#include <utils/qtcassert.h>

49
#include <QInputDialog>
50
51

using namespace AutotoolsProjectManager;
52
using namespace AutotoolsProjectManager::Constants;
53
using namespace Internal;
54
55
using namespace ProjectExplorer;
using namespace ProjectExplorer::Constants;
56
57
58
59

//////////////////////////////////////
// AutotoolsBuildConfiguration class
//////////////////////////////////////
Tobias Hunger's avatar
Tobias Hunger committed
60
AutotoolsBuildConfiguration::AutotoolsBuildConfiguration(ProjectExplorer::Target *parent)
61
    : BuildConfiguration(parent, Core::Id(AUTOTOOLS_BC_ID))
62
{
Tobias Hunger's avatar
Tobias Hunger committed
63
64
65
66
67
    AutotoolsProject *project = qobject_cast<AutotoolsProject *>(parent->project());
    if (project)
        m_buildDirectory = project->defaultBuildDirectory();
}

68
NamedWidget *AutotoolsBuildConfiguration::createConfigWidget()
Tobias Hunger's avatar
Tobias Hunger committed
69
{
70
    return new AutotoolsBuildSettingsWidget(this);
71
72
}

Tobias Hunger's avatar
Tobias Hunger committed
73
AutotoolsBuildConfiguration::AutotoolsBuildConfiguration(ProjectExplorer::Target *parent, const Core::Id id)
74
75
76
77
    : BuildConfiguration(parent, id)
{
}

Tobias Hunger's avatar
Tobias Hunger committed
78
79
AutotoolsBuildConfiguration::AutotoolsBuildConfiguration(ProjectExplorer::Target *parent,
                                                         AutotoolsBuildConfiguration *source)
80
81
82
83
84
85
86
87
    : BuildConfiguration(parent, source),
      m_buildDirectory(source->m_buildDirectory)
{
    cloneSteps(source);
}

QVariantMap AutotoolsBuildConfiguration::toMap() const
{
88
89
    QVariantMap map = BuildConfiguration::toMap();
    map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
90
91
92
93
94
95
96
97
    return map;
}

bool AutotoolsBuildConfiguration::fromMap(const QVariantMap &map)
{
    if (!BuildConfiguration::fromMap(map))
        return false;

Tobias Hunger's avatar
Tobias Hunger committed
98
    m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY)).toString();
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    return true;
}

QString AutotoolsBuildConfiguration::buildDirectory() const
{
    return m_buildDirectory;
}

void AutotoolsBuildConfiguration::setBuildDirectory(const QString &buildDirectory)
{
    if (m_buildDirectory == buildDirectory)
        return;
    m_buildDirectory = buildDirectory;
    emit buildDirectoryChanged();
}

//////////////////////////////////////
// AutotoolsBuildConfiguration class
//////////////////////////////////////
AutotoolsBuildConfigurationFactory::AutotoolsBuildConfigurationFactory(QObject *parent) :
119
    IBuildConfigurationFactory(parent)
120
121
122
{
}

Tobias Hunger's avatar
Tobias Hunger committed
123
QList<Core::Id> AutotoolsBuildConfigurationFactory::availableCreationIds(const Target *parent) const
124
{
Tobias Hunger's avatar
Tobias Hunger committed
125
    if (!canHandle(parent))
126
127
        return QList<Core::Id>();
    return QList<Core::Id>() << Core::Id(AUTOTOOLS_BC_ID);
128
129
}

130
QString AutotoolsBuildConfigurationFactory::displayNameForId(const Core::Id id) const
131
{
132
    if (id == AUTOTOOLS_BC_ID)
133
134
135
136
        return tr("Build");
    return QString();
}

Tobias Hunger's avatar
Tobias Hunger committed
137
bool AutotoolsBuildConfigurationFactory::canCreate(const Target *parent, const Core::Id id) const
138
{
Tobias Hunger's avatar
Tobias Hunger committed
139
    if (!canHandle(parent))
140
        return false;
141
    if (id == AUTOTOOLS_BC_ID)
142
143
144
145
        return true;
    return false;
}

Tobias Hunger's avatar
Tobias Hunger committed
146
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::create(Target *parent, const Core::Id id, const QString &name)
147
148
149
150
{
    if (!canCreate(parent, id))
        return 0;

Tobias Hunger's avatar
Tobias Hunger committed
151
152
    bool ok = true;
    QString buildConfigurationName = name;
153
    if (buildConfigurationName.isNull())
Tobias Hunger's avatar
Tobias Hunger committed
154
155
156
157
158
159
        buildConfigurationName = QInputDialog::getText(0,
                                                       tr("New Configuration"),
                                                       tr("New configuration name:"),
                                                       QLineEdit::Normal,
                                                       QString(), &ok);
    buildConfigurationName = buildConfigurationName.trimmed();
160
161
162
    if (!ok || buildConfigurationName.isEmpty())
        return 0;

Tobias Hunger's avatar
Tobias Hunger committed
163
164
    AutotoolsBuildConfiguration *bc = createDefaultConfiguration(parent);
    bc->setDisplayName(buildConfigurationName);
165
166
167
    return bc;
}

Tobias Hunger's avatar
Tobias Hunger committed
168
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::createDefaultConfiguration(ProjectExplorer::Target *target)
169
170
{
    AutotoolsBuildConfiguration *bc = new AutotoolsBuildConfiguration(target);
171
    BuildStepList *buildSteps = bc->stepList(Core::Id(BUILDSTEPS_BUILD));
172
173
174

    // ### Build Steps Build ###
    // autogen.sh or autoreconf
Tobias Hunger's avatar
Tobias Hunger committed
175
    QFile autogenFile(target->project()->projectDirectory() + QLatin1String("/autogen.sh"));
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
    if (autogenFile.exists()) {
        AutogenStep *autogenStep = new AutogenStep(buildSteps);
        buildSteps->insertStep(0, autogenStep);
    } else {
        AutoreconfStep *autoreconfStep = new AutoreconfStep(buildSteps);
        autoreconfStep->setAdditionalArguments(QLatin1String("--force --install"));
        buildSteps->insertStep(0, autoreconfStep);
    }

    // ./configure.
    ConfigureStep *configureStep = new ConfigureStep(buildSteps);
    buildSteps->insertStep(1, configureStep);

    // make
    MakeStep *makeStep = new MakeStep(buildSteps);
    buildSteps->insertStep(2, makeStep);
    makeStep->setBuildTarget(QLatin1String("all"),  /*on =*/ true);

    // ### Build Steps Clean ###
195
    BuildStepList *cleanSteps = bc->stepList(Core::Id(BUILDSTEPS_CLEAN));
196
197
198
199
200
201
202
203
    MakeStep *cleanMakeStep = new MakeStep(cleanSteps);
    cleanMakeStep->setAdditionalArguments(QLatin1String("clean"));
    cleanMakeStep->setClean(true);
    cleanSteps->insertStep(0, cleanMakeStep);

    return bc;
}

Tobias Hunger's avatar
Tobias Hunger committed
204
205
bool AutotoolsBuildConfigurationFactory::canHandle(const Target *t) const
{
Tobias Hunger's avatar
Tobias Hunger committed
206
    if (!t->project()->supportsKit(t->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
207
        return false;
208
    return t->project()->id() == Constants::AUTOTOOLS_PROJECT_ID;
Tobias Hunger's avatar
Tobias Hunger committed
209
210
211
}

bool AutotoolsBuildConfigurationFactory::canClone(const Target *parent, BuildConfiguration *source) const
212
213
214
215
{
    return canCreate(parent, source->id());
}

216
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::clone(Target *parent, BuildConfiguration *source)
217
218
219
220
221
{
    if (!canClone(parent, source))
        return 0;

    AutotoolsBuildConfiguration *origin = static_cast<AutotoolsBuildConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
222
    return new AutotoolsBuildConfiguration(parent, origin);
223
224
}

Tobias Hunger's avatar
Tobias Hunger committed
225
bool AutotoolsBuildConfigurationFactory::canRestore(const Target *parent, const QVariantMap &map) const
226
{
227
    return canCreate(parent, idFromMap(map));
228
229
}

230
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::restore(Target *parent, const QVariantMap &map)
231
232
233
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
234
    AutotoolsBuildConfiguration *bc = new AutotoolsBuildConfiguration(parent);
235
236
237
238
239
240
    if (bc->fromMap(map))
        return bc;
    delete bc;
    return 0;
}

241
BuildConfiguration::BuildType AutotoolsBuildConfiguration::buildType() const
242
243
244
245
{
    // TODO: Should I return something different from Unknown?
    return Unknown;
}