configurestep.cpp 7.91 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 "configurestep.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 44
#include <QVariantMap>
#include <QDateTime>
#include <QLineEdit>
#include <QFormLayout>
45 46 47 48 49 50 51 52

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

const char CONFIGURE_ADDITIONAL_ARGUMENTS_KEY[] = "AutotoolsProjectManager.ConfigureStep.AdditionalArguments";
const char CONFIGURE_STEP_ID[] = "AutotoolsProjectManager.ConfigureStep";

53 54 55 56 57 58 59 60
/////////////////////
// Helper Function
/////////////////////
static QString projectDirRelativeToBuildDir(BuildConfiguration *bc) {
    const QDir buildDir(bc->buildDirectory().toString());
    QString projDirToBuildDir = buildDir.relativeFilePath(
                bc->target()->project()->projectDirectory().toString());
    if (projDirToBuildDir.isEmpty())
61
        return QString("./");
62 63
    if (!projDirToBuildDir.endsWith('/'))
        projDirToBuildDir.append('/');
64 65 66
    return projDirToBuildDir;
}

67 68 69
////////////////////////////////
// ConfigureStepFactory Class
////////////////////////////////
Tobias Hunger's avatar
Tobias Hunger committed
70 71
ConfigureStepFactory::ConfigureStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ }
72

73
QList<BuildStepInfo> ConfigureStepFactory::availableSteps(BuildStepList *parent) const
74
{
75 76 77
    if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
            || parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
        return {};
78

79
    QString display = tr("Configure", "Display name for AutotoolsProjectManager::ConfigureStep id.");
80
    return {{CONFIGURE_STEP_ID, display}};
81 82
}

83
BuildStep *ConfigureStepFactory::create(BuildStepList *parent, Core::Id id)
84
{
85
    Q_UNUSED(id)
86 87 88 89 90 91 92 93
    return new ConfigureStep(parent);
}

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

Tobias Hunger's avatar
Tobias Hunger committed
94

95 96 97
////////////////////////
// ConfigureStep class
////////////////////////
98
ConfigureStep::ConfigureStep(BuildStepList* bsl) :
Tobias Hunger's avatar
Tobias Hunger committed
99
    AbstractProcessStep(bsl, Core::Id(CONFIGURE_STEP_ID))
100 101 102 103
{
    ctor();
}

Tobias Hunger's avatar
Tobias Hunger committed
104
ConfigureStep::ConfigureStep(BuildStepList *bsl, Core::Id id) : AbstractProcessStep(bsl, id)
105 106 107 108
{
    ctor();
}

Tobias Hunger's avatar
Tobias Hunger committed
109
ConfigureStep::ConfigureStep(BuildStepList *bsl, ConfigureStep *bs) : AbstractProcessStep(bsl, bs),
110 111 112 113 114 115 116 117 118 119
    m_additionalArguments(bs->additionalArguments())
{
    ctor();
}

void ConfigureStep::ctor()
{
    setDefaultDisplayName(tr("Configure"));
}

120
bool ConfigureStep::init(QList<const BuildStep *> &earlierSteps)
121
{
122
    BuildConfiguration *bc = buildConfiguration();
123 124 125 126

    ProcessParameters *pp = processParameters();
    pp->setMacroExpander(bc->macroExpander());
    pp->setEnvironment(bc->environment());
127
    pp->setWorkingDirectory(bc->buildDirectory().toString());
128
    pp->setCommand(projectDirRelativeToBuildDir(bc) + "configure");
129
    pp->setArguments(additionalArguments());
130
    pp->resolveAll();
131

132
    return AbstractProcessStep::init(earlierSteps);
133 134
}

135
void ConfigureStep::run(QFutureInterface<bool>& fi)
136
{
137
    BuildConfiguration *bc = buildConfiguration();
138

139
    //Check whether we need to run configure
140
    const QString projectDir(bc->target()->project()->projectDirectory().toString());
141 142
    const QFileInfo configureInfo(projectDir + "/configure");
    const QFileInfo configStatusInfo(bc->buildDirectory().toString() + "/config.status");
143 144 145 146 147 148 149

    if (!configStatusInfo.exists()
        || configStatusInfo.lastModified() < configureInfo.lastModified()) {
        m_runConfigure = true;
    }

    if (!m_runConfigure) {
150
        emit addOutput(tr("Configuration unchanged, skipping configure step."), BuildStep::OutputFormat::NormalMessage);
151
        reportRunResult(fi, true);
152 153 154 155
        return;
    }

    m_runConfigure = false;
156
    AbstractProcessStep::run(fi);
157 158
}

159
BuildStepConfigWidget *ConfigureStep::createConfigWidget()
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
{
    return new ConfigureStepConfigWidget(this);
}

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

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

    m_additionalArguments = list;
    m_runConfigure = true;

    emit additionalArgumentsChanged(list);
}

180 181 182 183 184
void ConfigureStep::notifyBuildDirectoryChanged()
{
    emit buildDirectoryChanged();
}

185 186 187 188 189 190 191
QString ConfigureStep::additionalArguments() const
{
    return m_additionalArguments;
}

QVariantMap ConfigureStep::toMap() const
{
hjk's avatar
hjk committed
192
    QVariantMap map = AbstractProcessStep::toMap();
193

194
    map.insert(CONFIGURE_ADDITIONAL_ARGUMENTS_KEY, m_additionalArguments);
195 196 197 198 199
    return map;
}

bool ConfigureStep::fromMap(const QVariantMap &map)
{
200
    m_additionalArguments = map.value(CONFIGURE_ADDITIONAL_ARGUMENTS_KEY).toString();
201 202 203 204 205 206 207 208 209

    return BuildStep::fromMap(map);
}

/////////////////////////////////////
// ConfigureStepConfigWidget class
/////////////////////////////////////
ConfigureStepConfigWidget::ConfigureStepConfigWidget(ConfigureStep *configureStep) :
    m_configureStep(configureStep),
Tobias Hunger's avatar
Tobias Hunger committed
210
    m_additionalArguments(new QLineEdit)
211 212 213 214 215 216 217 218 219 220 221
{
    QFormLayout *fl = new QFormLayout(this);
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    setLayout(fl);

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

    updateDetails();

222 223 224 225 226 227
    connect(m_additionalArguments, &QLineEdit::textChanged,
            configureStep, &ConfigureStep::setAdditionalArguments);
    connect(configureStep, &ConfigureStep::additionalArgumentsChanged,
            this, &ConfigureStepConfigWidget::updateDetails);
    connect(configureStep, &ConfigureStep::buildDirectoryChanged,
            this, &ConfigureStepConfigWidget::updateDetails);
228 229 230 231 232 233 234 235 236 237 238 239 240 241
}

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

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

void ConfigureStepConfigWidget::updateDetails()
{
242
    BuildConfiguration *bc = m_configureStep->buildConfiguration();
243 244 245 246

    ProcessParameters param;
    param.setMacroExpander(bc->macroExpander());
    param.setEnvironment(bc->environment());
247
    param.setWorkingDirectory(bc->buildDirectory().toString());
248
    param.setCommand(projectDirRelativeToBuildDir(bc) + "configure");
249
    param.setArguments(m_configureStep->additionalArguments());
250
    m_summaryText = param.summaryInWorkdir(displayName());
251 252
    emit updateSummary();
}