forked from qt-creator/qt-creator
ProjectExplorer: Add executable() accessor to RunConfiguration
Amends f6c276daf0, which was a quick fix for 4.9.
Change-Id: I94281af6a9a0d0bfe197ce836488f708d5bd677d
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -256,7 +256,7 @@ Runnable CustomExecutableRunConfiguration::runnable() const
|
|||||||
aspect<WorkingDirectoryAspect>()->workingDirectory(macroExpander());
|
aspect<WorkingDirectoryAspect>()->workingDirectory(macroExpander());
|
||||||
|
|
||||||
Runnable r;
|
Runnable r;
|
||||||
r.executable = aspect<ExecutableAspect>()->executable().toString();
|
r.executable = executable().toString();
|
||||||
r.commandLineArguments = aspect<ArgumentsAspect>()->arguments(macroExpander());
|
r.commandLineArguments = aspect<ArgumentsAspect>()->arguments(macroExpander());
|
||||||
r.environment = aspect<EnvironmentAspect>()->environment();
|
r.environment = aspect<EnvironmentAspect>()->environment();
|
||||||
r.workingDirectory = workingDirectory.toString();
|
r.workingDirectory = workingDirectory.toString();
|
||||||
|
|||||||
@@ -1614,14 +1614,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
tr("The currently active run configuration's executable (if applicable)."),
|
tr("The currently active run configuration's executable (if applicable)."),
|
||||||
[]() -> QString {
|
[]() -> QString {
|
||||||
if (Target *target = activeTarget()) {
|
if (Target *target = activeTarget()) {
|
||||||
if (RunConfiguration *rc = target->activeRunConfiguration()) {
|
if (RunConfiguration *rc = target->activeRunConfiguration())
|
||||||
// TODO: This duplicates code and is not always correct, but see
|
return rc->executable().toString();
|
||||||
// QTCREATORBUG-18317.
|
|
||||||
// Solution: Re-introduce RunConfiguration::executable()?
|
|
||||||
if (auto executableAspect = rc->aspect<ExecutableAspect>())
|
|
||||||
return executableAspect->executable().toString();
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -200,6 +200,12 @@ RunConfiguration::RunConfiguration(Target *target, Core::Id id)
|
|||||||
|
|
||||||
for (const AspectFactory &factory : theAspectFactories)
|
for (const AspectFactory &factory : theAspectFactories)
|
||||||
m_aspects.append(factory(target));
|
m_aspects.append(factory(target));
|
||||||
|
|
||||||
|
m_executableGetter = [this] {
|
||||||
|
if (const auto executableAspect = aspect<ExecutableAspect>())
|
||||||
|
return executableAspect->executable();
|
||||||
|
return FileName();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
RunConfiguration::~RunConfiguration() = default;
|
RunConfiguration::~RunConfiguration() = default;
|
||||||
@@ -321,6 +327,16 @@ QVariantMap RunConfiguration::toMap() const
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RunConfiguration::setExecutableGetter(const RunConfiguration::ExecutableGetter &exeGetter)
|
||||||
|
{
|
||||||
|
m_executableGetter = exeGetter;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileName RunConfiguration::executable() const
|
||||||
|
{
|
||||||
|
return m_executableGetter();
|
||||||
|
}
|
||||||
|
|
||||||
BuildTargetInfo RunConfiguration::buildTargetInfo() const
|
BuildTargetInfo RunConfiguration::buildTargetInfo() const
|
||||||
{
|
{
|
||||||
return target()->buildTarget(m_buildKey);
|
return target()->buildTarget(m_buildKey);
|
||||||
@@ -376,8 +392,7 @@ bool RunConfiguration::fromMap(const QVariantMap &map)
|
|||||||
Runnable RunConfiguration::runnable() const
|
Runnable RunConfiguration::runnable() const
|
||||||
{
|
{
|
||||||
Runnable r;
|
Runnable r;
|
||||||
if (auto executableAspect = aspect<ExecutableAspect>())
|
r.executable = executable().toString();
|
||||||
r.executable = executableAspect->executable().toString();
|
|
||||||
if (auto argumentsAspect = aspect<ArgumentsAspect>())
|
if (auto argumentsAspect = aspect<ArgumentsAspect>())
|
||||||
r.commandLineArguments = argumentsAspect->arguments(macroExpander());
|
r.commandLineArguments = argumentsAspect->arguments(macroExpander());
|
||||||
if (auto workingDirectoryAspect = aspect<WorkingDirectoryAspect>())
|
if (auto workingDirectoryAspect = aspect<WorkingDirectoryAspect>())
|
||||||
|
|||||||
@@ -160,6 +160,10 @@ public:
|
|||||||
bool fromMap(const QVariantMap &map) override;
|
bool fromMap(const QVariantMap &map) override;
|
||||||
QVariantMap toMap() const override;
|
QVariantMap toMap() const override;
|
||||||
|
|
||||||
|
using ExecutableGetter = std::function<Utils::FileName()>;
|
||||||
|
void setExecutableGetter(const ExecutableGetter &exeGetter);
|
||||||
|
Utils::FileName executable() const;
|
||||||
|
|
||||||
virtual Runnable runnable() const;
|
virtual Runnable runnable() const;
|
||||||
|
|
||||||
// Return a handle to the build system target that created this run configuration.
|
// Return a handle to the build system target that created this run configuration.
|
||||||
@@ -210,6 +214,7 @@ private:
|
|||||||
QString m_buildKey;
|
QString m_buildKey;
|
||||||
bool m_isEnabled = false;
|
bool m_isEnabled = false;
|
||||||
std::function<Utils::OutputFormatter *(Project *)> m_outputFormatterCreator;
|
std::function<Utils::OutputFormatter *(Project *)> m_outputFormatterCreator;
|
||||||
|
ExecutableGetter m_executableGetter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RunConfigurationCreationInfo
|
class RunConfigurationCreationInfo
|
||||||
|
|||||||
@@ -279,6 +279,9 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
|
|||||||
addAspect<TerminalAspect>();
|
addAspect<TerminalAspect>();
|
||||||
|
|
||||||
setOutputFormatter<PythonOutputFormatter>();
|
setOutputFormatter<PythonOutputFormatter>();
|
||||||
|
setExecutableGetter([this] {
|
||||||
|
return FileName::fromString(aspect<InterpreterAspect>()->value());
|
||||||
|
});
|
||||||
|
|
||||||
connect(target, &Target::applicationTargetsChanged,
|
connect(target, &Target::applicationTargetsChanged,
|
||||||
this, &PythonRunConfiguration::updateTargetInformation);
|
this, &PythonRunConfiguration::updateTargetInformation);
|
||||||
@@ -300,7 +303,7 @@ Runnable PythonRunConfiguration::runnable() const
|
|||||||
QtcProcess::addArg(&r.commandLineArguments, mainScript());
|
QtcProcess::addArg(&r.commandLineArguments, mainScript());
|
||||||
QtcProcess::addArgs(&r.commandLineArguments,
|
QtcProcess::addArgs(&r.commandLineArguments,
|
||||||
aspect<ArgumentsAspect>()->arguments(macroExpander()));
|
aspect<ArgumentsAspect>()->arguments(macroExpander()));
|
||||||
r.executable = aspect<InterpreterAspect>()->value();
|
r.executable = executable().toString();
|
||||||
r.environment = aspect<EnvironmentAspect>()->environment();
|
r.environment = aspect<EnvironmentAspect>()->environment();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,9 +298,11 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
|||||||
return envModifier(Environment());
|
return envModifier(Environment());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setExecutableGetter([this] { return FileName::fromString(theExecutable()); });
|
||||||
|
|
||||||
m_qmlViewerAspect = addAspect<BaseStringAspect>();
|
m_qmlViewerAspect = addAspect<BaseStringAspect>();
|
||||||
m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
|
m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
|
||||||
m_qmlViewerAspect->setPlaceHolderText(executable());
|
m_qmlViewerAspect->setPlaceHolderText(executable().toString());
|
||||||
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
||||||
m_qmlViewerAspect->setHistoryCompleter("QmlProjectManager.viewer.history");
|
m_qmlViewerAspect->setHistoryCompleter("QmlProjectManager.viewer.history");
|
||||||
|
|
||||||
@@ -314,7 +316,6 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
|||||||
this, &QmlProjectRunConfiguration::updateEnabledState);
|
this, &QmlProjectRunConfiguration::updateEnabledState);
|
||||||
|
|
||||||
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
||||||
|
|
||||||
connect(target, &Target::kitChanged,
|
connect(target, &Target::kitChanged,
|
||||||
this, &QmlProjectRunConfiguration::updateEnabledState);
|
this, &QmlProjectRunConfiguration::updateEnabledState);
|
||||||
|
|
||||||
@@ -325,7 +326,7 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
|||||||
Runnable QmlProjectRunConfiguration::runnable() const
|
Runnable QmlProjectRunConfiguration::runnable() const
|
||||||
{
|
{
|
||||||
Runnable r;
|
Runnable r;
|
||||||
r.executable = executable();
|
r.executable = executable().toString();
|
||||||
r.commandLineArguments = commandLineArguments();
|
r.commandLineArguments = commandLineArguments();
|
||||||
r.environment = aspect<EnvironmentAspect>()->environment();
|
r.environment = aspect<EnvironmentAspect>()->environment();
|
||||||
r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString();
|
r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString();
|
||||||
@@ -338,7 +339,7 @@ QString QmlProjectRunConfiguration::disabledReason() const
|
|||||||
return tr("No script file to execute.");
|
return tr("No script file to execute.");
|
||||||
if (DeviceTypeKitAspect::deviceTypeId(target()->kit())
|
if (DeviceTypeKitAspect::deviceTypeId(target()->kit())
|
||||||
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE
|
||||||
&& !QFileInfo::exists(executable())) {
|
&& !executable().exists()) {
|
||||||
return tr("No qmlscene found.");
|
return tr("No qmlscene found.");
|
||||||
}
|
}
|
||||||
if (executable().isEmpty())
|
if (executable().isEmpty())
|
||||||
@@ -346,7 +347,7 @@ QString QmlProjectRunConfiguration::disabledReason() const
|
|||||||
return RunConfiguration::disabledReason();
|
return RunConfiguration::disabledReason();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlProjectRunConfiguration::executable() const
|
QString QmlProjectRunConfiguration::theExecutable() const
|
||||||
{
|
{
|
||||||
const QString qmlViewer = m_qmlViewerAspect->value();
|
const QString qmlViewer = m_qmlViewerAspect->value();
|
||||||
if (!qmlViewer.isEmpty())
|
if (!qmlViewer.isEmpty())
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ private:
|
|||||||
void updateEnabledState() final;
|
void updateEnabledState() final;
|
||||||
|
|
||||||
QString mainScript() const;
|
QString mainScript() const;
|
||||||
QString executable() const;
|
QString theExecutable() const;
|
||||||
QString commandLineArguments() const;
|
QString commandLineArguments() const;
|
||||||
|
|
||||||
ProjectExplorer::BaseStringAspect *m_qmlViewerAspect;
|
ProjectExplorer::BaseStringAspect *m_qmlViewerAspect;
|
||||||
|
|||||||
Reference in New Issue
Block a user