forked from qt-creator/qt-creator
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: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -58,8 +58,7 @@ namespace ProjectExplorer {
|
|||||||
|
|
||||||
BuildConfiguration::BuildConfiguration(Target *target, Core::Id id) :
|
BuildConfiguration::BuildConfiguration(Target *target, Core::Id id) :
|
||||||
ProjectConfiguration(target, id),
|
ProjectConfiguration(target, id),
|
||||||
m_clearSystemEnvironment(false),
|
m_clearSystemEnvironment(false)
|
||||||
m_macroExpander(0)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(target);
|
Q_ASSERT(target);
|
||||||
BuildStepList *bsl = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_BUILD));
|
BuildStepList *bsl = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_BUILD));
|
||||||
@@ -82,7 +81,6 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
|
|||||||
ProjectConfiguration(target, source),
|
ProjectConfiguration(target, source),
|
||||||
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
||||||
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
|
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
|
||||||
m_macroExpander(0),
|
|
||||||
m_buildDirectory(source->m_buildDirectory)
|
m_buildDirectory(source->m_buildDirectory)
|
||||||
{
|
{
|
||||||
Q_ASSERT(target);
|
Q_ASSERT(target);
|
||||||
@@ -96,9 +94,31 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
|
|||||||
this, SLOT(handleKitUpdate()));
|
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()
|
BuildConfiguration::~BuildConfiguration()
|
||||||
{
|
{
|
||||||
delete m_macroExpander;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FileName BuildConfiguration::buildDirectory() const
|
Utils::FileName BuildConfiguration::buildDirectory() const
|
||||||
@@ -123,26 +143,6 @@ QList<NamedWidget *> BuildConfiguration::createSubConfigWidgets()
|
|||||||
return QList<NamedWidget *>() << new BuildEnvironmentWidget(this);
|
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
|
QList<Core::Id> BuildConfiguration::knownStepLists() const
|
||||||
{
|
{
|
||||||
return Utils::transform(m_stepLists, &BuildStepList::id);
|
return Utils::transform(m_stepLists, &BuildStepList::id);
|
||||||
|
@@ -37,8 +37,6 @@
|
|||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
namespace Utils { class MacroExpander; }
|
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
class BuildConfiguration;
|
class BuildConfiguration;
|
||||||
@@ -83,8 +81,6 @@ public:
|
|||||||
virtual bool isEnabled() const;
|
virtual bool isEnabled() const;
|
||||||
virtual QString disabledReason() const;
|
virtual QString disabledReason() const;
|
||||||
|
|
||||||
Utils::MacroExpander *macroExpander();
|
|
||||||
|
|
||||||
enum BuildType {
|
enum BuildType {
|
||||||
Unknown,
|
Unknown,
|
||||||
Debug,
|
Debug,
|
||||||
@@ -111,11 +107,11 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void emitEnvironmentChanged();
|
void emitEnvironmentChanged();
|
||||||
|
void setupMacroExpander();
|
||||||
|
|
||||||
bool m_clearSystemEnvironment;
|
bool m_clearSystemEnvironment;
|
||||||
QList<Utils::EnvironmentItem> m_userEnvironmentChanges;
|
QList<Utils::EnvironmentItem> m_userEnvironmentChanges;
|
||||||
QList<BuildStepList *> m_stepLists;
|
QList<BuildStepList *> m_stepLists;
|
||||||
Utils::MacroExpander *m_macroExpander;
|
|
||||||
Utils::FileName m_buildDirectory;
|
Utils::FileName m_buildDirectory;
|
||||||
Utils::FileName m_lastEmmitedBuildDirectory;
|
Utils::FileName m_lastEmmitedBuildDirectory;
|
||||||
mutable Utils::Environment m_cachedEnvironment;
|
mutable Utils::Environment m_cachedEnvironment;
|
||||||
|
@@ -40,40 +40,21 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
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
|
|
||||||
{
|
|
||||||
if (name == QLatin1String("sourceDir")) {
|
|
||||||
*ret = m_target->project()->projectDirectory().toUserOutput();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} // namespace Internal
|
|
||||||
|
|
||||||
/// LocalApplicationRunConfiguration
|
|
||||||
|
|
||||||
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, Core::Id id) :
|
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, Core::Id id) :
|
||||||
RunConfiguration(target, id), m_macroExpander(0)
|
RunConfiguration(target, id)
|
||||||
{ }
|
{
|
||||||
|
setupMacroExpander();
|
||||||
|
}
|
||||||
|
|
||||||
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) :
|
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) :
|
||||||
RunConfiguration(target, rc), m_macroExpander(0)
|
RunConfiguration(target, rc)
|
||||||
{ }
|
{
|
||||||
|
setupMacroExpander();
|
||||||
|
}
|
||||||
|
|
||||||
LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
|
LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
|
||||||
{
|
{
|
||||||
delete m_macroExpander;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const
|
void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const
|
||||||
@@ -81,13 +62,17 @@ void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &
|
|||||||
Q_UNUSED(env);
|
Q_UNUSED(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::MacroExpander *LocalApplicationRunConfiguration::macroExpander() const
|
void LocalApplicationRunConfiguration::setupMacroExpander()
|
||||||
{
|
{
|
||||||
if (BuildConfiguration *bc = activeBuildConfiguration())
|
// Legacy
|
||||||
return bc->macroExpander();
|
macroExpander()->registerSubProvider([this]() -> Utils::MacroExpander * {
|
||||||
if (!m_macroExpander)
|
if (BuildConfiguration *bc = activeBuildConfiguration())
|
||||||
m_macroExpander = new Internal::FallBackMacroExpander(target());
|
return bc->macroExpander();
|
||||||
return m_macroExpander;
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
macroExpander()->registerVariable("sourceDir", tr("Project source directory"),
|
||||||
|
[this] { return target()->project()->projectDirectory().toUserOutput(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -34,10 +34,7 @@
|
|||||||
#include "runconfiguration.h"
|
#include "runconfiguration.h"
|
||||||
#include "applicationlauncher.h"
|
#include "applicationlauncher.h"
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils { class Environment; }
|
||||||
class MacroExpander;
|
|
||||||
class Environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
@@ -58,10 +55,8 @@ protected:
|
|||||||
explicit LocalApplicationRunConfiguration(Target *target, Core::Id id);
|
explicit LocalApplicationRunConfiguration(Target *target, Core::Id id);
|
||||||
explicit LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc);
|
explicit LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc);
|
||||||
|
|
||||||
Utils::MacroExpander *macroExpander() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable Utils::MacroExpander *m_macroExpander;
|
void setupMacroExpander();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "projectexplorer_export.h"
|
#include "projectexplorer_export.h"
|
||||||
|
|
||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
|
#include <utils/macroexpander.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -64,6 +65,9 @@ public:
|
|||||||
// Note: Make sure subclasses call the superclasses' toMap() function!
|
// Note: Make sure subclasses call the superclasses' toMap() function!
|
||||||
virtual QVariantMap toMap() const;
|
virtual QVariantMap toMap() const;
|
||||||
|
|
||||||
|
Utils::MacroExpander *macroExpander() { return &m_macroExpander; }
|
||||||
|
const Utils::MacroExpander *macroExpander() const { return &m_macroExpander; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void displayNameChanged();
|
void displayNameChanged();
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ private:
|
|||||||
Core::Id m_id;
|
Core::Id m_id;
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
QString m_defaultDisplayName;
|
QString m_defaultDisplayName;
|
||||||
|
Utils::MacroExpander m_macroExpander;
|
||||||
};
|
};
|
||||||
|
|
||||||
// helper functions:
|
// helper functions:
|
||||||
|
Reference in New Issue
Block a user