diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp index 3c5951805c78e5d5a0a36ee4afcfc8e5f6737828..e0022a61dfe07a8df013bbdd2533c33160dab4c5 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 ed66443d2d66ad4bb25e58cb20cc5d72db9750b6..ccca694b7e02c029f99a95ab2865f0d2eb9141d8 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 019fbe16f05ff30af363744143b9b270003746ce..cb0915ad2d84b7a9d56c3c856078ae390caabe32 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 cd535f6cd94776259242a1e3de454ac532bbdc2b..b20fddfd8befad18d1a50663b5302a48a6d260f7 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 2b0526413ea93d02d8ca260c27c90bdf443c53d5..5be41ad3853e5cbdeeb428e696b848305c5fe123 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(); }