Files
qt-creator/src/plugins/qt4projectmanager/qmakestep.cpp

411 lines
12 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "qmakestep.h"
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"
#include "qt4projectmanager.h"
#include "makestep.h"
#include "qtversionmanager.h"
#include "qt4buildconfiguration.h"
2008-12-02 12:01:29 +01:00
#include <coreplugin/icore.h>
2008-12-09 15:25:01 +01:00
#include <utils/qtcassert.h>
2008-12-02 12:01:29 +01:00
#include <QFileDialog>
#include <QDir>
#include <QFile>
#include <QCoreApplication>
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
using namespace ProjectExplorer;
QMakeStep::QMakeStep(ProjectExplorer::BuildConfiguration *bc)
: AbstractMakeStep(bc), m_forced(false)
2008-12-02 12:01:29 +01:00
{
}
QMakeStep::QMakeStep(QMakeStep *bs, ProjectExplorer::BuildConfiguration *bc)
: AbstractMakeStep(bs, bc),
m_forced(false),
m_userArgs(bs->m_userArgs)
{
}
2008-12-02 12:01:29 +01:00
QMakeStep::~QMakeStep()
{
}
2009-11-26 14:43:27 +01:00
Qt4BuildConfiguration *QMakeStep::qt4BuildConfiguration() const
{
return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
}
QStringList QMakeStep::allArguments()
2008-12-02 12:01:29 +01:00
{
QStringList additonalArguments = m_userArgs;
2009-11-26 14:43:27 +01:00
Qt4BuildConfiguration *bc = qt4BuildConfiguration();
2008-12-02 12:01:29 +01:00
QStringList arguments;
arguments << buildConfiguration()->project()->file()->fileName();
2008-12-02 12:01:29 +01:00
arguments << "-r";
if (!additonalArguments.contains("-spec"))
arguments << "-spec" << bc->qtVersion()->mkspec();
#ifdef Q_OS_WIN
2009-11-30 15:59:27 +01:00
ToolChain::ToolChainType type = bc->toolChainType();
if (type == ToolChain::GCC_MAEMO)
arguments << QLatin1String("-unix");
#endif
// Find out what flags we pass on to qmake
QStringList addedUserConfigArguments;
QStringList removedUserConfigArguments;
bc->getConfigCommandLineArguments(&addedUserConfigArguments, &removedUserConfigArguments);
if (!removedUserConfigArguments.isEmpty()) {
foreach (const QString &removedConfig, removedUserConfigArguments)
arguments.append("CONFIG-=" + removedConfig);
}
if (!addedUserConfigArguments.isEmpty()) {
foreach (const QString &addedConfig, addedUserConfigArguments)
arguments.append("CONFIG+=" + addedConfig);
2008-12-02 12:01:29 +01:00
}
if (!additonalArguments.isEmpty())
arguments << additonalArguments;
return arguments;
}
bool QMakeStep::init()
2008-12-02 12:01:29 +01:00
{
2009-11-26 14:43:27 +01:00
Qt4BuildConfiguration *qt4bc = qt4BuildConfiguration();
const QtVersion *qtVersion = qt4bc->qtVersion();
2008-12-02 12:01:29 +01:00
if (!qtVersion->isValid()) {
#if defined(Q_WS_MAC)
2008-12-02 12:01:29 +01:00
emit addToOutputWindow(tr("\n<font color=\"#ff0000\"><b>No valid Qt version set. Set one in Preferences </b></font>\n"));
#else
emit addToOutputWindow(tr("\n<font color=\"#ff0000\"><b>No valid Qt version set. Set one in Tools/Options </b></font>\n"));
#endif
return false;
}
QStringList args = allArguments();
QString workingDirectory = qt4bc->buildDirectory();
2008-12-02 12:01:29 +01:00
QString program = qtVersion->qmakeCommand();
// Check wheter we need to run qmake
m_needToRunQMake = true;
if (QDir(workingDirectory).exists(QLatin1String("Makefile"))) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(workingDirectory);
if (qtVersion->qmakeCommand() == qmakePath) {
2009-11-30 12:45:10 +01:00
m_needToRunQMake = !qt4bc->compareToImportFrom(workingDirectory);
}
2008-12-02 12:01:29 +01:00
}
if (m_forced) {
m_forced = false;
m_needToRunQMake = true;
2008-12-02 12:01:29 +01:00
}
setEnabled(m_needToRunQMake);
setWorkingDirectory(workingDirectory);
setCommand(program);
setArguments(args);
setEnvironment(qt4bc->environment());
2009-11-30 19:16:00 +01:00
setBuildParser(Qt4ProjectManager::Constants::BUILD_PARSER_QMAKE);
return AbstractMakeStep::init();
2008-12-02 12:01:29 +01:00
}
void QMakeStep::run(QFutureInterface<bool> &fi)
{
2009-11-26 14:43:27 +01:00
Qt4Project *pro = qt4BuildConfiguration()->qt4Project();
if (pro->rootProjectNode()->projectType() == ScriptTemplate) {
2008-12-02 12:01:29 +01:00
fi.reportResult(true);
return;
}
if (!m_needToRunQMake) {
2008-12-02 12:01:29 +01:00
emit addToOutputWindow(tr("<font color=\"#0000ff\">Configuration unchanged, skipping QMake step.</font>"));
fi.reportResult(true);
return;
}
2009-11-16 13:01:08 +01:00
AbstractMakeStep::run(fi);
2008-12-02 12:01:29 +01:00
}
QString QMakeStep::name()
{
return Constants::QMAKESTEP;
}
QString QMakeStep::displayName()
{
return "QMake";
}
void QMakeStep::setForced(bool b)
{
m_forced = b;
}
bool QMakeStep::forced()
{
return m_forced;
}
ProjectExplorer::BuildStepConfigWidget *QMakeStep::createConfigWidget()
{
return new QMakeStepConfigWidget(this);
}
bool QMakeStep::immutable() const
{
2009-07-27 16:36:27 +02:00
return false;
2008-12-02 12:01:29 +01:00
}
void QMakeStep::processStartupFailed()
{
m_forced = true;
AbstractProcessStep::processStartupFailed();
}
bool QMakeStep::processFinished(int exitCode, QProcess::ExitStatus status)
{
bool result = AbstractProcessStep::processFinished(exitCode, status);
if (!result)
m_forced = true;
return result;
}
void QMakeStep::setUserArguments(const QStringList &arguments)
{
m_userArgs = arguments;
emit userArgumentsChanged();
}
QStringList QMakeStep::userArguments()
{
return m_userArgs;
}
void QMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
{
m_userArgs = map.value("qmakeArgs").toStringList();
AbstractProcessStep::restoreFromLocalMap(map);
}
void QMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
{
map["qmakeArgs"] = m_userArgs;
AbstractProcessStep::storeIntoLocalMap(map);
}
////
// QMakeStepConfigWidget
////
2008-12-02 12:01:29 +01:00
QMakeStepConfigWidget::QMakeStepConfigWidget(QMakeStep *step)
: BuildStepConfigWidget(), m_step(step), m_ignoreChange(false)
2008-12-02 12:01:29 +01:00
{
m_ui.setupUi(this);
connect(m_ui.qmakeAdditonalArgumentsLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(qmakeArgumentsLineEdited()));
connect(m_ui.buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(buildConfigurationSelected()));
connect(step, SIGNAL(userArgumentsChanged()),
this, SLOT(userArgumentsChanged()));
connect(step->qt4BuildConfiguration(), SIGNAL(qtVersionChanged()),
this, SLOT(qtVersionChanged()));
connect(step->qt4BuildConfiguration(), SIGNAL(qmakeBuildConfigurationChanged()),
this, SLOT(qmakeBuildConfigChanged()));
}
void QMakeStepConfigWidget::init()
{
QString qmakeArgs = ProjectExplorer::Environment::joinArgumentList(m_step->userArguments());
m_ui.qmakeAdditonalArgumentsLineEdit->setText(qmakeArgs);
qmakeBuildConfigChanged();
updateSummaryLabel();
updateEffectiveQMakeCall();
2008-12-02 12:01:29 +01:00
}
QString QMakeStepConfigWidget::summaryText() const
{
return m_summaryText;
}
QString QMakeStepConfigWidget::displayName() const
{
return m_step->displayName();
}
void QMakeStepConfigWidget::qtVersionChanged()
{
updateSummaryLabel();
2009-11-25 20:08:39 +01:00
updateEffectiveQMakeCall();
}
void QMakeStepConfigWidget::qmakeBuildConfigChanged()
{
Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
bool debug = bc->qmakeBuildConfiguration() & QtVersion::DebugBuild;
m_ignoreChange = true;
m_ui.buildConfigurationComboBox->setCurrentIndex(debug? 0 : 1);
m_ignoreChange = false;
updateSummaryLabel();
updateEffectiveQMakeCall();
}
void QMakeStepConfigWidget::userArgumentsChanged()
{
if (m_ignoreChange)
return;
QString qmakeArgs = ProjectExplorer::Environment::joinArgumentList(m_step->userArguments());
m_ui.qmakeAdditonalArgumentsLineEdit->setText(qmakeArgs);
updateSummaryLabel();
updateEffectiveQMakeCall();
}
void QMakeStepConfigWidget::qmakeArgumentsLineEdited()
2008-12-02 12:01:29 +01:00
{
m_ignoreChange = true;
m_step->setUserArguments(
ProjectExplorer::Environment::parseCombinedArgString(m_ui.qmakeAdditonalArgumentsLineEdit->text()));
m_ignoreChange = false;
updateSummaryLabel();
updateEffectiveQMakeCall();
2008-12-02 12:01:29 +01:00
}
void QMakeStepConfigWidget::buildConfigurationSelected()
2008-12-02 12:01:29 +01:00
{
if (m_ignoreChange)
return;
Qt4BuildConfiguration *bc = m_step->qt4BuildConfiguration();
QtVersion::QmakeBuildConfigs buildConfiguration = bc->qmakeBuildConfiguration();
if (m_ui.buildConfigurationComboBox->currentIndex() == 0) { // debug
buildConfiguration = buildConfiguration | QtVersion::DebugBuild;
2008-12-02 12:01:29 +01:00
} else {
buildConfiguration = buildConfiguration & ~QtVersion::DebugBuild;
2008-12-02 12:01:29 +01:00
}
m_ignoreChange = true;
bc->setQMakeBuildConfiguration(buildConfiguration);
m_ignoreChange = false;
2008-12-02 12:01:29 +01:00
updateSummaryLabel();
updateEffectiveQMakeCall();
2008-12-02 12:01:29 +01:00
}
void QMakeStepConfigWidget::updateSummaryLabel()
{
Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
const QtVersion *qtVersion = qt4bc->qtVersion();
if (!qtVersion) {
m_summaryText = tr("<b>QMake:</b> No Qt version set. QMake can not be run.");
emit updateSummary();
return;
}
QStringList args = m_step->allArguments();
// We don't want the full path to the .pro file
const QString projectFileName = m_step->buildConfiguration()->project()->file()->fileName();
int index = args.indexOf(projectFileName);
if (index != -1)
args[index] = QFileInfo(projectFileName).fileName();
// And we only use the .pro filename not the full path
QString program = QFileInfo(qtVersion->qmakeCommand()).fileName();
m_summaryText = tr("<b>QMake:</b> %1 %2").arg(program, args.join(QString(QLatin1Char(' '))));
emit updateSummary();
}
void QMakeStepConfigWidget::updateEffectiveQMakeCall()
{
2009-11-26 14:43:27 +01:00
Qt4BuildConfiguration *qt4bc = m_step->qt4BuildConfiguration();
const QtVersion *qtVersion = qt4bc->qtVersion();
if (qtVersion) {
QString program = QFileInfo(qtVersion->qmakeCommand()).fileName();
m_ui.qmakeArgumentsEdit->setPlainText(program + QLatin1Char(' ') + ProjectExplorer::Environment::joinArgumentList(m_step->allArguments()));
} else {
m_ui.qmakeArgumentsEdit->setPlainText(tr("No valid Qt version set."));
}
2008-12-02 12:01:29 +01:00
}
////
// QMakeStepFactory
////
QMakeStepFactory::QMakeStepFactory()
{
}
QMakeStepFactory::~QMakeStepFactory()
{
}
bool QMakeStepFactory::canCreate(const QString & name) const
{
return (name == Constants::QMAKESTEP);
}
ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildConfiguration *bc, const QString & name) const
{
Q_UNUSED(name)
return new QMakeStep(bc);
}
ProjectExplorer::BuildStep *QMakeStepFactory::clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const
{
return new QMakeStep(static_cast<QMakeStep *>(bs), bc);
}
QStringList QMakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const
{
2009-11-30 19:01:52 +01:00
if (Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(bc))
if (!qt4bc->qmakeStep())
return QStringList() << Constants::QMAKESTEP;
return QStringList();
}
QString QMakeStepFactory::displayNameForName(const QString &name) const
{
Q_UNUSED(name);
return tr("QMake");
}