forked from qt-creator/qt-creator
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:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user