2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "buildconfiguration.h"
|
|
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-10-27 14:16:28 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2009-09-24 16:02:02 +02:00
|
|
|
|
2010-03-11 17:47:09 +01:00
|
|
|
#include <QtCore/QProcess>
|
|
|
|
|
|
2009-09-21 15:50:27 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2010-01-14 17:41:29 +01:00
|
|
|
namespace {
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2010-03-16 14:36:59 +01:00
|
|
|
IBuildStepFactory *findCloneFactory(BuildConfiguration *parent, StepType type, BuildStep *source)
|
2009-10-27 14:16:28 +01:00
|
|
|
{
|
|
|
|
|
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
|
|
|
|
|
foreach(IBuildStepFactory *factory, factories)
|
2010-03-16 14:36:59 +01:00
|
|
|
if (factory->canClone(parent, type, source))
|
2009-10-27 14:16:28 +01:00
|
|
|
return factory;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 14:36:59 +01:00
|
|
|
IBuildStepFactory *findRestoreFactory(BuildConfiguration *parent, StepType type, const QVariantMap &map)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-18 12:11:04 +01:00
|
|
|
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
|
|
|
|
|
foreach(IBuildStepFactory *factory, factories)
|
2010-03-16 14:36:59 +01:00
|
|
|
if (factory->canRestore(parent, type, map))
|
2010-01-18 12:11:04 +01:00
|
|
|
return factory;
|
|
|
|
|
return 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
const char * const BUILD_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.BuildStepsCount");
|
2010-01-19 16:59:18 +01:00
|
|
|
const char * const BUILD_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.BuildStep.");
|
2010-01-18 12:11:04 +01:00
|
|
|
const char * const CLEAN_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.CleanStepsCount");
|
2010-01-19 16:59:18 +01:00
|
|
|
const char * const CLEAN_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.CleanStep.");
|
2010-03-11 17:47:09 +01:00
|
|
|
const char * const CLEAR_SYSTEM_ENVIRONMENT_KEY("ProjectExplorer.BuildConfiguration.ClearSystemEnvironment");
|
|
|
|
|
const char * const USER_ENVIRONMENT_CHANGES_KEY("ProjectExplorer.BuildConfiguration.UserEnvironmentChanges");
|
2010-01-18 12:11:04 +01:00
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
BuildConfiguration::BuildConfiguration(Target *target, const QString &id) :
|
2010-01-18 12:11:04 +01:00
|
|
|
ProjectConfiguration(id),
|
2010-03-11 17:47:09 +01:00
|
|
|
m_target(target),
|
|
|
|
|
m_clearSystemEnvironment(false)
|
2009-12-08 12:21:11 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
Q_ASSERT(m_target);
|
2009-12-08 12:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *source) :
|
2010-01-18 12:11:04 +01:00
|
|
|
ProjectConfiguration(source),
|
2010-03-11 17:47:09 +01:00
|
|
|
m_target(target),
|
|
|
|
|
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
|
|
|
|
m_userEnvironmentChanges(source->m_userEnvironmentChanges)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
Q_ASSERT(m_target);
|
2009-10-27 14:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildConfiguration::~BuildConfiguration()
|
|
|
|
|
{
|
2010-03-16 14:36:59 +01:00
|
|
|
for (int i = 0; i < LastStepType; ++i) {
|
|
|
|
|
qDeleteAll(m_steps[i]);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
QVariantMap BuildConfiguration::toMap() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-18 12:11:04 +01:00
|
|
|
QVariantMap map(ProjectConfiguration::toMap());
|
2010-03-16 14:36:59 +01:00
|
|
|
map.insert(QLatin1String(BUILD_STEPS_COUNT_KEY), m_steps[Build].count());
|
|
|
|
|
for (int i = 0; i < m_steps[Build].count(); ++i)
|
|
|
|
|
map.insert(QString::fromLatin1(BUILD_STEPS_PREFIX) + QString::number(i), m_steps[Build].at(i)->toMap());
|
|
|
|
|
map.insert(QLatin1String(CLEAN_STEPS_COUNT_KEY), m_steps[Clean].count());
|
|
|
|
|
for (int i = 0; i < m_steps[Clean].count(); ++i)
|
|
|
|
|
map.insert(QString::fromLatin1(CLEAN_STEPS_PREFIX) + QString::number(i), m_steps[Clean].at(i)->toMap());
|
2010-03-11 17:47:09 +01:00
|
|
|
map.insert(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY), m_clearSystemEnvironment);
|
|
|
|
|
map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), EnvironmentItem::toStringList(m_userEnvironmentChanges));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
return map;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
void BuildConfiguration::cloneSteps(BuildConfiguration *source)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(source);
|
2010-03-16 14:36:59 +01:00
|
|
|
for (int i = 0; i < LastStepType; ++i) {
|
|
|
|
|
foreach (BuildStep *originalbs, source->steps(StepType(i))) {
|
|
|
|
|
IBuildStepFactory *factory(findCloneFactory(this, StepType(i), originalbs));
|
|
|
|
|
if (!factory)
|
|
|
|
|
continue;
|
|
|
|
|
BuildStep *clonebs(factory->clone(this, StepType(i), originalbs));
|
|
|
|
|
if (clonebs)
|
|
|
|
|
m_steps[i].append(clonebs);
|
|
|
|
|
}
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-18 12:11:04 +01:00
|
|
|
|
|
|
|
|
bool BuildConfiguration::fromMap(const QVariantMap &map)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!ProjectConfiguration::fromMap(map))
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
int maxI(map.value(QLatin1String(BUILD_STEPS_COUNT_KEY), 0).toInt());
|
|
|
|
|
if (maxI < 0)
|
|
|
|
|
maxI = 0;
|
|
|
|
|
for (int i = 0; i < maxI; ++i) {
|
|
|
|
|
QVariantMap bsData(map.value(QString::fromLatin1(BUILD_STEPS_PREFIX) + QString::number(i)).toMap());
|
2010-02-18 18:37:11 +01:00
|
|
|
if (bsData.isEmpty()) {
|
|
|
|
|
qWarning() << "No buildstep data found (continuing).";
|
2010-01-18 12:11:04 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-03-16 14:36:59 +01:00
|
|
|
IBuildStepFactory *factory(findRestoreFactory(this, Build, bsData));
|
2010-02-18 18:37:11 +01:00
|
|
|
if (!factory) {
|
|
|
|
|
qWarning() << "No factory for buildstep found (continuing).";
|
2010-01-18 12:11:04 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-03-16 14:36:59 +01:00
|
|
|
BuildStep *bs(factory->restore(this, Build, bsData));
|
2010-02-18 18:37:11 +01:00
|
|
|
if (!bs) {
|
|
|
|
|
qWarning() << "Restoration of buildstep failed (continuing).";
|
2010-01-18 12:11:04 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-03-16 14:36:59 +01:00
|
|
|
insertStep(Build, m_steps[Build].count(), bs);
|
2010-01-18 12:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
maxI = map.value(QLatin1String(CLEAN_STEPS_COUNT_KEY), 0).toInt();
|
|
|
|
|
if (maxI < 0)
|
|
|
|
|
maxI = 0;
|
|
|
|
|
for (int i = 0; i < maxI; ++i) {
|
|
|
|
|
QVariantMap bsData(map.value(QString::fromLatin1(CLEAN_STEPS_PREFIX) + QString::number(i)).toMap());
|
2010-02-18 18:37:11 +01:00
|
|
|
if (bsData.isEmpty()) {
|
|
|
|
|
qWarning() << "No cleanstep data found for (continuing).";
|
2010-01-18 12:11:04 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-03-16 14:36:59 +01:00
|
|
|
IBuildStepFactory *factory(findRestoreFactory(this, Clean, bsData));
|
2010-02-18 18:37:11 +01:00
|
|
|
if (!factory) {
|
|
|
|
|
qWarning() << "No factory for cleanstep found (continuing).";
|
2010-01-18 12:11:04 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-03-16 14:36:59 +01:00
|
|
|
BuildStep *bs(factory->restore(this, Clean, bsData));
|
2010-02-18 18:37:11 +01:00
|
|
|
if (!bs) {
|
|
|
|
|
qWarning() << "Restoration of cleanstep failed (continuing).";
|
2010-01-18 12:11:04 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-03-16 14:36:59 +01:00
|
|
|
insertStep(Clean, m_steps[Clean].count(), bs);
|
2010-01-18 12:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-11 17:47:09 +01:00
|
|
|
m_clearSystemEnvironment = map.value(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY)).toBool();
|
|
|
|
|
m_userEnvironmentChanges = EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-09-24 16:02:02 +02:00
|
|
|
|
2010-03-16 14:36:59 +01:00
|
|
|
QList<BuildStep *> BuildConfiguration::steps(StepType type) const
|
2009-10-27 14:16:28 +01:00
|
|
|
{
|
2010-03-16 14:36:59 +01:00
|
|
|
Q_ASSERT(type >= 0 && type < LastStepType);
|
|
|
|
|
return m_steps[type];
|
2009-10-27 14:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-16 14:36:59 +01:00
|
|
|
void BuildConfiguration::insertStep(StepType type, int position, BuildStep *step)
|
2009-10-27 14:16:28 +01:00
|
|
|
{
|
2010-03-16 14:36:59 +01:00
|
|
|
Q_ASSERT(type >= 0 && type < LastStepType);
|
|
|
|
|
m_steps[type].insert(position, step);
|
2009-10-27 14:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-16 14:36:59 +01:00
|
|
|
void BuildConfiguration::removeStep(StepType type, int position)
|
2009-10-27 14:16:28 +01:00
|
|
|
{
|
2010-03-16 14:36:59 +01:00
|
|
|
Q_ASSERT(type >= 0 && type < LastStepType);
|
|
|
|
|
delete m_steps[type].at(position);
|
|
|
|
|
m_steps[type].removeAt(position);
|
2009-10-27 14:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-16 14:36:59 +01:00
|
|
|
void BuildConfiguration::moveStepUp(StepType type, int position)
|
2009-10-27 14:16:28 +01:00
|
|
|
{
|
2010-03-16 14:36:59 +01:00
|
|
|
Q_ASSERT(type >= 0 && type < LastStepType);
|
|
|
|
|
if (position <= 0 || m_steps[type].size() <= 1)
|
2009-11-30 13:26:27 +01:00
|
|
|
return;
|
2010-03-16 14:36:59 +01:00
|
|
|
m_steps[type].swap(position - 1, position);
|
2009-10-27 14:16:28 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
Target *BuildConfiguration::target() const
|
2009-11-23 13:29:45 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return m_target;
|
2009-11-23 13:29:45 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-11 17:47:09 +01:00
|
|
|
Environment BuildConfiguration::baseEnvironment() const
|
|
|
|
|
{
|
|
|
|
|
if (useSystemEnvironment())
|
|
|
|
|
return Environment(QProcess::systemEnvironment());
|
|
|
|
|
return Environment();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BuildConfiguration::baseEnvironmentText() const
|
|
|
|
|
{
|
|
|
|
|
if (useSystemEnvironment())
|
|
|
|
|
return tr("System Environment");
|
|
|
|
|
else
|
|
|
|
|
return tr("Clean Environment");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Environment BuildConfiguration::environment() const
|
|
|
|
|
{
|
|
|
|
|
Environment env = baseEnvironment();
|
|
|
|
|
env.modify(userEnvironmentChanges());
|
|
|
|
|
return env;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildConfiguration::setUseSystemEnvironment(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (useSystemEnvironment() == b)
|
|
|
|
|
return;
|
|
|
|
|
m_clearSystemEnvironment = !b;
|
|
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BuildConfiguration::useSystemEnvironment() const
|
|
|
|
|
{
|
|
|
|
|
return !m_clearSystemEnvironment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<EnvironmentItem> BuildConfiguration::userEnvironmentChanges() const
|
|
|
|
|
{
|
|
|
|
|
return m_userEnvironmentChanges;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
|
|
|
|
|
{
|
|
|
|
|
if (m_userEnvironmentChanges == diff)
|
|
|
|
|
return;
|
|
|
|
|
m_userEnvironmentChanges = diff;
|
|
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-27 14:16:28 +01:00
|
|
|
///
|
|
|
|
|
// IBuildConfigurationFactory
|
|
|
|
|
///
|
2009-09-24 16:02:02 +02:00
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
IBuildConfigurationFactory::IBuildConfigurationFactory(QObject *parent) :
|
|
|
|
|
QObject(parent)
|
2009-09-24 16:02:02 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IBuildConfigurationFactory::~IBuildConfigurationFactory()
|
|
|
|
|
{
|
|
|
|
|
}
|