Commit 8eb08db5 authored by hjk's avatar hjk
Browse files

Add MacroExpander member to ProjectConfiguration



Some derived classes already had one, at times.
Make it uniformly accessible in the base class.

Change-Id: Iccb7ebf9d163daba46a01ae5de150af4a883fad6
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 3ce62fc5
......@@ -58,8 +58,7 @@ namespace ProjectExplorer {
BuildConfiguration::BuildConfiguration(Target *target, Core::Id id) :
ProjectConfiguration(target, id),
m_clearSystemEnvironment(false),
m_macroExpander(0)
m_clearSystemEnvironment(false)
{
Q_ASSERT(target);
BuildStepList *bsl = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_BUILD));
......@@ -82,7 +81,6 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
ProjectConfiguration(target, source),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
m_macroExpander(0),
m_buildDirectory(source->m_buildDirectory)
{
Q_ASSERT(target);
......@@ -96,9 +94,31 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
this, SLOT(handleKitUpdate()));
}
void BuildConfiguration::setupMacroExpander()
{
Utils::MacroExpander *expander = macroExpander();
expander->registerSubProvider(
[this] { return target()->kit()->macroExpander(); });
// Legacy support.
expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[this] { return target()->project()->displayName(); });
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current build"),
[this] { return displayName(); });
expander->registerVariable("sourceDir", tr("Source directory"),
[this] { return target()->project()->projectDirectory().toUserOutput(); });
expander->registerVariable("buildDir", tr("Build directory"),
[this] { return buildDirectory().toUserOutput(); });
}
BuildConfiguration::~BuildConfiguration()
{
delete m_macroExpander;
}
Utils::FileName BuildConfiguration::buildDirectory() const
......@@ -123,26 +143,6 @@ QList<NamedWidget *> BuildConfiguration::createSubConfigWidgets()
return QList<NamedWidget *>() << new BuildEnvironmentWidget(this);
}
Utils::MacroExpander *BuildConfiguration::macroExpander()
{
if (!m_macroExpander) {
m_macroExpander = new ProjectMacroExpander(target()->project()->displayName(),
target()->kit(), displayName());
m_macroExpander->registerSubProvider(
[this]() { return target()->kit()->macroExpander(); });
// Legacy support.
m_macroExpander->registerVariable("sourceDir", tr("Source directory"),
[this]() { return target()->project()->projectDirectory().toUserOutput(); });
m_macroExpander->registerVariable("buildDir", tr("Build directory"),
[this]() { return buildDirectory().toUserOutput(); });
}
return m_macroExpander;
}
QList<Core::Id> BuildConfiguration::knownStepLists() const
{
return Utils::transform(m_stepLists, &BuildStepList::id);
......
......@@ -37,8 +37,6 @@
#include <utils/environment.h>
#include <utils/fileutils.h>
namespace Utils { class MacroExpander; }
namespace ProjectExplorer {
class BuildConfiguration;
......@@ -83,8 +81,6 @@ public:
virtual bool isEnabled() const;
virtual QString disabledReason() const;
Utils::MacroExpander *macroExpander();
enum BuildType {
Unknown,
Debug,
......@@ -111,11 +107,11 @@ private slots:
private:
void emitEnvironmentChanged();
void setupMacroExpander();
bool m_clearSystemEnvironment;
QList<Utils::EnvironmentItem> m_userEnvironmentChanges;
QList<BuildStepList *> m_stepLists;
Utils::MacroExpander *m_macroExpander;
Utils::FileName m_buildDirectory;
Utils::FileName m_lastEmmitedBuildDirectory;
mutable Utils::Environment m_cachedEnvironment;
......
......@@ -40,40 +40,21 @@
#include <QDir>
namespace ProjectExplorer {
namespace Internal {
class FallBackMacroExpander : public Utils::MacroExpander
{
public:
explicit FallBackMacroExpander(const Target *target) : m_target(target) {}
virtual bool resolveMacro(const QString &name, QString *ret) const;
private:
const Target *m_target;
};
bool FallBackMacroExpander::resolveMacro(const QString &name, QString *ret) const
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, Core::Id id) :
RunConfiguration(target, id)
{
if (name == QLatin1String("sourceDir")) {
*ret = m_target->project()->projectDirectory().toUserOutput();
return true;
}
return false;
setupMacroExpander();
}
} // namespace Internal
/// LocalApplicationRunConfiguration
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, Core::Id id) :
RunConfiguration(target, id), m_macroExpander(0)
{ }
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) :
RunConfiguration(target, rc), m_macroExpander(0)
{ }
RunConfiguration(target, rc)
{
setupMacroExpander();
}
LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
{
delete m_macroExpander;
}
void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const
......@@ -81,13 +62,17 @@ void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &
Q_UNUSED(env);
}
Utils::MacroExpander *LocalApplicationRunConfiguration::macroExpander() const
void LocalApplicationRunConfiguration::setupMacroExpander()
{
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->macroExpander();
if (!m_macroExpander)
m_macroExpander = new Internal::FallBackMacroExpander(target());
return m_macroExpander;
// Legacy
macroExpander()->registerSubProvider([this]() -> Utils::MacroExpander * {
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->macroExpander();
return 0;
});
macroExpander()->registerVariable("sourceDir", tr("Project source directory"),
[this] { return target()->project()->projectDirectory().toUserOutput(); });
}
} // namespace ProjectExplorer
......@@ -34,10 +34,7 @@
#include "runconfiguration.h"
#include "applicationlauncher.h"
namespace Utils {
class MacroExpander;
class Environment;
}
namespace Utils { class Environment; }
namespace ProjectExplorer {
......@@ -58,10 +55,8 @@ protected:
explicit LocalApplicationRunConfiguration(Target *target, Core::Id id);
explicit LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc);
Utils::MacroExpander *macroExpander() const;
private:
mutable Utils::MacroExpander *m_macroExpander;
void setupMacroExpander();
};
} // namespace ProjectExplorer
......
......@@ -34,6 +34,7 @@
#include "projectexplorer_export.h"
#include <coreplugin/id.h>
#include <utils/macroexpander.h>
#include <QObject>
#include <QString>
......@@ -64,6 +65,9 @@ public:
// Note: Make sure subclasses call the superclasses' toMap() function!
virtual QVariantMap toMap() const;
Utils::MacroExpander *macroExpander() { return &m_macroExpander; }
const Utils::MacroExpander *macroExpander() const { return &m_macroExpander; }
signals:
void displayNameChanged();
......@@ -75,6 +79,7 @@ private:
Core::Id m_id;
QString m_displayName;
QString m_defaultDisplayName;
Utils::MacroExpander m_macroExpander;
};
// helper functions:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment