From b89ca41d9797b87bb994121b31cde1d8e67310fd Mon Sep 17 00:00:00 2001 From: Daniel Teske <daniel.teske@digia.com> Date: Tue, 16 Apr 2013 14:18:57 +0200 Subject: [PATCH] CustomExecutableRunConfiguration: Use sourceDir if the project has no bc For the workingDirectory Task-number: QTCREATORBUG-9118 Change-Id: I63079e95d1da169507a5d932680df955127f0f65 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> --- .../localapplicationrunconfiguration.cpp | 40 +++++++++++++++++-- .../localapplicationrunconfiguration.h | 2 + src/plugins/projectexplorer/processstep.cpp | 5 ++- .../projectexplorerconstants.h | 1 + .../customexecutablerunconfiguration.cpp | 2 + 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp index 3c5951805c7..e0022a61dfe 100644 --- a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp +++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp @@ -32,24 +32,56 @@ #include "buildconfiguration.h" #include "localenvironmentaspect.h" +#include <utils/stringutils.h> #include <coreplugin/variablemanager.h> +#include <projectexplorer/target.h> +#include <projectexplorer/project.h> + +#include <QDir> + namespace ProjectExplorer { + +namespace Internal { +class FallBackMacroExpander : public Utils::AbstractQtcMacroExpander { +public: + explicit FallBackMacroExpander(const Target *target) : m_target(target) {} + virtual bool resolveMacro(const QString &name, QString *ret); +private: + const Target *m_target; +}; + +bool FallBackMacroExpander::resolveMacro(const QString &name, QString *ret) +{ + if (name == QLatin1String("sourceDir")) { + *ret = QDir::toNativeSeparators(m_target->project()->projectDirectory()); + return true; + } + *ret = Core::VariableManager::value(name.toUtf8()); + return !ret->isEmpty(); +} +} // namespace Internal + /// LocalApplicationRunConfiguration LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, const Core::Id id) : - RunConfiguration(target, id) + RunConfiguration(target, id), m_macroExpander(0) { ctor(); } LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) : - RunConfiguration(target, rc) + RunConfiguration(target, rc), m_macroExpander(0) { ctor(); } +LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration() +{ + delete m_macroExpander; +} + void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const { Q_UNUSED(env); @@ -59,7 +91,9 @@ Utils::AbstractMacroExpander *LocalApplicationRunConfiguration::macroExpander() { if (BuildConfiguration *bc = activeBuildConfiguration()) return bc->macroExpander(); - return Core::VariableManager::macroExpander(); + if (!m_macroExpander) + m_macroExpander = new Internal::FallBackMacroExpander(target()); + return m_macroExpander; } void LocalApplicationRunConfiguration::ctor() diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.h b/src/plugins/projectexplorer/localapplicationrunconfiguration.h index ed66443d2d6..ccca694b7e0 100644 --- a/src/plugins/projectexplorer/localapplicationrunconfiguration.h +++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.h @@ -44,6 +44,7 @@ class PROJECTEXPLORER_EXPORT LocalApplicationRunConfiguration : public RunConfig { Q_OBJECT public: + ~LocalApplicationRunConfiguration(); enum RunMode { Console = ApplicationLauncher::Console, Gui @@ -66,6 +67,7 @@ protected: private: void ctor(); + mutable Utils::AbstractMacroExpander *m_macroExpander; }; } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/processstep.cpp b/src/plugins/projectexplorer/processstep.cpp index 019fbe16f05..cb0915ad2d8 100644 --- a/src/plugins/projectexplorer/processstep.cpp +++ b/src/plugins/projectexplorer/processstep.cpp @@ -137,7 +137,10 @@ void ProcessStep::setArguments(const QString &arguments) void ProcessStep::setWorkingDirectory(const QString &workingDirectory) { if (workingDirectory.isEmpty()) - m_workingDirectory = QLatin1String(ProjectExplorer::Constants::DEFAULT_WORKING_DIR); + if (target()->activeBuildConfiguration()) + m_workingDirectory = QLatin1String(ProjectExplorer::Constants::DEFAULT_WORKING_DIR); + else + m_workingDirectory = QLatin1String(ProjectExplorer::Constants::DEFAULT_WORKING_DIR_ALTERNATE); else m_workingDirectory = workingDirectory; } diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index cd535f6cd94..b20fddfd8be 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -228,6 +228,7 @@ const char CUSTOM_TOOLCHAIN_ID[] = "ProjectExplorer.ToolChain.Custom"; // Default directory to run custom (build) commands in. const char DEFAULT_WORKING_DIR[] = "%{buildDir}"; +const char DEFAULT_WORKING_DIR_ALTERNATE[] = "%{sourceDir}"; // Desktop Device related ids: const char DESKTOP_DEVICE_ID[] = "Desktop Device"; diff --git a/src/plugins/qtsupport/customexecutablerunconfiguration.cpp b/src/plugins/qtsupport/customexecutablerunconfiguration.cpp index 2b0526413ea..5be41ad3853 100644 --- a/src/plugins/qtsupport/customexecutablerunconfiguration.cpp +++ b/src/plugins/qtsupport/customexecutablerunconfiguration.cpp @@ -72,6 +72,8 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(ProjectExplor m_workingDirectory(QLatin1String(ProjectExplorer::Constants::DEFAULT_WORKING_DIR)), m_runMode(Gui) { + if (!parent->activeBuildConfiguration()) + m_workingDirectory = QLatin1String(ProjectExplorer::Constants::DEFAULT_WORKING_DIR_ALTERNATE); ctor(); } -- GitLab