Commit ef563d80 authored by hjk's avatar hjk

MacroExpander: Fall back to global expander

... and use that all over the place.

Change-Id: Ie6e0ed0f0d9eaba9b4466761e6b455f33a905086
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 89602419
......@@ -221,9 +221,17 @@ QString MacroExpander::value(const QByteArray &variable, bool *found)
* \sa MacroExpander
* \sa macroExpander()
*/
QString MacroExpander::expandedString(const QString &stringWithVariables)
QString MacroExpander::expand(const QString &stringWithVariables)
{
return Utils::expandMacros(stringWithVariables, this);
QString res = Utils::expandMacros(stringWithVariables, this);
if (this != globalMacroExpander())
res = Utils::expandMacros(res, this);
return res;
}
QByteArray MacroExpander::expand(const QByteArray &stringWithVariables)
{
return expand(QString::fromLatin1(stringWithVariables)).toLatin1();
}
/*!
......
......@@ -49,7 +49,8 @@ public:
QString value(const QByteArray &variable, bool *found = 0);
QString expandedString(const QString &stringWithVariables);
QString expand(const QString &stringWithVariables);
QByteArray expand(const QByteArray &stringWithVariables);
typedef std::function<QString(QString)> PrefixFunction;
typedef std::function<QString()> StringFunction;
......
......@@ -186,7 +186,7 @@ QString CMakeProject::shadowBuildDirectory(const QString &projectFilePath, const
const QString projectName = QFileInfo(info.absolutePath()).fileName();
ProjectExplorer::ProjectMacroExpander expander(projectFilePath, projectName, k, bcName);
QDir projectDir = QDir(projectDirectory(Utils::FileName::fromString(projectFilePath)).toString());
QString buildPath = Utils::expandMacros(Core::DocumentManager::buildDirectory(), &expander);
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return QDir::cleanPath(projectDir.absoluteFilePath(buildPath));
}
......
......@@ -123,7 +123,7 @@ QString CMakeRunConfiguration::workingDirectory() const
EnvironmentAspect *aspect = extraAspect<EnvironmentAspect>();
QTC_ASSERT(aspect, return QString());
return QDir::cleanPath(aspect->environment().expandVariables(
Utils::expandMacros(baseWorkingDirectory(), macroExpander())));
macroExpander()->expand(baseWorkingDirectory())));
}
QString CMakeRunConfiguration::baseWorkingDirectory() const
......
......@@ -556,8 +556,8 @@ bool ExternalToolRunner::resolve()
{ // executable
QStringList expandedExecutables; /* for error message */
foreach (const QString &executable, m_tool->executables()) {
QString expanded = expander->expandedString(executable);
expandedExecutables << expanded;
QString expanded = expander->expand(executable);
expandedExecutables.append(expanded);
m_resolvedExecutable = Environment::systemEnvironment().searchInPath(expanded);
if (!m_resolvedExecutable.isEmpty())
break;
......@@ -575,15 +575,11 @@ bool ExternalToolRunner::resolve()
return false;
}
}
{ // arguments
m_resolvedArguments = QtcProcess::expandMacros(m_tool->arguments(), expander);
}
{ // input
m_resolvedInput = expander->expandedString(m_tool->input());
}
{ // working directory
m_resolvedWorkingDirectory = expander->expandedString(m_tool->workingDirectory());
}
m_resolvedArguments = QtcProcess::expandMacros(m_tool->arguments(), expander);
m_resolvedInput = expander->expand(m_tool->input());
m_resolvedWorkingDirectory = expander->expand(m_tool->workingDirectory());
return true;
}
......
......@@ -1836,7 +1836,7 @@ void DebuggerEngine::validateExecutable(DebuggerStartParameters *sp)
SourcePathRegExpMap globalRegExpSourceMap;
globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size());
foreach (auto entry, options->sourcePathRegExpMap) {
const QString expanded = Utils::globalMacroExpander()->expandedString(entry.second);
const QString expanded = Utils::globalMacroExpander()->expand(entry.second);
if (!expanded.isEmpty())
globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded));
}
......
......@@ -3334,7 +3334,7 @@ bool boolSetting(int code)
QString stringSetting(int code)
{
QString raw = theDebuggerCore->m_debuggerSettings->item(code)->value().toString();
return globalMacroExpander()->expandedString(raw);
return globalMacroExpander()->expand(raw);
}
QStringList stringListSetting(int code)
......
......@@ -4404,9 +4404,8 @@ void GdbEngine::abortDebugger()
void GdbEngine::resetInferior()
{
if (!startParameters().commandsForReset.isEmpty()) {
QByteArray substitutedCommands = globalMacroExpander()->expandedString(
QString::fromLatin1(startParameters().commandsForReset)).toLatin1();
foreach (QByteArray command, substitutedCommands.split('\n')) {
QByteArray commands = globalMacroExpander()->expand(startParameters().commandsForReset);
foreach (QByteArray command, commands.split('\n')) {
command = command.trimmed();
if (!command.isEmpty()) {
if (state() == InferiorStopOk) {
......@@ -4455,8 +4454,8 @@ void GdbEngine::handleInferiorPrepared()
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
if (!sp.commandsAfterConnect.isEmpty()) {
QByteArray substitutedCommands = globalMacroExpander()->expandedString(QString::fromLatin1(sp.commandsAfterConnect)).toLatin1();
foreach (QByteArray command, substitutedCommands.split('\n')) {
QByteArray commands = globalMacroExpander()->expand(sp.commandsAfterConnect);
foreach (QByteArray command, commands.split('\n')) {
postCommand(command);
}
}
......
......@@ -43,7 +43,7 @@
#include <coreplugin/idocument.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/macroexpander.h>
#include <utils/algorithm.h>
#include <QDebug>
......@@ -155,7 +155,7 @@ QList<NamedWidget *> BuildConfiguration::createSubConfigWidgets()
return QList<NamedWidget *>() << new BuildEnvironmentWidget(this);
}
Utils::AbstractMacroExpander *BuildConfiguration::macroExpander()
Utils::MacroExpander *BuildConfiguration::macroExpander()
{
if (!m_macroExpander)
m_macroExpander = new Internal::BuildConfigMacroExpander(this);
......
......@@ -37,7 +37,7 @@
#include <utils/environment.h>
#include <utils/fileutils.h>
namespace Utils { class AbstractMacroExpander; }
namespace Utils { class MacroExpander; }
namespace ProjectExplorer {
......@@ -83,7 +83,7 @@ public:
virtual bool isEnabled() const;
virtual QString disabledReason() const;
Utils::AbstractMacroExpander *macroExpander();
Utils::MacroExpander *macroExpander();
enum BuildType {
Unknown,
......@@ -115,7 +115,7 @@ private:
bool m_clearSystemEnvironment;
QList<Utils::EnvironmentItem> m_userEnvironmentChanges;
QList<BuildStepList *> m_stepLists;
Utils::AbstractMacroExpander *m_macroExpander;
Utils::MacroExpander *m_macroExpander;
Utils::FileName m_buildDirectory;
Utils::FileName m_lastEmmitedBuildDirectory;
mutable Utils::Environment m_cachedEnvironment;
......
......@@ -45,7 +45,7 @@ class QTextEdit;
QT_END_NAMESPACE
namespace Utils {
class AbstractMacroExpander;
class MacroExpander;
class TextFieldCheckBox;
class TextFieldComboBox;
} // namespace Utils
......@@ -67,15 +67,15 @@ public:
static Field *parse(const QVariant &input, QString *errorMessage);
void createWidget(JsonFieldPage *page);
void adjustState(Utils::AbstractMacroExpander *expander);
void adjustState(Utils::MacroExpander *expander);
virtual void setEnabled(bool e) { m_widget->setEnabled(e); }
void setVisible(bool v) { m_widget->setVisible(v); }
virtual bool validate(Utils::AbstractMacroExpander *expander, QString *message)
virtual bool validate(Utils::MacroExpander *expander, QString *message)
{ Q_UNUSED(expander); Q_UNUSED(message); return true; }
void initialize(Utils::AbstractMacroExpander *expander);
virtual void cleanup(Utils::AbstractMacroExpander *expander) { Q_UNUSED(expander); }
void initialize(Utils::MacroExpander *expander);
virtual void cleanup(Utils::MacroExpander *expander) { Q_UNUSED(expander); }
virtual bool suppressName() const { return false; }
......@@ -89,7 +89,7 @@ public:
QVariant m_enabledExpression;
virtual bool parseData(const QVariant &data, QString *errorMessage) = 0;
virtual void initializeData(Utils::AbstractMacroExpander *expander) { Q_UNUSED(expander); }
virtual void initializeData(Utils::MacroExpander *expander) { Q_UNUSED(expander); }
virtual QWidget *widget(const QString &displayName) = 0;
virtual void setup(JsonFieldPage *page, const QString &name)
{ Q_UNUSED(page); Q_UNUSED(name); }
......@@ -136,8 +136,8 @@ public:
void setup(JsonFieldPage *page, const QString &name);
bool validate(Utils::AbstractMacroExpander *expander, QString *message);
void initializeData(Utils::AbstractMacroExpander *expander);
bool validate(Utils::MacroExpander *expander, QString *message);
void initializeData(Utils::MacroExpander *expander);
QString m_placeholderText;
QString m_defaultText;
......@@ -159,8 +159,8 @@ public:
void setup(JsonFieldPage *page, const QString &name);
bool validate(Utils::AbstractMacroExpander *expander, QString *message);
void initializeData(Utils::AbstractMacroExpander *expander);
bool validate(Utils::MacroExpander *expander, QString *message);
void initializeData(Utils::MacroExpander *expander);
QString m_defaultText;
bool m_acceptRichText;
......@@ -182,8 +182,8 @@ public:
void setup(JsonFieldPage *page, const QString &name);
bool validate(Utils::AbstractMacroExpander *expander, QString *message);
void initializeData(Utils::AbstractMacroExpander *expander);
bool validate(Utils::MacroExpander *expander, QString *message);
void initializeData(Utils::MacroExpander *expander);
QString m_path;
QString m_basePath;
......@@ -206,8 +206,8 @@ public:
void setup(JsonFieldPage *page, const QString &name);
bool validate(Utils::AbstractMacroExpander *expander, QString *message);
void initializeData(Utils::AbstractMacroExpander *expander);
bool validate(Utils::MacroExpander *expander, QString *message);
void initializeData(Utils::MacroExpander *expander);
QString m_checkedValue;
QString m_uncheckedValue;
......@@ -228,8 +228,8 @@ public:
void setup(JsonFieldPage *page, const QString &name);
bool validate(Utils::AbstractMacroExpander *expander, QString *message);
void initializeData(Utils::AbstractMacroExpander *expander);
bool validate(Utils::MacroExpander *expander, QString *message);
void initializeData(Utils::MacroExpander *expander);
QStringList m_itemList;
QStringList m_itemDataList;
......@@ -240,7 +240,7 @@ public:
int m_currentIndex;
};
JsonFieldPage(Utils::AbstractMacroExpander *expander, QWidget *parent = 0);
JsonFieldPage(Utils::MacroExpander *expander, QWidget *parent = 0);
~JsonFieldPage();
bool setup(const QVariant &data);
......@@ -254,7 +254,7 @@ public:
void showError(const QString &m) const;
void clearError() const;
Utils::AbstractMacroExpander *expander();
Utils::MacroExpander *expander();
private:
QFormLayout *m_formLayout;
......@@ -262,7 +262,7 @@ private:
QList<Field *> m_fields;
Utils::AbstractMacroExpander *m_expander;
Utils::MacroExpander *m_expander;
};
} // namespace ProjectExplorer
......
......@@ -61,7 +61,7 @@ void JsonWizard::addGenerator(JsonWizardGenerator *gen)
m_generators.append(gen);
}
Utils::AbstractMacroExpander *JsonWizard::expander() const
Utils::MacroExpander *JsonWizard::expander() const
{
return m_expander;
}
......@@ -114,7 +114,7 @@ QVariant JsonWizard::value(const QString &n) const
QVariant v = property(n.toUtf8());
if (v.isValid()) {
if (v.type() == QVariant::String)
return Utils::expandMacros(v.toString(), m_expander);
return m_expander->expand(v.toString());
else
return v;
}
......@@ -128,10 +128,10 @@ void JsonWizard::setValue(const QString &key, const QVariant &value)
setProperty(key.toUtf8(), value);
}
bool JsonWizard::boolFromVariant(const QVariant &v, Utils::AbstractMacroExpander *expander)
bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expander)
{
if (v.type() == QVariant::String)
return !Utils::expandMacros(v.toString(), expander).isEmpty();
return !expander->expand(v.toString()).isEmpty();
return v.toBool();
}
......
......@@ -37,7 +37,7 @@
#include <utils/wizard.h>
namespace Utils { class AbstractMacroExpander; }
namespace Utils { class MacroExpander; }
namespace ProjectExplorer {
......@@ -71,7 +71,7 @@ public:
void addGenerator(JsonWizardGenerator *gen);
Utils::AbstractMacroExpander *expander() const;
Utils::MacroExpander *expander() const;
void resetFileList();
GeneratorFiles fileList();
......@@ -79,7 +79,7 @@ public:
QVariant value(const QString &n) const;
void setValue(const QString &key, const QVariant &value);
static bool boolFromVariant(const QVariant &v, Utils::AbstractMacroExpander *expander);
static bool boolFromVariant(const QVariant &v, Utils::MacroExpander *expander);
void removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a);
......
......@@ -31,9 +31,7 @@
#ifndef JSONWIZARDEXPANDER_H
#define JSONWIZARDEXPANDER_H
#include <utils/stringutils.h>
#include <QString>
#include <utils/macroexpander.h>
namespace ProjectExplorer {
......@@ -42,7 +40,7 @@ class JsonWizard;
namespace Internal {
// Documentation inside.
class JsonWizardExpander : public Utils::AbstractMacroExpander
class JsonWizardExpander : public Utils::MacroExpander
{
public:
explicit JsonWizardExpander(JsonWizard *wizard);
......
......@@ -39,7 +39,7 @@
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/macroexpander.h>
#include <QCoreApplication>
#include <QDir>
......@@ -48,7 +48,7 @@
namespace ProjectExplorer {
namespace Internal {
static QString processTextFileContents(Utils::AbstractMacroExpander *expander,
static QString processTextFileContents(Utils::MacroExpander *expander,
const QString &input, QString *errorMessage)
{
errorMessage->clear();
......@@ -57,7 +57,7 @@ static QString processTextFileContents(Utils::AbstractMacroExpander *expander,
return input;
QString tmp;
if (!customWizardPreprocess(Utils::expandMacros(input, expander), &tmp, errorMessage))
if (!customWizardPreprocess(expander->expand(input), &tmp, errorMessage))
return QString();
// Expand \n, \t and handle line continuation:
......@@ -124,7 +124,7 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage)
return true;
}
Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::AbstractMacroExpander *expander,
Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *expander,
const QString &wizardDir, const QString &projectDir,
QString *errorMessage)
{
......@@ -140,7 +140,7 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::AbstractMacroExpan
continue;
// Read contents of source file
const QString src = wizard.absoluteFilePath(Utils::expandMacros(f.source, expander));
const QString src = wizard.absoluteFilePath(expander->expand(f.source));
const QFile::OpenMode openMode
= JsonWizard::boolFromVariant(f.isBinary, expander)
? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
......@@ -151,7 +151,7 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::AbstractMacroExpan
// Generate file information:
Core::GeneratedFile gf;
gf.setPath(project.absoluteFilePath(Utils::expandMacros(f.target, expander)));
gf.setPath(project.absoluteFilePath(expander->expand(f.target)));
if (JsonWizard::boolFromVariant(f.isBinary, expander)) {
gf.setBinary(true);
......
......@@ -44,7 +44,7 @@ class JsonWizardFileGenerator : public JsonWizardGenerator
public:
bool setup(const QVariant &data, QString *errorMessage);
Core::GeneratedFiles fileList(Utils::AbstractMacroExpander *expander,
Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
const QString &wizardDir, const QString &projectDir,
QString *errorMessage);
......
......@@ -40,7 +40,7 @@
#include <QList>
#include <QObject>
namespace Utils { class AbstractMacroExpander; }
namespace Utils { class MacroExpander; }
namespace ProjectExplorer {
......@@ -49,7 +49,7 @@ class JsonWizardGenerator
public:
virtual ~JsonWizardGenerator() { }
virtual Core::GeneratedFiles fileList(Utils::AbstractMacroExpander *expander,
virtual Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
const QString &baseDir, const QString &projectDir,
QString *errorMessage) = 0;
virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
......
......@@ -300,7 +300,7 @@ QString Kit::unexpandedDisplayName() const
QString Kit::displayName() const
{
return Utils::expandMacros(d->m_unexpandedDisplayName, &d->m_macroExpander);
return d->m_macroExpander.expand(d->m_unexpandedDisplayName);
}
static QString candidateName(const QString &name, const QString &postfix)
......
......@@ -33,7 +33,6 @@
#include "buildconfiguration.h"
#include <utils/macroexpander.h>
#include <utils/stringutils.h>
#include <projectexplorer/target.h>
#include <projectexplorer/project.h>
......@@ -43,7 +42,7 @@
namespace ProjectExplorer {
namespace Internal {
class FallBackMacroExpander : public Utils::AbstractMacroExpander
class FallBackMacroExpander : public Utils::MacroExpander
{
public:
explicit FallBackMacroExpander(const Target *target) : m_target(target) {}
......@@ -58,9 +57,7 @@ bool FallBackMacroExpander::resolveMacro(const QString &name, QString *ret)
*ret = m_target->project()->projectDirectory().toUserOutput();
return true;
}
bool found;
*ret = Utils::globalMacroExpander()->value(name.toUtf8(), &found);
return found;
return false;
}
} // namespace Internal
......@@ -84,7 +81,7 @@ void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &
Q_UNUSED(env);
}
Utils::AbstractMacroExpander *LocalApplicationRunConfiguration::macroExpander() const
Utils::MacroExpander *LocalApplicationRunConfiguration::macroExpander() const
{
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->macroExpander();
......
......@@ -35,7 +35,7 @@
#include "applicationlauncher.h"
namespace Utils {
class AbstractMacroExpander;
class MacroExpander;
class Environment;
}
......@@ -58,10 +58,10 @@ protected:
explicit LocalApplicationRunConfiguration(Target *target, Core::Id id);
explicit LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc);
Utils::AbstractMacroExpander *macroExpander() const;
Utils::MacroExpander *macroExpander() const;
private:
mutable Utils::AbstractMacroExpander *m_macroExpander;
mutable Utils::MacroExpander *m_macroExpander;
};
} // namespace ProjectExplorer
......
......@@ -30,7 +30,7 @@
#include "processparameters.h"
#include <utils/stringutils.h>
#include <utils/macroexpander.h>
#include <utils/qtcprocess.h>
#include <QFileInfo>
......@@ -97,7 +97,7 @@ void ProcessParameters::setWorkingDirectory(const QString &workingDirectory)
*/
/*!
\fn void ProjectExplorer::ProcessParameters::setMacroExpander(Utils::AbstractMacroExpander *mx)
\fn void ProjectExplorer::ProcessParameters::setMacroExpander(Utils::MacroExpander *mx)
Sets the macro expander \a mx to use on the command, arguments, and working
dir.
......@@ -113,7 +113,7 @@ QString ProcessParameters::effectiveWorkingDirectory() const
if (m_effectiveWorkingDirectory.isEmpty()) {
QString wds = m_workingDirectory;
if (m_macroExpander)
Utils::expandMacros(&wds, m_macroExpander);
wds = m_macroExpander->expand(wds);
m_effectiveWorkingDirectory = QDir::cleanPath(m_environment.expandVariables(wds));
}
return m_effectiveWorkingDirectory;
......@@ -128,7 +128,7 @@ QString ProcessParameters::effectiveCommand() const
if (m_effectiveCommand.isEmpty()) {
QString cmd = m_command;
if (m_macroExpander)
Utils::expandMacros(&cmd, m_macroExpander);
cmd = m_macroExpander->expand(cmd);
m_effectiveCommand =
m_environment.searchInPath(cmd, QStringList(effectiveWorkingDirectory())).toString();
m_commandMissing = m_effectiveCommand.isEmpty();
......@@ -153,7 +153,7 @@ QString ProcessParameters::effectiveArguments() const
if (m_effectiveArguments.isEmpty()) {
m_effectiveArguments = m_arguments;
if (m_macroExpander)
Utils::expandMacros(&m_effectiveArguments, m_macroExpander);
m_effectiveArguments = m_macroExpander->expand(m_effectiveArguments);
}
return m_effectiveArguments;
}
......@@ -162,7 +162,7 @@ QString ProcessParameters::prettyCommand() const
{
QString cmd = m_command;
if (m_macroExpander)
Utils::expandMacros(&cmd, m_macroExpander);
cmd = m_macroExpander->expand(cmd);
return QFileInfo(cmd).fileName();
}
......
......@@ -35,7 +35,7 @@
#include <utils/environment.h>
namespace Utils { class AbstractMacroExpander; }
namespace Utils { class MacroExpander; }
namespace ProjectExplorer {
......@@ -57,8 +57,8 @@ public:
void setEnvironment(const Utils::Environment &env) { m_environment = env; }
Utils::Environment environment() const { return m_environment; }
void setMacroExpander(Utils::AbstractMacroExpander *mx) { m_macroExpander = mx; }
Utils::AbstractMacroExpander *macroExpander() const { return m_macroExpander; }
void setMacroExpander(Utils::MacroExpander *mx) { m_macroExpander = mx; }
Utils::MacroExpander *macroExpander() const { return m_macroExpander; }
/// Get the fully expanded working directory:
QString effectiveWorkingDirectory() const;
......@@ -81,7 +81,7 @@ private:
QString m_command;
QString m_arguments;
Utils::Environment m_environment;
Utils::AbstractMacroExpander *m_macroExpander;
Utils::MacroExpander *m_macroExpander;
mutable QString m_effectiveWorkingDirectory;
mutable QString m_effectiveCommand;
......
......@@ -32,13 +32,13 @@
#define PROJECTMACROEXPANDER_H
#include "projectexplorer_export.h"
#include <utils/stringutils.h>
#include <utils/macroexpander.h>
#include <QFileInfo>
namespace ProjectExplorer {
class Kit;
class PROJECTEXPLORER_EXPORT ProjectMacroExpander : public Utils::AbstractMacroExpander
class PROJECTEXPLORER_EXPORT ProjectMacroExpander : public Utils::MacroExpander
{
public:
ProjectMacroExpander(const QString &projectFilePath, const QString &projectName, const Kit *k, const QString &bcName);
......
......@@ -372,7 +372,7 @@ Utils::FileName QbsProject::defaultBuildDirectory(const QString &projectFilePath