forked from qt-creator/qt-creator
Change-Id: I2e7d81a4efb75877901d29964df4f71314e951b4 Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
274 lines
8.9 KiB
C++
274 lines
8.9 KiB
C++
/**************************************************************************
|
|
**
|
|
** This file is part of Qt Creator
|
|
**
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
|
**
|
|
** Contact: http://www.qt-project.org/
|
|
**
|
|
**
|
|
** 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.
|
|
**
|
|
**
|
|
**************************************************************************/
|
|
|
|
#include "genericbuildconfiguration.h"
|
|
|
|
#include "genericmakestep.h"
|
|
#include "genericproject.h"
|
|
|
|
#include <projectexplorer/buildsteplist.h>
|
|
#include <projectexplorer/profileinformation.h>
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
#include <projectexplorer/toolchain.h>
|
|
#include <utils/pathchooser.h>
|
|
#include <utils/qtcassert.h>
|
|
|
|
#include <QFormLayout>
|
|
#include <QInputDialog>
|
|
|
|
using namespace GenericProjectManager;
|
|
using namespace GenericProjectManager::Internal;
|
|
using ProjectExplorer::BuildConfiguration;
|
|
|
|
namespace {
|
|
const char * const GENERIC_BC_ID("GenericProjectManager.GenericBuildConfiguration");
|
|
|
|
const char * const BUILD_DIRECTORY_KEY("GenericProjectManager.GenericBuildConfiguration.BuildDirectory");
|
|
}
|
|
|
|
GenericBuildConfiguration::GenericBuildConfiguration(ProjectExplorer::Target *parent)
|
|
: BuildConfiguration(parent, Core::Id(GENERIC_BC_ID))
|
|
{
|
|
}
|
|
|
|
GenericBuildConfiguration::GenericBuildConfiguration(ProjectExplorer::Target *parent, const Core::Id id)
|
|
: BuildConfiguration(parent, id)
|
|
{
|
|
}
|
|
|
|
GenericBuildConfiguration::GenericBuildConfiguration(ProjectExplorer::Target *parent, GenericBuildConfiguration *source) :
|
|
BuildConfiguration(parent, source),
|
|
m_buildDirectory(source->m_buildDirectory)
|
|
{
|
|
cloneSteps(source);
|
|
}
|
|
|
|
GenericBuildConfiguration::~GenericBuildConfiguration()
|
|
{
|
|
}
|
|
|
|
QVariantMap GenericBuildConfiguration::toMap() const
|
|
{
|
|
QVariantMap map(BuildConfiguration::toMap());
|
|
map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
|
|
return map;
|
|
}
|
|
|
|
bool GenericBuildConfiguration::fromMap(const QVariantMap &map)
|
|
{
|
|
m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY), target()->project()->projectDirectory()).toString();
|
|
|
|
return BuildConfiguration::fromMap(map);
|
|
}
|
|
|
|
QString GenericBuildConfiguration::buildDirectory() const
|
|
{
|
|
// Convert to absolute path when necessary
|
|
const QDir projectDir(target()->project()->projectDirectory());
|
|
return projectDir.absoluteFilePath(m_buildDirectory);
|
|
}
|
|
|
|
/**
|
|
* Returns the build directory unmodified, instead of making it absolute like
|
|
* buildDirectory() does.
|
|
*/
|
|
QString GenericBuildConfiguration::rawBuildDirectory() const
|
|
{
|
|
return m_buildDirectory;
|
|
}
|
|
|
|
void GenericBuildConfiguration::setBuildDirectory(const QString &buildDirectory)
|
|
{
|
|
if (m_buildDirectory == buildDirectory)
|
|
return;
|
|
m_buildDirectory = buildDirectory;
|
|
emit buildDirectoryChanged();
|
|
}
|
|
|
|
ProjectExplorer::BuildConfigWidget *GenericBuildConfiguration::createConfigWidget()
|
|
{
|
|
return new GenericBuildSettingsWidget;
|
|
}
|
|
|
|
ProjectExplorer::IOutputParser *GenericBuildConfiguration::createOutputParser() const
|
|
{
|
|
ProjectExplorer::ToolChain *tc =
|
|
ProjectExplorer::ToolChainProfileInformation::toolChain(target()->profile());
|
|
return tc ? tc->outputParser() : 0;
|
|
}
|
|
|
|
|
|
/*!
|
|
\class GenericBuildConfigurationFactory
|
|
*/
|
|
|
|
GenericBuildConfigurationFactory::GenericBuildConfigurationFactory(QObject *parent) :
|
|
ProjectExplorer::IBuildConfigurationFactory(parent)
|
|
{
|
|
}
|
|
|
|
GenericBuildConfigurationFactory::~GenericBuildConfigurationFactory()
|
|
{
|
|
}
|
|
|
|
QList<Core::Id> GenericBuildConfigurationFactory::availableCreationIds(const ProjectExplorer::Target *parent) const
|
|
{
|
|
if (!canHandle(parent))
|
|
return QList<Core::Id>();
|
|
return QList<Core::Id>() << Core::Id(GENERIC_BC_ID);
|
|
}
|
|
|
|
QString GenericBuildConfigurationFactory::displayNameForId(const Core::Id id) const
|
|
{
|
|
if (id == GENERIC_BC_ID)
|
|
return tr("Build");
|
|
return QString();
|
|
}
|
|
|
|
bool GenericBuildConfigurationFactory::canCreate(const ProjectExplorer::Target *parent, const Core::Id id) const
|
|
{
|
|
if (!canHandle(parent))
|
|
return false;
|
|
if (id == GENERIC_BC_ID)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
BuildConfiguration *GenericBuildConfigurationFactory::create(ProjectExplorer::Target *parent, const Core::Id id, const QString &name)
|
|
{
|
|
if (!canCreate(parent, id))
|
|
return 0;
|
|
|
|
//TODO asking for name is duplicated everywhere, but maybe more
|
|
// wizards will show up, that incorporate choosing the nam
|
|
bool ok = true;
|
|
QString buildConfigurationName = name;
|
|
if (buildConfigurationName.isEmpty())
|
|
buildConfigurationName = QInputDialog::getText(0,
|
|
tr("New Configuration"),
|
|
tr("New configuration name:"),
|
|
QLineEdit::Normal,
|
|
QString(), &ok);
|
|
buildConfigurationName = buildConfigurationName.trimmed();
|
|
if (!ok || buildConfigurationName.isEmpty())
|
|
return 0;
|
|
|
|
GenericBuildConfiguration *bc = new GenericBuildConfiguration(parent);
|
|
bc->setDisplayName(buildConfigurationName);
|
|
|
|
ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
|
ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
|
|
|
Q_ASSERT(buildSteps);
|
|
GenericMakeStep *makeStep = new GenericMakeStep(buildSteps);
|
|
buildSteps->insertStep(0, makeStep);
|
|
makeStep->setBuildTarget(QLatin1String("all"), /* on = */ true);
|
|
|
|
Q_ASSERT(cleanSteps);
|
|
GenericMakeStep *cleanMakeStep = new GenericMakeStep(cleanSteps);
|
|
cleanSteps->insertStep(0, cleanMakeStep);
|
|
cleanMakeStep->setBuildTarget(QLatin1String("clean"), /* on = */ true);
|
|
cleanMakeStep->setClean(true);
|
|
|
|
return bc;
|
|
}
|
|
|
|
bool GenericBuildConfigurationFactory::canClone(const ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const
|
|
{
|
|
return canCreate(parent, source->id());
|
|
}
|
|
|
|
BuildConfiguration *GenericBuildConfigurationFactory::clone(ProjectExplorer::Target *parent, BuildConfiguration *source)
|
|
{
|
|
if (!canClone(parent, source))
|
|
return 0;
|
|
return new GenericBuildConfiguration(parent, qobject_cast<GenericBuildConfiguration *>(source));
|
|
}
|
|
|
|
bool GenericBuildConfigurationFactory::canRestore(const ProjectExplorer::Target *parent, const QVariantMap &map) const
|
|
{
|
|
return canCreate(parent, ProjectExplorer::idFromMap(map));
|
|
}
|
|
|
|
BuildConfiguration *GenericBuildConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
|
|
{
|
|
if (!canRestore(parent, map))
|
|
return 0;
|
|
GenericBuildConfiguration *bc(new GenericBuildConfiguration(parent));
|
|
if (bc->fromMap(map))
|
|
return bc;
|
|
delete bc;
|
|
return 0;
|
|
}
|
|
|
|
bool GenericBuildConfigurationFactory::canHandle(const ProjectExplorer::Target *t) const
|
|
{
|
|
if (!t->project()->supportsProfile(t->profile()))
|
|
return false;
|
|
return qobject_cast<GenericProject *>(t->project());
|
|
}
|
|
|
|
BuildConfiguration::BuildType GenericBuildConfiguration::buildType() const
|
|
{
|
|
return Unknown;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
// GenericBuildSettingsWidget
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
GenericBuildSettingsWidget::GenericBuildSettingsWidget() : m_buildConfiguration(0)
|
|
{
|
|
QFormLayout *fl = new QFormLayout(this);
|
|
fl->setContentsMargins(0, -1, 0, -1);
|
|
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
|
|
|
// build directory
|
|
m_pathChooser = new Utils::PathChooser(this);
|
|
m_pathChooser->setEnabled(true);
|
|
fl->addRow(tr("Build directory:"), m_pathChooser);
|
|
connect(m_pathChooser, SIGNAL(changed(QString)), this, SLOT(buildDirectoryChanged()));
|
|
}
|
|
|
|
QString GenericBuildSettingsWidget::displayName() const
|
|
{ return tr("Generic Manager"); }
|
|
|
|
void GenericBuildSettingsWidget::init(BuildConfiguration *bc)
|
|
{
|
|
m_buildConfiguration = static_cast<GenericBuildConfiguration *>(bc);
|
|
m_pathChooser->setBaseDirectory(bc->target()->project()->projectDirectory());
|
|
m_pathChooser->setPath(m_buildConfiguration->rawBuildDirectory());
|
|
}
|
|
|
|
void GenericBuildSettingsWidget::buildDirectoryChanged()
|
|
{
|
|
m_buildConfiguration->setBuildDirectory(m_pathChooser->rawPath());
|
|
}
|