2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
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
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
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"
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
#include "buildmanager.h"
|
|
|
|
|
#include "buildsteplist.h"
|
|
|
|
|
#include "projectexplorer.h"
|
|
|
|
|
#include "projectexplorerconstants.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "profilemanager.h"
|
2010-07-16 14:00:41 +02:00
|
|
|
#include "target.h"
|
2010-09-22 15:14:07 +02:00
|
|
|
#include "project.h"
|
2010-07-16 14:00:41 +02:00
|
|
|
|
2010-11-12 17:23:55 +01:00
|
|
|
#include <coreplugin/variablemanager.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2010-11-12 17:23:55 +01:00
|
|
|
|
2011-12-19 12:06:44 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-08-18 13:46:52 +02:00
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QProcess>
|
2010-03-11 17:47:09 +01:00
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
static const char BUILD_STEP_LIST_COUNT[] = "ProjectExplorer.BuildConfiguration.BuildStepListCount";
|
|
|
|
|
static const char BUILD_STEP_LIST_PREFIX[] = "ProjectExplorer.BuildConfiguration.BuildStepList.";
|
|
|
|
|
static const char CLEAR_SYSTEM_ENVIRONMENT_KEY[] = "ProjectExplorer.BuildConfiguration.ClearSystemEnvironment";
|
|
|
|
|
static const char USER_ENVIRONMENT_CHANGES_KEY[] = "ProjectExplorer.BuildConfiguration.UserEnvironmentChanges";
|
2009-09-21 15:50:27 +02:00
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
class BuildConfigMacroExpander : public Utils::AbstractQtcMacroExpander {
|
|
|
|
|
public:
|
|
|
|
|
explicit BuildConfigMacroExpander(const BuildConfiguration *bc) : m_bc(bc) {}
|
|
|
|
|
virtual bool resolveMacro(const QString &name, QString *ret);
|
|
|
|
|
private:
|
|
|
|
|
const BuildConfiguration *m_bc;
|
|
|
|
|
};
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
bool BuildConfigMacroExpander::resolveMacro(const QString &name, QString *ret)
|
|
|
|
|
{
|
|
|
|
|
if (name == QLatin1String("sourceDir")) {
|
|
|
|
|
*ret = QDir::toNativeSeparators(m_bc->target()->project()->projectDirectory());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (name == QLatin1String("buildDir")) {
|
|
|
|
|
*ret = QDir::toNativeSeparators(m_bc->buildDirectory());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-12-21 11:29:35 +01:00
|
|
|
*ret = Core::VariableManager::instance()->value(name.toUtf8());
|
2011-08-18 13:46:52 +02:00
|
|
|
return !ret->isEmpty();
|
|
|
|
|
}
|
|
|
|
|
} // namespace Internal
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
BuildConfiguration::BuildConfiguration(Target *target, const Core::Id id) :
|
2010-07-16 14:00:41 +02:00
|
|
|
ProjectConfiguration(target, id),
|
2010-11-12 17:23:55 +01:00
|
|
|
m_clearSystemEnvironment(false),
|
2011-08-18 13:46:52 +02:00
|
|
|
m_macroExpander(0)
|
2009-12-08 12:21:11 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(target);
|
2012-03-15 17:17:40 +01:00
|
|
|
BuildStepList *bsl = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_BUILD));
|
2010-07-16 14:00:41 +02:00
|
|
|
//: Display name of the build build step list. Used as part of the labels in the project window.
|
2010-08-19 12:26:21 +02:00
|
|
|
bsl->setDefaultDisplayName(tr("Build"));
|
2010-07-16 14:00:41 +02:00
|
|
|
m_stepLists.append(bsl);
|
2012-03-15 17:17:40 +01:00
|
|
|
bsl = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_CLEAN));
|
2010-07-16 14:00:41 +02:00
|
|
|
//: Display name of the clean build step list. Used as part of the labels in the project window.
|
2010-08-19 12:26:21 +02:00
|
|
|
bsl->setDefaultDisplayName(tr("Clean"));
|
2010-07-16 14:00:41 +02:00
|
|
|
m_stepLists.append(bsl);
|
2011-03-24 11:58:40 +01:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
connect(ProfileManager::instance(), SIGNAL(profileUpdated(ProjectExplorer::Profile*)),
|
|
|
|
|
this, SLOT(handleProfileUpdate(ProjectExplorer::Profile*)));
|
2009-12-08 12:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *source) :
|
2010-07-16 14:00:41 +02:00
|
|
|
ProjectConfiguration(target, source),
|
2010-03-11 17:47:09 +01:00
|
|
|
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
2010-11-12 17:23:55 +01:00
|
|
|
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
|
2011-08-18 13:46:52 +02:00
|
|
|
m_macroExpander(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(target);
|
|
|
|
|
// Do not clone stepLists here, do that in the derived constructor instead
|
|
|
|
|
// otherwise BuildStepFactories might reject to set up a BuildStep for us
|
|
|
|
|
// since we are not yet the derived class!
|
2011-03-24 11:58:40 +01:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
connect(ProfileManager::instance(), SIGNAL(profileUpdated(ProjectExplorer::Profile*)),
|
|
|
|
|
this, SLOT(handleProfileUpdate(ProjectExplorer::Profile*)));
|
2009-10-27 14:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildConfiguration::~BuildConfiguration()
|
2011-08-18 13:46:52 +02:00
|
|
|
{
|
|
|
|
|
delete m_macroExpander;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::AbstractMacroExpander *BuildConfiguration::macroExpander()
|
|
|
|
|
{
|
|
|
|
|
if (!m_macroExpander)
|
|
|
|
|
m_macroExpander = new Internal::BuildConfigMacroExpander(this);
|
|
|
|
|
return m_macroExpander;
|
|
|
|
|
}
|
2010-07-16 14:00:41 +02:00
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
QList<Core::Id> BuildConfiguration::knownStepLists() const
|
2009-10-27 14:16:28 +01:00
|
|
|
{
|
2012-03-15 17:17:40 +01:00
|
|
|
QList<Core::Id> result;
|
2010-07-16 14:00:41 +02:00
|
|
|
foreach (BuildStepList *list, m_stepLists)
|
|
|
|
|
result.append(list->id());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
BuildStepList *BuildConfiguration::stepList(Core::Id id) const
|
2010-07-16 14:00:41 +02:00
|
|
|
{
|
|
|
|
|
foreach (BuildStepList *list, m_stepLists)
|
|
|
|
|
if (id == list->id())
|
|
|
|
|
return list;
|
|
|
|
|
return 0;
|
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-11 17:47:09 +01:00
|
|
|
map.insert(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY), m_clearSystemEnvironment);
|
2010-09-23 10:35:23 +02:00
|
|
|
map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
map.insert(QLatin1String(BUILD_STEP_LIST_COUNT), m_stepLists.count());
|
|
|
|
|
for (int i = 0; i < m_stepLists.count(); ++i)
|
2010-08-02 14:29:32 +02:00
|
|
|
map.insert(QLatin1String(BUILD_STEP_LIST_PREFIX) + QString::number(i), m_stepLists.at(i)->toMap());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
return map;
|
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-03-11 17:47:09 +01:00
|
|
|
m_clearSystemEnvironment = map.value(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY)).toBool();
|
2010-09-23 10:35:23 +02:00
|
|
|
m_userEnvironmentChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
|
2010-03-11 17:47:09 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
qDeleteAll(m_stepLists);
|
|
|
|
|
m_stepLists.clear();
|
2009-10-27 14:16:28 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
int maxI = map.value(QLatin1String(BUILD_STEP_LIST_COUNT), 0).toInt();
|
|
|
|
|
for (int i = 0; i < maxI; ++i) {
|
2010-08-02 14:29:32 +02:00
|
|
|
QVariantMap data = map.value(QLatin1String(BUILD_STEP_LIST_PREFIX) + QString::number(i)).toMap();
|
2010-07-16 14:00:41 +02:00
|
|
|
if (data.isEmpty()) {
|
|
|
|
|
qWarning() << "No data for build step list" << i << "found!";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
BuildStepList *list = new BuildStepList(this, data);
|
|
|
|
|
if (list->isNull()) {
|
|
|
|
|
qWarning() << "Failed to restore build step list" << i;
|
|
|
|
|
delete list;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-08-03 15:24:33 +02:00
|
|
|
if (list->id() == Constants::BUILDSTEPS_BUILD)
|
2011-11-22 09:57:27 +01:00
|
|
|
list->setDefaultDisplayName(tr("Build"));
|
2012-08-03 15:24:33 +02:00
|
|
|
else if (list->id() == Constants::BUILDSTEPS_CLEAN)
|
2011-11-22 09:57:27 +01:00
|
|
|
list->setDefaultDisplayName(tr("Clean"));
|
2010-07-16 14:00:41 +02:00
|
|
|
m_stepLists.append(list);
|
|
|
|
|
}
|
2010-04-13 15:04:21 +02:00
|
|
|
|
2012-05-03 17:05:38 +02:00
|
|
|
// We currently assume there to be at least a clean and build list!
|
2012-03-15 17:17:40 +01:00
|
|
|
QTC_CHECK(knownStepLists().contains(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD)));
|
|
|
|
|
QTC_CHECK(knownStepLists().contains(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN)));
|
2010-04-13 15:04:21 +02:00
|
|
|
|
2010-08-19 12:26:21 +02:00
|
|
|
return ProjectConfiguration::fromMap(map);
|
2009-10-27 14:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
void BuildConfiguration::handleProfileUpdate(ProjectExplorer::Profile *p)
|
2011-03-24 14:35:03 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (p != target()->profile())
|
2011-03-24 14:35:03 +01:00
|
|
|
return;
|
2012-04-24 15:49:09 +02:00
|
|
|
emit environmentChanged();
|
2011-03-24 14:35:03 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
Target *BuildConfiguration::target() const
|
2009-11-23 13:29:45 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
return static_cast<Target *>(parent());
|
2009-11-23 13:29:45 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment BuildConfiguration::baseEnvironment() const
|
2010-03-11 17:47:09 +01:00
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment result;
|
2010-03-11 17:47:09 +01:00
|
|
|
if (useSystemEnvironment())
|
2012-04-30 19:01:26 +02:00
|
|
|
result = Utils::Environment::systemEnvironment();
|
2010-09-22 15:14:07 +02:00
|
|
|
return result;
|
2010-03-11 17:47:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BuildConfiguration::baseEnvironmentText() const
|
|
|
|
|
{
|
|
|
|
|
if (useSystemEnvironment())
|
|
|
|
|
return tr("System Environment");
|
|
|
|
|
else
|
|
|
|
|
return tr("Clean Environment");
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment BuildConfiguration::environment() const
|
2010-03-11 17:47:09 +01:00
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment env = baseEnvironment();
|
2010-03-11 17:47:09 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
QList<Utils::EnvironmentItem> BuildConfiguration::userEnvironmentChanges() const
|
2010-03-11 17:47:09 +01:00
|
|
|
{
|
|
|
|
|
return m_userEnvironmentChanges;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
void BuildConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
|
2010-03-11 17:47:09 +01:00
|
|
|
{
|
|
|
|
|
if (m_userEnvironmentChanges == diff)
|
|
|
|
|
return;
|
|
|
|
|
m_userEnvironmentChanges = diff;
|
|
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
void BuildConfiguration::cloneSteps(BuildConfiguration *source)
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_stepLists);
|
|
|
|
|
m_stepLists.clear();
|
|
|
|
|
foreach (BuildStepList *bsl, source->m_stepLists) {
|
|
|
|
|
BuildStepList *newBsl = new BuildStepList(this, bsl);
|
2010-08-30 12:25:27 +02:00
|
|
|
newBsl->cloneSteps(bsl);
|
2010-07-16 14:00:41 +02:00
|
|
|
m_stepLists.append(newBsl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-19 15:46:01 +01:00
|
|
|
bool BuildConfiguration::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-26 15:56:36 +02:00
|
|
|
QString BuildConfiguration::disabledReason() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
2010-07-16 14:00:41 +02:00
|
|
|
{ }
|
2009-09-24 16:02:02 +02:00
|
|
|
|
|
|
|
|
IBuildConfigurationFactory::~IBuildConfigurationFactory()
|
2010-07-16 14:00:41 +02:00
|
|
|
{ }
|
2011-08-18 13:46:52 +02:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
IBuildConfigurationFactory *IBuildConfigurationFactory::find(Target *parent, const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
QList<IBuildConfigurationFactory *> factories
|
|
|
|
|
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
|
|
|
|
|
foreach (IBuildConfigurationFactory *factory, factories) {
|
|
|
|
|
if (factory->canRestore(parent, map))
|
|
|
|
|
return factory;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent)
|
|
|
|
|
{
|
|
|
|
|
QList<IBuildConfigurationFactory *> factories
|
|
|
|
|
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
|
|
|
|
|
foreach (IBuildConfigurationFactory *factory, factories) {
|
|
|
|
|
if (!factory->availableCreationIds(parent).isEmpty())
|
|
|
|
|
return factory;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
} // namespace ProjectExplorer
|