autoreconfstep.cpp 7.11 KB
Newer Older
1
/****************************************************************************
2
**
3 4 5 6
** Copyright (C) 2016 Openismus GmbH.
** Author: Peter Penz (ppenz@openismus.com)
** Author: Patricia Santana Cruz (patriciasantanacruz@gmail.com)
** Contact: https://www.qt.io/licensing/
7
**
hjk's avatar
hjk committed
8
** This file is part of Qt Creator.
9
**
hjk's avatar
hjk committed
10 11 12 13
** 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
14 15 16
** 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.
17
**
18 19 20 21 22 23 24
** 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.
25
**
hjk's avatar
hjk committed
26
****************************************************************************/
27 28 29 30 31 32 33

#include "autoreconfstep.h"
#include "autotoolsproject.h"
#include "autotoolsbuildconfiguration.h"
#include "autotoolsprojectconstants.h"

#include <projectexplorer/buildsteplist.h>
Tobias Hunger's avatar
Tobias Hunger committed
34
#include <projectexplorer/target.h>
35 36 37 38 39 40
#include <projectexplorer/toolchain.h>
#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcprocess.h>

41 42 43
#include <QVariantMap>
#include <QLineEdit>
#include <QFormLayout>
44 45 46 47 48 49 50 51 52 53 54

using namespace AutotoolsProjectManager;
using namespace AutotoolsProjectManager::Internal;
using namespace ProjectExplorer;

const char AUTORECONF_STEP_ID[] = "AutotoolsProjectManager.AutoreconfStep";
const char AUTORECONF_ADDITIONAL_ARGUMENTS_KEY[] = "AutotoolsProjectManager.AutoreconfStep.AdditionalArguments";

////////////////////////////////
// AutoreconfStepFactory class
////////////////////////////////
Tobias Hunger's avatar
Tobias Hunger committed
55 56
AutoreconfStepFactory::AutoreconfStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ }
57

58
QList<BuildStepInfo> AutoreconfStepFactory::availableSteps(BuildStepList *parent) const
59
{
60 61 62
    if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
            || parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
        return {};
63

64
    QString display = tr("Autoreconf", "Display name for AutotoolsProjectManager::AutoreconfStep id.");
65
    return {{AUTORECONF_STEP_ID, display}};
66 67
}

68
BuildStep *AutoreconfStepFactory::create(BuildStepList *parent, Core::Id id)
69
{
70
    Q_UNUSED(id);
71 72 73 74 75 76 77 78 79 80 81
    return new AutoreconfStep(parent);
}

BuildStep *AutoreconfStepFactory::clone(BuildStepList *parent, BuildStep *source)
{
    return new AutoreconfStep(parent, static_cast<AutoreconfStep *>(source));
}

/////////////////////////
// AutoreconfStep class
/////////////////////////
82
AutoreconfStep::AutoreconfStep(BuildStepList *bsl) :
Tobias Hunger's avatar
Tobias Hunger committed
83
    AbstractProcessStep(bsl, Core::Id(AUTORECONF_STEP_ID))
84 85 86 87
{
    ctor();
}

Tobias Hunger's avatar
Tobias Hunger committed
88
AutoreconfStep::AutoreconfStep(BuildStepList *bsl, Core::Id id) : AbstractProcessStep(bsl, id)
89 90 91 92
{
    ctor();
}

93
AutoreconfStep::AutoreconfStep(BuildStepList *bsl, AutoreconfStep *bs) :
94 95 96 97 98 99 100 101 102 103 104
    AbstractProcessStep(bsl, bs),
    m_additionalArguments(bs->additionalArguments())
{
    ctor();
}

void AutoreconfStep::ctor()
{
    setDefaultDisplayName(tr("Autoreconf"));
}

105
bool AutoreconfStep::init(QList<const BuildStep *> &earlierSteps)
106
{
107
    BuildConfiguration *bc = buildConfiguration();
108 109 110 111

    ProcessParameters *pp = processParameters();
    pp->setMacroExpander(bc->macroExpander());
    pp->setEnvironment(bc->environment());
112 113
    const QString projectDir(bc->target()->project()->projectDirectory().toString());
    pp->setWorkingDirectory(projectDir);
114
    pp->setCommand("autoreconf");
115
    pp->setArguments(additionalArguments());
116
    pp->resolveAll();
117

118
    return AbstractProcessStep::init(earlierSteps);
119 120
}

121
void AutoreconfStep::run(QFutureInterface<bool> &fi)
122
{
123
    BuildConfiguration *bc = buildConfiguration();
124

125
    // Check whether we need to run autoreconf
126
    const QString projectDir(bc->target()->project()->projectDirectory().toString());
127

128
    if (!QFileInfo::exists(projectDir + "/configure"))
129 130 131
        m_runAutoreconf = true;

    if (!m_runAutoreconf) {
132
        emit addOutput(tr("Configuration unchanged, skipping autoreconf step."), BuildStep::OutputFormat::NormalMessage);
133
        reportRunResult(fi, true);
134 135 136 137
        return;
    }

    m_runAutoreconf = false;
138
    AbstractProcessStep::run(fi);
139 140
}

141
BuildStepConfigWidget *AutoreconfStep::createConfigWidget()
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
{
    return new AutoreconfStepConfigWidget(this);
}

bool AutoreconfStep::immutable() const
{
    return false;
}

void AutoreconfStep::setAdditionalArguments(const QString &list)
{
    if (list == m_additionalArguments)
        return;

    m_additionalArguments = list;
    m_runAutoreconf = true;

    emit additionalArgumentsChanged(list);
}

QString AutoreconfStep::additionalArguments() const
{
    return m_additionalArguments;
}

QVariantMap AutoreconfStep::toMap() const
{
hjk's avatar
hjk committed
169
    QVariantMap map = AbstractProcessStep::toMap();
170

171
    map.insert(AUTORECONF_ADDITIONAL_ARGUMENTS_KEY, m_additionalArguments);
172 173 174 175 176
    return map;
}

bool AutoreconfStep::fromMap(const QVariantMap &map)
{
177
    m_additionalArguments = map.value(AUTORECONF_ADDITIONAL_ARGUMENTS_KEY).toString();
178 179 180 181 182 183 184 185 186

    return BuildStep::fromMap(map);
}

//////////////////////////////////////
// AutoreconfStepConfigWidget class
//////////////////////////////////////
AutoreconfStepConfigWidget::AutoreconfStepConfigWidget(AutoreconfStep *autoreconfStep) :
    m_autoreconfStep(autoreconfStep),
Tobias Hunger's avatar
Tobias Hunger committed
187
    m_additionalArguments(new QLineEdit(this))
188 189 190 191 192 193 194 195 196 197 198
{
    QFormLayout *fl = new QFormLayout(this);
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    setLayout(fl);

    fl->addRow(tr("Arguments:"), m_additionalArguments);
    m_additionalArguments->setText(m_autoreconfStep->additionalArguments());

    updateDetails();

199 200 201 202
    connect(m_additionalArguments, &QLineEdit::textChanged,
            autoreconfStep, &AutoreconfStep::setAdditionalArguments);
    connect(autoreconfStep, &AutoreconfStep::additionalArgumentsChanged,
            this, &AutoreconfStepConfigWidget::updateDetails);
203 204 205 206 207 208 209 210 211 212 213 214 215 216
}

QString AutoreconfStepConfigWidget::displayName() const
{
    return tr("Autoreconf", "AutotoolsProjectManager::AutoreconfStepConfigWidget display name.");
}

QString AutoreconfStepConfigWidget::summaryText() const
{
    return m_summaryText;
}

void AutoreconfStepConfigWidget::updateDetails()
{
217
    BuildConfiguration *bc = m_autoreconfStep->buildConfiguration();
218 219 220 221

    ProcessParameters param;
    param.setMacroExpander(bc->macroExpander());
    param.setEnvironment(bc->environment());
222 223
    const QString projectDir(bc->target()->project()->projectDirectory().toString());
    param.setWorkingDirectory(projectDir);
224
    param.setCommand("autoreconf");
225 226 227 228
    param.setArguments(m_autoreconfStep->additionalArguments());
    m_summaryText = param.summary(displayName());
    emit updateSummary();
}