From a68aee95a1fb1667cf912a481992870f6e60b07b Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 18 Feb 2020 14:44:58 +0100 Subject: [PATCH] ProjectExplorer: Replace ProjectConfiguration::m_macroExpander ... by MacroExpanders in Build and RunConfiguration. Deploy didn't use its own, BuildStep always composed an empty expander with the BuildConfiguration's, uses now the BuildConfiguration's expander directly. Change-Id: I9de51bfc32aeb3d73f4974175e42a37807e49ac1 Reviewed-by: Christian Kandeler --- .../projectexplorer/buildconfiguration.cpp | 6 ++++++ .../projectexplorer/buildconfiguration.h | 4 ++++ src/plugins/projectexplorer/buildstep.cpp | 11 +++++++---- src/plugins/projectexplorer/buildstep.h | 3 +++ .../projectexplorer/deployconfiguration.cpp | 8 -------- src/plugins/projectexplorer/ioutputparser.h | 2 +- .../projectexplorer/projectconfiguration.h | 5 ----- .../projectexplorer/runconfiguration.cpp | 19 +++++++++---------- .../projectexplorer/runconfiguration.h | 4 ++++ src/plugins/projectexplorer/runcontrol.cpp | 4 ++-- src/plugins/projectexplorer/runcontrol.h | 2 +- src/plugins/projectexplorer/target.cpp | 11 +++++------ src/plugins/projectexplorer/target.h | 2 ++ 13 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp index a6262cf69d1..d34d7dda1cb 100644 --- a/src/plugins/projectexplorer/buildconfiguration.cpp +++ b/src/plugins/projectexplorer/buildconfiguration.cpp @@ -86,6 +86,7 @@ public: bool m_configWidgetHasFrame = false; QList m_initialBuildSteps; QList m_initialCleanSteps; + Utils::MacroExpander m_macroExpander; // FIXME: Remove. BuildConfiguration::BuildType m_initialBuildType = BuildConfiguration::Unknown; @@ -204,6 +205,11 @@ void BuildConfiguration::doInitialize(const BuildInfo &info) d->m_initializer(info); } +MacroExpander *BuildConfiguration::macroExpander() const +{ + return &d->m_macroExpander; +} + void BuildConfiguration::setInitializer(const std::function &initializer) { d->m_initializer = initializer; diff --git a/src/plugins/projectexplorer/buildconfiguration.h b/src/plugins/projectexplorer/buildconfiguration.h index 00de9bb71e0..3d125f5bb36 100644 --- a/src/plugins/projectexplorer/buildconfiguration.h +++ b/src/plugins/projectexplorer/buildconfiguration.h @@ -32,6 +32,8 @@ #include #include +namespace Utils { class MacroExpander; } + namespace ProjectExplorer { namespace Internal { class BuildConfigurationPrivate; } @@ -118,6 +120,8 @@ public: void doInitialize(const BuildInfo &info); + Utils::MacroExpander *macroExpander() const; + signals: void environmentChanged(); void buildDirectoryChanged(); diff --git a/src/plugins/projectexplorer/buildstep.cpp b/src/plugins/projectexplorer/buildstep.cpp index 930b7a6b3fa..5ec896e14dd 100644 --- a/src/plugins/projectexplorer/buildstep.cpp +++ b/src/plugins/projectexplorer/buildstep.cpp @@ -127,10 +127,6 @@ BuildStep::BuildStep(BuildStepList *bsl, Core::Id id) : ProjectConfiguration(bsl, id) { QTC_CHECK(bsl->target() && bsl->target() == this->target()); - Utils::MacroExpander *expander = macroExpander(); - expander->setDisplayName(tr("Build Step")); - expander->setAccumulating(true); - expander->registerSubProvider([this] { return projectConfiguration()->macroExpander(); }); } void BuildStep::run() @@ -220,6 +216,13 @@ BuildSystem *BuildStep::buildSystem() const return target()->buildSystem(); } +Utils::MacroExpander *BuildStep::macroExpander() const +{ + if (auto bc = buildConfiguration()) + return bc->macroExpander(); + return Utils::globalMacroExpander(); +} + void BuildStep::reportRunResult(QFutureInterface &fi, bool success) { fi.reportResult(success); diff --git a/src/plugins/projectexplorer/buildstep.h b/src/plugins/projectexplorer/buildstep.h index 4c45fefb7f1..10f8063fe3b 100644 --- a/src/plugins/projectexplorer/buildstep.h +++ b/src/plugins/projectexplorer/buildstep.h @@ -38,6 +38,8 @@ #include #include +namespace Utils { class MacroExpander; } + namespace ProjectExplorer { class BuildConfiguration; @@ -77,6 +79,7 @@ public: ProjectConfiguration *projectConfiguration() const; BuildSystem *buildSystem() const; + Utils::MacroExpander *macroExpander() const; enum class OutputFormat { Stdout, Stderr, // These are for forwarded output from external tools diff --git a/src/plugins/projectexplorer/deployconfiguration.cpp b/src/plugins/projectexplorer/deployconfiguration.cpp index f4100036468..e5469e9e3b2 100644 --- a/src/plugins/projectexplorer/deployconfiguration.cpp +++ b/src/plugins/projectexplorer/deployconfiguration.cpp @@ -47,14 +47,6 @@ DeployConfiguration::DeployConfiguration(Target *target, Core::Id id) m_stepList(this, Constants::BUILDSTEPS_DEPLOY) { QTC_CHECK(target && target == this->target()); - Utils::MacroExpander *expander = macroExpander(); - expander->setDisplayName(tr("Deploy Settings")); - expander->setAccumulating(true); - expander->registerSubProvider([target] { - BuildConfiguration *bc = target->activeBuildConfiguration(); - return bc ? bc->macroExpander() : target->macroExpander(); - }); - //: Default DeployConfiguration display name setDefaultDisplayName(tr("Deploy locally")); } diff --git a/src/plugins/projectexplorer/ioutputparser.h b/src/plugins/projectexplorer/ioutputparser.h index 1872461cbb9..cd65378fe25 100644 --- a/src/plugins/projectexplorer/ioutputparser.h +++ b/src/plugins/projectexplorer/ioutputparser.h @@ -28,7 +28,7 @@ #include "projectexplorer_export.h" #include "buildstep.h" -#include +namespace Utils { class FilePath; } namespace ProjectExplorer { class Task; diff --git a/src/plugins/projectexplorer/projectconfiguration.h b/src/plugins/projectexplorer/projectconfiguration.h index c6134f6ed8f..a87a264c420 100644 --- a/src/plugins/projectexplorer/projectconfiguration.h +++ b/src/plugins/projectexplorer/projectconfiguration.h @@ -29,7 +29,6 @@ #include #include -#include #include #include @@ -188,9 +187,6 @@ 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; } - Target *target() const; Project *project() const; @@ -223,7 +219,6 @@ private: const Core::Id m_id; Utils::DisplayName m_displayName; QString m_toolTip; - Utils::MacroExpander m_macroExpander; }; // helper function: diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 03c908a8596..8a6f7afaa4c 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -167,27 +167,26 @@ RunConfiguration::RunConfiguration(Target *target, Core::Id id) QTC_CHECK(target && target == this->target()); connect(target, &Target::parsingFinished, this, &RunConfiguration::update); - Utils::MacroExpander *expander = macroExpander(); - expander->setDisplayName(tr("Run Settings")); - expander->setAccumulating(true); - expander->registerSubProvider([target] { + m_expander.setDisplayName(tr("Run Settings")); + m_expander.setAccumulating(true); + m_expander.registerSubProvider([target] { BuildConfiguration *bc = target->activeBuildConfiguration(); return bc ? bc->macroExpander() : target->macroExpander(); }); - expander->registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"), + m_expander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"), [this](const QString &var) { const auto envAspect = aspect(); return envAspect ? envAspect->environment().expandedValueForKey(var) : QString(); }); - expander->registerVariable(Constants::VAR_CURRENTRUN_WORKINGDIR, + m_expander.registerVariable(Constants::VAR_CURRENTRUN_WORKINGDIR, tr("The currently active run configuration's working directory"), - [this, expander] { + [this] { const auto wdAspect = aspect(); - return wdAspect ? wdAspect->workingDirectory(expander).toString() : QString(); + return wdAspect ? wdAspect->workingDirectory(&m_expander).toString() : QString(); }); - expander->registerVariable(Constants::VAR_CURRENTRUN_NAME, + m_expander.registerVariable(Constants::VAR_CURRENTRUN_NAME, QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."), [this] { return displayName(); }, false); @@ -232,7 +231,7 @@ QWidget *RunConfiguration::createConfigurationWidget() } } - Core::VariableChooser::addSupportForChildWidgets(widget, macroExpander()); + Core::VariableChooser::addSupportForChildWidgets(widget, &m_expander); auto detailsWidget = new Utils::DetailsWidget; detailsWidget->setState(DetailsWidget::NoSummary); diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 5a51508ccf7..de54858abc6 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -33,6 +33,7 @@ #include "task.h" #include +#include #include #include @@ -170,6 +171,8 @@ public: void update(); + const Utils::MacroExpander *macroExpander() const { return &m_expander; } + signals: void enabledChanged(); @@ -199,6 +202,7 @@ private: QString m_buildKey; CommandLineGetter m_commandLineGetter; Updater m_updater; + Utils::MacroExpander m_expander; }; class RunConfigurationCreationInfo diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 1bd5d90f9a1..0c3eecc0608 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -322,7 +322,7 @@ public: IDevice::ConstPtr device; Core::Id runMode; Utils::Icon icon; - MacroExpander *macroExpander; + const MacroExpander *macroExpander; QPointer runConfiguration; // Not owned. Avoid use. QString buildKey; QMap settingsData; @@ -896,7 +896,7 @@ Kit *RunControl::kit() const return d->kit; } -MacroExpander *RunControl::macroExpander() const +const MacroExpander *RunControl::macroExpander() const { return d->macroExpander; } diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h index 1ad3e26b273..cda6d6ab55e 100644 --- a/src/plugins/projectexplorer/runcontrol.h +++ b/src/plugins/projectexplorer/runcontrol.h @@ -222,7 +222,7 @@ public: Target *target() const; Project *project() const; Kit *kit() const; - Utils::MacroExpander *macroExpander() const; + const Utils::MacroExpander *macroExpander() const; ProjectConfigurationAspect *aspect(Core::Id id) const; template T *aspect() const { return runConfiguration() ? runConfiguration()->aspect() : nullptr; diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index aa20d94aa82..ef8215f73fb 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -150,17 +150,16 @@ Target::Target(Project *project, Kit *k, _constructor_tag) : connect(km, &KitManager::kitUpdated, this, &Target::handleKitUpdates); connect(km, &KitManager::kitRemoved, this, &Target::handleKitRemoval); - Utils::MacroExpander *expander = macroExpander(); - expander->setDisplayName(tr("Target Settings")); - expander->setAccumulating(true); + d->m_macroExpander.setDisplayName(tr("Target Settings")); + d->m_macroExpander.setAccumulating(true); - expander->registerSubProvider([this] { return kit()->macroExpander(); }); + d->m_macroExpander.registerSubProvider([this] { return kit()->macroExpander(); }); - expander->registerVariable("sourceDir", tr("Source directory"), + d->m_macroExpander.registerVariable("sourceDir", tr("Source directory"), [project] { return project->projectDirectory().toUserOutput(); }); // Legacy support. - expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME, + d->m_macroExpander.registerVariable(Constants::VAR_CURRENTPROJECT_NAME, QCoreApplication::translate("ProjectExplorer", "Name of current project"), [project] { return project->displayName(); }, false); diff --git a/src/plugins/projectexplorer/target.h b/src/plugins/projectexplorer/target.h index 2e452fac22c..08ea4ef4516 100644 --- a/src/plugins/projectexplorer/target.h +++ b/src/plugins/projectexplorer/target.h @@ -32,6 +32,8 @@ QT_FORWARD_DECLARE_CLASS(QIcon) +namespace Utils { class MacroExpander; } + namespace ProjectExplorer { class BuildConfiguration; class BuildTargetInfo;