autotoolsbuildconfiguration.cpp 8.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010-2011 Openismus GmbH.
**   Authors: Peter Penz (ppenz@openismus.com)
**            Patricia Santana Cruz (patriciasantanacruz@gmail.com)
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/

#include "autotoolsbuildconfiguration.h"
#include "makestep.h"
#include "autotoolsproject.h"
#include "autotoolstarget.h"
#include "autotoolsprojectconstants.h"
#include "autogenstep.h"
#include "autoreconfstep.h"
#include "configurestep.h"

#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/projectexplorerconstants.h>
47
#include <qtsupport/customexecutablerunconfiguration.h>
48 49
#include <utils/qtcassert.h>

50
#include <QInputDialog>
51 52

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

//////////////////////////////////////
// AutotoolsBuildConfiguration class
//////////////////////////////////////
AutotoolsBuildConfiguration::AutotoolsBuildConfiguration(AutotoolsTarget *parent)
62
    : BuildConfiguration(parent, Core::Id(AUTOTOOLS_BC_ID))
63 64 65 66
{
    m_buildDirectory = autotoolsTarget()->defaultBuildDirectory();
}

67
AutotoolsBuildConfiguration::AutotoolsBuildConfiguration(AutotoolsTarget *parent, const Core::Id id)
68 69 70 71 72 73 74 75 76 77 78 79 80
    : BuildConfiguration(parent, id)
{
}

AutotoolsBuildConfiguration::AutotoolsBuildConfiguration(AutotoolsTarget *parent, AutotoolsBuildConfiguration *source)
    : BuildConfiguration(parent, source),
      m_buildDirectory(source->m_buildDirectory)
{
    cloneSteps(source);
}

QVariantMap AutotoolsBuildConfiguration::toMap() const
{
81 82
    QVariantMap map = BuildConfiguration::toMap();
    map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
83 84 85 86 87 88 89 90
    return map;
}

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

91
    m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY), autotoolsTarget()->defaultBuildDirectory()).toString();
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    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();
}

AutotoolsTarget *AutotoolsBuildConfiguration::autotoolsTarget() const
{
    return static_cast<AutotoolsTarget *>(target());
}

113
IOutputParser *AutotoolsBuildConfiguration::createOutputParser() const
114
{
115
    ToolChain *tc = autotoolsTarget()->autotoolsProject()->toolChain();
116 117 118 119 120 121 122 123 124
    if (tc)
        return tc->outputParser();
    return 0;
}

//////////////////////////////////////
// AutotoolsBuildConfiguration class
//////////////////////////////////////
AutotoolsBuildConfigurationFactory::AutotoolsBuildConfigurationFactory(QObject *parent) :
125
    IBuildConfigurationFactory(parent)
126 127 128
{
}

129
QList<Core::Id> AutotoolsBuildConfigurationFactory::availableCreationIds(Target *parent) const
130 131
{
    if (!qobject_cast<AutotoolsTarget *>(parent))
132 133
        return QList<Core::Id>();
    return QList<Core::Id>() << Core::Id(AUTOTOOLS_BC_ID);
134 135
}

136
QString AutotoolsBuildConfigurationFactory::displayNameForId(const Core::Id id) const
137
{
138
    if (id == Core::Id(AUTOTOOLS_BC_ID))
139 140 141 142
        return tr("Build");
    return QString();
}

143
bool AutotoolsBuildConfigurationFactory::canCreate(Target *parent, const Core::Id id) const
144 145 146
{
    if (!qobject_cast<AutotoolsTarget *>(parent))
        return false;
147
    if (id == Core::Id(AUTOTOOLS_BC_ID))
148 149 150 151
        return true;
    return false;
}

152
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::create(Target *parent, const Core::Id id)
153 154 155 156
{
    if (!canCreate(parent, id))
        return 0;

hjk's avatar
hjk committed
157 158
    AutotoolsTarget *t = static_cast<AutotoolsTarget *>(parent);
    AutotoolsBuildConfiguration *bc = createDefaultConfiguration(t);
159 160 161 162 163 164 165 166 167 168 169 170 171 172

    bool ok;
    QString buildConfigurationName = QInputDialog::getText(0,
                          tr("New Configuration"),
                          tr("New configuration name:"),
                          QLineEdit::Normal,
                          QString(),
                          &ok);

    if (!ok || buildConfigurationName.isEmpty())
        return 0;
    bc->setDisplayName(buildConfigurationName);

    t->addBuildConfiguration(bc);
173
    t->addDeployConfiguration(t->createDeployConfiguration(Core::Id(DEFAULT_DEPLOYCONFIGURATION_ID)));
174 175
    // User needs to choose where the executable file is.
    // TODO: Parse the file in *Anjuta style* to be able to add custom RunConfigurations.
176
    t->addRunConfiguration(new QtSupport::CustomExecutableRunConfiguration(t));
177 178 179 180 181 182 183

    return bc;
}

AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::createDefaultConfiguration(AutotoolsTarget *target) const
{
    AutotoolsBuildConfiguration *bc = new AutotoolsBuildConfiguration(target);
184
    BuildStepList *buildSteps = bc->stepList(Core::Id(BUILDSTEPS_BUILD));
185 186 187

    // ### Build Steps Build ###
    // autogen.sh or autoreconf
188
    QFile autogenFile(target->autotoolsProject()->projectDirectory() + QLatin1String("/autogen.sh"));
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    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 ###
208
    BuildStepList *cleanSteps = bc->stepList(Core::Id(BUILDSTEPS_CLEAN));
209 210 211 212 213 214 215 216
    MakeStep *cleanMakeStep = new MakeStep(cleanSteps);
    cleanMakeStep->setAdditionalArguments(QLatin1String("clean"));
    cleanMakeStep->setClean(true);
    cleanSteps->insertStep(0, cleanMakeStep);

    return bc;
}

217
bool AutotoolsBuildConfigurationFactory::canClone(Target *parent, BuildConfiguration *source) const
218 219 220 221
{
    return canCreate(parent, source->id());
}

222
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::clone(Target *parent, BuildConfiguration *source)
223 224 225 226 227 228 229 230 231
{
    if (!canClone(parent, source))
        return 0;

    AutotoolsBuildConfiguration *origin = static_cast<AutotoolsBuildConfiguration *>(source);
    AutotoolsTarget *target(static_cast<AutotoolsTarget *>(parent));
    return new AutotoolsBuildConfiguration(target, origin);
}

232
bool AutotoolsBuildConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
233
{
234
    return canCreate(parent, idFromMap(map));
235 236
}

237
AutotoolsBuildConfiguration *AutotoolsBuildConfigurationFactory::restore(Target *parent, const QVariantMap &map)
238 239 240 241 242 243 244 245 246 247 248
{
    if (!canRestore(parent, map))
        return 0;
    AutotoolsTarget *target(static_cast<AutotoolsTarget *>(parent));
    AutotoolsBuildConfiguration *bc = new AutotoolsBuildConfiguration(target);
    if (bc->fromMap(map))
        return bc;
    delete bc;
    return 0;
}

249
BuildConfiguration::BuildType AutotoolsBuildConfiguration::buildType() const
250 251 252 253
{
    // TODO: Should I return something different from Unknown?
    return Unknown;
}