diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp index d339f4a9804..c5e1c70ea67 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp @@ -98,8 +98,7 @@ bool CustomExecutableRunConfiguration::isEnabled() const Runnable CustomExecutableRunConfiguration::runnable() const { - FilePath workingDirectory = - aspect()->workingDirectory(macroExpander()); + const FilePath workingDirectory = aspect()->workingDirectory(); Runnable r; r.command = commandLine(); diff --git a/src/plugins/projectexplorer/projectconfiguration.cpp b/src/plugins/projectexplorer/projectconfiguration.cpp index 92e77dc89f8..0b9559a90b6 100644 --- a/src/plugins/projectexplorer/projectconfiguration.cpp +++ b/src/plugins/projectexplorer/projectconfiguration.cpp @@ -145,6 +145,12 @@ void ProjectConfiguration::acquaintAspects() aspect->acquaintSiblings(m_aspects); } +void ProjectConfiguration::doPostInit() +{ + for (const std::function &postInit : qAsConst(m_postInit)) + postInit(); +} + FilePath ProjectConfiguration::mapFromBuildDeviceToGlobalPath(const FilePath &path) const { IDevice::ConstPtr dev = BuildDeviceKitAspect::device(kit()); diff --git a/src/plugins/projectexplorer/projectconfiguration.h b/src/plugins/projectexplorer/projectconfiguration.h index a6d17329739..9263804c56a 100644 --- a/src/plugins/projectexplorer/projectconfiguration.h +++ b/src/plugins/projectexplorer/projectconfiguration.h @@ -91,6 +91,9 @@ public: Utils::FilePath mapFromBuildDeviceToGlobalPath(const Utils::FilePath &path) const; + void addPostInit(const std::function &fixup) { m_postInit.append(fixup); } + void doPostInit(); + signals: void displayNameChanged(); void toolTipChanged(); @@ -103,6 +106,7 @@ private: const Utils::Id m_id; Utils::DisplayName m_displayName; QString m_toolTip; + QList> m_postInit; }; // helper function: diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 86753d3ea0c..b776a9dec91 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -1966,7 +1966,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er [] { if (const RunConfiguration * const rc = activeRunConfiguration()) { if (const auto wdAspect = rc->aspect()) - return wdAspect->workingDirectory(rc->macroExpander()).toString(); + return wdAspect->workingDirectory().toString(); } return QString(); }); diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 4bb59cab1b0..76ac46ec224 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -197,7 +197,7 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id) tr("The run configuration's working directory"), [this] { const auto wdAspect = aspect(); - return wdAspect ? wdAspect->workingDirectory(&m_expander).toString() : QString(); + return wdAspect ? wdAspect->workingDirectory().toString() : QString(); }); m_expander.registerVariable("RunConfig:Name", tr("The run configuration's name."), [this] { return displayName(); }); @@ -215,6 +215,11 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id) arguments = argumentsAspect->arguments(macroExpander()); return CommandLine{executable, arguments, CommandLine::Raw}; }; + + addPostInit([this] { + if (const auto wdAspect = aspect()) + wdAspect->setMacroExpander(&m_expander); + }); } RunConfiguration::~RunConfiguration() = default; @@ -233,8 +238,6 @@ bool RunConfiguration::isEnabled() const QWidget *RunConfiguration::createConfigurationWidget() { - if (const auto wdAspect = aspect()) - wdAspect->setMacroExpanderProvider([this] { return &m_expander; }); Layouting::Form builder; for (BaseAspect *aspect : qAsConst(m_aspects)) { if (aspect->isVisible()) @@ -402,7 +405,7 @@ Runnable RunConfiguration::runnable() const Runnable r; r.command = commandLine(); if (auto workingDirectoryAspect = aspect()) - r.workingDirectory = workingDirectoryAspect->workingDirectory(macroExpander()); + r.workingDirectory = workingDirectoryAspect->workingDirectory(); if (auto environmentAspect = aspect()) r.environment = environmentAspect->environment(); if (m_runnableModifier) @@ -571,6 +574,7 @@ RunConfiguration *RunConfigurationFactory::create(Target *target) const rc->m_aspects.registerAspect(factory(target)); rc->acquaintAspects(); + rc->doPostInit(); return rc; } diff --git a/src/plugins/projectexplorer/runconfigurationaspects.cpp b/src/plugins/projectexplorer/runconfigurationaspects.cpp index 4f02850f15b..0a3a2634b0f 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/runconfigurationaspects.cpp @@ -176,8 +176,8 @@ void WorkingDirectoryAspect::addToLayout(LayoutBuilder &builder) { QTC_CHECK(!m_chooser); m_chooser = new PathChooser; - if (m_expanderProvider) - m_chooser->setMacroExpander(m_expanderProvider()); + if (QTC_GUARD(m_macroExpander)) + m_chooser->setMacroExpander(m_macroExpander); m_chooser->setHistoryCompleter(settingsKey()); m_chooser->setExpectedKind(Utils::PathChooser::Directory); m_chooser->setPromptDialogTitle(tr("Select Working Directory")); @@ -246,14 +246,12 @@ void WorkingDirectoryAspect::toMap(QVariantMap &data) const Macros in the value are expanded using \a expander. */ -FilePath WorkingDirectoryAspect::workingDirectory(const MacroExpander *expander) const +FilePath WorkingDirectoryAspect::workingDirectory() const { const Environment env = m_envAspect ? m_envAspect->environment() : Environment::systemEnvironment(); FilePath res = m_workingDirectory; - QString workingDir = m_workingDirectory.path(); - if (expander) - workingDir = expander->expandProcessArgs(workingDir); + const QString workingDir = m_workingDirectory.path(); res.setPath(PathChooser::expandedDirectory(workingDir, env, QString())); return res; } @@ -293,9 +291,9 @@ void WorkingDirectoryAspect::setDefaultWorkingDirectory(const FilePath &defaultW } } -void WorkingDirectoryAspect::setMacroExpanderProvider(const MacroExpanderProvider &expanderProvider) +void WorkingDirectoryAspect::setMacroExpander(MacroExpander *macroExpander) { - m_expanderProvider = expanderProvider; + m_macroExpander = macroExpander; } /*! diff --git a/src/plugins/projectexplorer/runconfigurationaspects.h b/src/plugins/projectexplorer/runconfigurationaspects.h index e417f4ca28c..82b844a6636 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.h +++ b/src/plugins/projectexplorer/runconfigurationaspects.h @@ -78,11 +78,11 @@ public: void addToLayout(Utils::LayoutBuilder &builder) override; void acquaintSiblings(const Utils::AspectContainer &) override; - Utils::FilePath workingDirectory(const Utils::MacroExpander *expander) const; + Utils::FilePath workingDirectory() const; Utils::FilePath defaultWorkingDirectory() const; Utils::FilePath unexpandedWorkingDirectory() const; void setDefaultWorkingDirectory(const Utils::FilePath &defaultWorkingDirectory); - void setMacroExpanderProvider(const Utils::MacroExpanderProvider &expanderProvider); + void setMacroExpander(Utils::MacroExpander *macroExpander); Utils::PathChooser *pathChooser() const; private: @@ -96,7 +96,7 @@ private: Utils::FilePath m_defaultWorkingDirectory; QPointer m_chooser; QPointer m_resetButton; - Utils::MacroExpanderProvider m_expanderProvider; + Utils::MacroExpander *m_macroExpander = nullptr; }; class PROJECTEXPLORER_EXPORT ArgumentsAspect : public Utils::BaseAspect diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index bebcc279db3..0d317debbd8 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -203,7 +203,7 @@ Target::Target(Project *project, Kit *k, _constructor_tag) : [this] { if (RunConfiguration * const rc = activeRunConfiguration()) { if (const auto wdAspect = rc->aspect()) - return wdAspect->workingDirectory(&d->m_macroExpander).toString(); + return wdAspect->workingDirectory().toString(); } return QString(); }, false);