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>
This commit is contained in:
Daniel Teske
2013-04-16 14:18:57 +02:00
parent dceb1c3acc
commit b89ca41d97
5 changed files with 46 additions and 4 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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";

View File

@@ -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();
}