ProjectExplorer: Replace RunConfiguration::executable

... by a RunConfiguration::commandLine().

That's what is typically consumed, and removes the need for some
custom runnable() implementations.

Change-Id: I7700b12cdd0965802a0add977b432314734a5a72
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-06-11 14:39:39 +02:00
parent a51b8a061e
commit 7ebe005206
8 changed files with 44 additions and 41 deletions

View File

@@ -255,8 +255,7 @@ Runnable CustomExecutableRunConfiguration::runnable() const
aspect<WorkingDirectoryAspect>()->workingDirectory(macroExpander());
Runnable r;
r.executable = executable().toString();
r.commandLineArguments = aspect<ArgumentsAspect>()->arguments(macroExpander());
r.setCommandLine(commandLine());
r.environment = aspect<EnvironmentAspect>()->environment();
r.workingDirectory = workingDirectory.toString();
r.device = DeviceManager::instance()->defaultDevice(Constants::DESKTOP_DEVICE_TYPE);

View File

@@ -1640,7 +1640,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
[]() -> QString {
if (Target *target = activeTarget()) {
if (RunConfiguration *rc = target->activeRunConfiguration())
return rc->executable().toString();
return rc->commandLine().executable().toString();
}
return QString();
});

View File

@@ -201,10 +201,14 @@ RunConfiguration::RunConfiguration(Target *target, Core::Id id)
for (const AspectFactory &factory : theAspectFactories)
m_aspects.append(factory(target));
m_executableGetter = [this] {
m_commandLineGetter = [this] {
FilePath executable;
if (const auto executableAspect = aspect<ExecutableAspect>())
return executableAspect->executable();
return FilePath();
executable = executableAspect->executable();
QString arguments;
if (const auto argumentsAspect = aspect<ArgumentsAspect>())
arguments = argumentsAspect->arguments(macroExpander());
return CommandLine{executable, arguments, CommandLine::Raw};
};
}
@@ -327,14 +331,14 @@ QVariantMap RunConfiguration::toMap() const
return map;
}
void RunConfiguration::setExecutableGetter(const RunConfiguration::ExecutableGetter &exeGetter)
void RunConfiguration::setCommandLineGetter(const CommandLineGetter &cmdGetter)
{
m_executableGetter = exeGetter;
m_commandLineGetter = cmdGetter;
}
FilePath RunConfiguration::executable() const
CommandLine RunConfiguration::commandLine() const
{
return m_executableGetter();
return m_commandLineGetter();
}
BuildTargetInfo RunConfiguration::buildTargetInfo() const
@@ -392,9 +396,7 @@ bool RunConfiguration::fromMap(const QVariantMap &map)
Runnable RunConfiguration::runnable() const
{
Runnable r;
r.executable = executable().toString();
if (auto argumentsAspect = aspect<ArgumentsAspect>())
r.commandLineArguments = argumentsAspect->arguments(macroExpander());
r.setCommandLine(commandLine());
if (auto workingDirectoryAspect = aspect<WorkingDirectoryAspect>())
r.workingDirectory = workingDirectoryAspect->workingDirectory(macroExpander()).toString();
if (auto environmentAspect = aspect<EnvironmentAspect>())

View File

@@ -160,9 +160,9 @@ public:
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
using ExecutableGetter = std::function<Utils::FilePath()>;
void setExecutableGetter(const ExecutableGetter &exeGetter);
Utils::FilePath executable() const;
using CommandLineGetter = std::function<Utils::CommandLine()>;
void setCommandLineGetter(const CommandLineGetter &cmdGetter);
Utils::CommandLine commandLine() const;
virtual Runnable runnable() const;
@@ -214,7 +214,7 @@ private:
QString m_buildKey;
bool m_isEnabled = false;
std::function<Utils::OutputFormatter *(Project *)> m_outputFormatterCreator;
ExecutableGetter m_executableGetter;
CommandLineGetter m_commandLineGetter;
};
class RunConfigurationCreationInfo

View File

@@ -264,7 +264,13 @@ ArgumentsAspect::ArgumentsAspect()
QString ArgumentsAspect::arguments(const MacroExpander *expander) const
{
QTC_ASSERT(expander, return m_arguments);
return expander->expandProcessArgs(m_arguments);
if (m_currentlyExpanding)
return m_arguments;
m_currentlyExpanding = true;
const QString expanded = expander->expandProcessArgs(m_arguments);
m_currentlyExpanding = false;
return expanded;
}
QString ArgumentsAspect::unexpandedArguments() const

View File

@@ -115,6 +115,7 @@ private:
QString m_arguments;
QPointer<Utils::FancyLineEdit> m_chooser;
mutable bool m_currentlyExpanding = false;
};
class PROJECTEXPLORER_EXPORT UseLibraryPathsAspect : public BaseBoolAspect

View File

@@ -246,7 +246,6 @@ public:
private:
void doAdditionalSetup(const RunConfigurationCreationInfo &) final { updateTargetInformation(); }
Runnable runnable() const final;
bool supportsDebugger() const { return true; }
QString mainScript() const { return aspect<MainScriptAspect>()->value(); }
@@ -275,12 +274,16 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
scriptAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
addAspect<LocalEnvironmentAspect>(target);
addAspect<ArgumentsAspect>();
auto argumentsAspect = addAspect<ArgumentsAspect>();
addAspect<TerminalAspect>();
setOutputFormatter<PythonOutputFormatter>();
setExecutableGetter([this] {
return FilePath::fromString(aspect<InterpreterAspect>()->value());
setCommandLineGetter([this, interpreterAspect, argumentsAspect] {
CommandLine cmd{FilePath::fromString(interpreterAspect->value()), {mainScript()}};
cmd.addArgs(argumentsAspect->arguments(macroExpander()), CommandLine::Raw);
return cmd;
});
connect(target, &Target::applicationTargetsChanged,
@@ -297,17 +300,6 @@ void PythonRunConfiguration::updateTargetInformation()
aspect<MainScriptAspect>()->setValue(script);
}
Runnable PythonRunConfiguration::runnable() const
{
CommandLine cmd{executable(), {mainScript()}};
cmd.addArgs(aspect<ArgumentsAspect>()->arguments(macroExpander()), CommandLine::Raw);
Runnable r;
r.setCommandLine(cmd);
r.environment = aspect<EnvironmentAspect>()->environment();
return r;
}
class PythonRunConfigurationFactory : public RunConfigurationFactory
{
public:

View File

@@ -298,17 +298,21 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
return envModifier(Environment());
});
setExecutableGetter([this] { return FilePath::fromString(theExecutable()); });
m_qmlViewerAspect = addAspect<BaseStringAspect>();
m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
m_qmlViewerAspect->setPlaceHolderText(executable().toString());
m_qmlViewerAspect->setPlaceHolderText(commandLine().executable().toString());
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
m_qmlViewerAspect->setHistoryCompleter("QmlProjectManager.viewer.history");
auto argumentAspect = addAspect<ArgumentsAspect>();
argumentAspect->setSettingsKey(Constants::QML_VIEWER_ARGUMENTS_KEY);
setCommandLineGetter([this] {
return CommandLine(FilePath::fromString(theExecutable()),
commandLineArguments(),
CommandLine::Raw);
});
auto qmlProject = qobject_cast<QmlProject *>(target->project());
QTC_ASSERT(qmlProject, return);
m_mainQmlFileAspect = addAspect<MainQmlFileAspect>(qmlProject);
@@ -326,8 +330,7 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
Runnable QmlProjectRunConfiguration::runnable() const
{
Runnable r;
r.executable = executable().toString();
r.commandLineArguments = commandLineArguments();
r.setCommandLine(commandLine());
r.environment = aspect<EnvironmentAspect>()->environment();
r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString();
return r;
@@ -339,10 +342,10 @@ QString QmlProjectRunConfiguration::disabledReason() const
return tr("No script file to execute.");
if (DeviceTypeKitAspect::deviceTypeId(target()->kit())
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE
&& !executable().exists()) {
&& !commandLine().executable().exists()) {
return tr("No qmlscene found.");
}
if (executable().isEmpty())
if (commandLine().executable().isEmpty())
return tr("No qmlscene binary specified for target device.");
return RunConfiguration::disabledReason();
}
@@ -405,7 +408,7 @@ QString QmlProjectRunConfiguration::commandLineArguments() const
void QmlProjectRunConfiguration::updateEnabledState()
{
bool enabled = false;
if (m_mainQmlFileAspect->isQmlFilePresent() && !executable().isEmpty()) {
if (m_mainQmlFileAspect->isQmlFilePresent() && !commandLine().executable().isEmpty()) {
Project *p = target()->project();
enabled = !p->isParsing() && p->hasParsingData();
}