ProjectExplorer: Shift full FilePath creation into Executable aspect

Less need for correction: When a target is given, the executable
produced by the aspect will be on the target device.

Change-Id: I86c38e9f9fa5b4d4fe9b2ef7f21a0b3aa5b28670
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-05-11 13:54:42 +02:00
parent 8737dfd962
commit 72a2083cd1
15 changed files with 47 additions and 51 deletions

View File

@@ -48,7 +48,7 @@ public:
explicit BareMetalRunConfiguration(Target *target, Utils::Id id) explicit BareMetalRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
const auto exeAspect = addAspect<ExecutableAspect>(); const auto exeAspect = addAspect<ExecutableAspect>(target);
exeAspect->setDisplayStyle(StringAspect::LabelDisplay); exeAspect->setDisplayStyle(StringAspect::LabelDisplay);
exeAspect->setPlaceHolderText(tr("Unknown")); exeAspect->setPlaceHolderText(tr("Unknown"));
@@ -69,10 +69,10 @@ class BareMetalCustomRunConfiguration final : public RunConfiguration
Q_DECLARE_TR_FUNCTIONS(BareMetal::Internal::BareMetalCustomRunConfiguration) Q_DECLARE_TR_FUNCTIONS(BareMetal::Internal::BareMetalCustomRunConfiguration)
public: public:
explicit BareMetalCustomRunConfiguration(Target *target, Utils::Id id) explicit BareMetalCustomRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
const auto exeAspect = addAspect<ExecutableAspect>(); const auto exeAspect = addAspect<ExecutableAspect>(target);
exeAspect->setSettingsKey("BareMetal.CustomRunConfig.Executable"); exeAspect->setSettingsKey("BareMetal.CustomRunConfig.Executable");
exeAspect->setPlaceHolderText(tr("Unknown")); exeAspect->setPlaceHolderText(tr("Unknown"));
exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay);

View File

@@ -84,13 +84,12 @@ private:
QString defaultDisplayName() const; QString defaultDisplayName() const;
}; };
QdbRunConfiguration::QdbRunConfiguration(Target *target, Utils::Id id) QdbRunConfiguration::QdbRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto exeAspect = addAspect<ExecutableAspect>(); auto exeAspect = addAspect<ExecutableAspect>(target);
exeAspect->setSettingsKey("QdbRunConfig.RemoteExecutable"); exeAspect->setSettingsKey("QdbRunConfig.RemoteExecutable");
exeAspect->setLabelText(tr("Executable on device:")); exeAspect->setLabelText(tr("Executable on device:"));
exeAspect->setExecutablePathStyle(OsTypeLinux);
exeAspect->setPlaceHolderText(tr("Remote path not set")); exeAspect->setPlaceHolderText(tr("Remote path not set"));
exeAspect->makeOverridable("QdbRunConfig.AlternateRemoteExecutable", exeAspect->makeOverridable("QdbRunConfig.AlternateRemoteExecutable",
"QdbRunCofig.UseAlternateRemoteExecutable"); "QdbRunCofig.UseAlternateRemoteExecutable");

View File

@@ -77,10 +77,10 @@ static IosDeviceType toIosDeviceType(const SimulatorInfo &device)
return iosDeviceType; return iosDeviceType;
} }
IosRunConfiguration::IosRunConfiguration(Target *target, Utils::Id id) IosRunConfiguration::IosRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto executableAspect = addAspect<ExecutableAspect>(); auto executableAspect = addAspect<ExecutableAspect>(target);
executableAspect->setDisplayStyle(StringAspect::LabelDisplay); executableAspect->setDisplayStyle(StringAspect::LabelDisplay);
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();

View File

@@ -44,7 +44,7 @@ MesonRunConfiguration::MesonRunConfiguration(ProjectExplorer::Target *target, Ut
{ {
auto envAspect = addAspect<ProjectExplorer::LocalEnvironmentAspect>(target); auto envAspect = addAspect<ProjectExplorer::LocalEnvironmentAspect>(target);
addAspect<ProjectExplorer::ExecutableAspect>(); addAspect<ProjectExplorer::ExecutableAspect>(target);
addAspect<ProjectExplorer::ArgumentsAspect>(); addAspect<ProjectExplorer::ArgumentsAspect>();
addAspect<ProjectExplorer::WorkingDirectoryAspect>(envAspect); addAspect<ProjectExplorer::WorkingDirectoryAspect>(envAspect);
addAspect<ProjectExplorer::TerminalAspect>(); addAspect<ProjectExplorer::TerminalAspect>();

View File

@@ -52,7 +52,7 @@ public:
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect>(target); auto envAspect = addAspect<LocalEnvironmentAspect>(target);
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>(target);
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
addAspect<WorkingDirectoryAspect>(envAspect); addAspect<WorkingDirectoryAspect>(envAspect);
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();
@@ -89,7 +89,7 @@ public:
NimbleTestConfiguration(ProjectExplorer::Target *target, Utils::Id id) NimbleTestConfiguration(ProjectExplorer::Target *target, Utils::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
addAspect<ExecutableAspect>()->setExecutable(Nim::nimblePathFromKit(target->kit())); addAspect<ExecutableAspect>(target)->setExecutable(Nim::nimblePathFromKit(target->kit()));
addAspect<ArgumentsAspect>()->setArguments("test"); addAspect<ArgumentsAspect>()->setArguments("test");
addAspect<WorkingDirectoryAspect>(nullptr)->setDefaultWorkingDirectory(project()->projectDirectory()); addAspect<WorkingDirectoryAspect>(nullptr)->setDefaultWorkingDirectory(project()->projectDirectory());
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();

View File

@@ -50,7 +50,7 @@ public:
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect>(target); auto envAspect = addAspect<LocalEnvironmentAspect>(target);
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>(target);
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
addAspect<WorkingDirectoryAspect>(envAspect); addAspect<WorkingDirectoryAspect>(envAspect);
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();

View File

@@ -41,20 +41,19 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
: CustomExecutableRunConfiguration(target, CUSTOM_EXECUTABLE_RUNCONFIG_ID) : CustomExecutableRunConfiguration(target, CUSTOM_EXECUTABLE_RUNCONFIG_ID)
{} {}
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Utils::Id id) CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect>(target); auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto exeAspect = addAspect<ExecutableAspect>(); auto exeAspect = addAspect<ExecutableAspect>(nullptr); // nullptr - to enforce host-only operation.
exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable"); exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable");
exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay);
exeAspect->setHistoryCompleter("Qt.CustomExecutable.History"); exeAspect->setHistoryCompleter("Qt.CustomExecutable.History");
exeAspect->setExpectedKind(PathChooser::ExistingCommand); exeAspect->setExpectedKind(PathChooser::ExistingCommand);
exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment())); exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment()));
auto argsAspect = addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
addAspect<WorkingDirectoryAspect>(envAspect); addAspect<WorkingDirectoryAspect>(envAspect);
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();
@@ -62,12 +61,6 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment())); exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment()));
}); });
setCommandLineGetter([exeAspect, argsAspect, this] {
const FilePath executable = exeAspect->executable();
const QString arguments = argsAspect->arguments(macroExpander());
return CommandLine{executable, arguments, CommandLine::Raw};
});
setDefaultDisplayName(defaultDisplayName()); setDefaultDisplayName(defaultDisplayName());
} }

View File

@@ -68,7 +68,7 @@ DesktopRunConfiguration::DesktopRunConfiguration(Target *target, Id id, Kind kin
{ {
auto envAspect = addAspect<LocalEnvironmentAspect>(target); auto envAspect = addAspect<LocalEnvironmentAspect>(target);
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>(target);
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
addAspect<WorkingDirectoryAspect>(envAspect); addAspect<WorkingDirectoryAspect>(envAspect);
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();

View File

@@ -217,9 +217,6 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id)
if (const auto argumentsAspect = aspect<ArgumentsAspect>()) if (const auto argumentsAspect = aspect<ArgumentsAspect>())
arguments = argumentsAspect->arguments(macroExpander()); arguments = argumentsAspect->arguments(macroExpander());
if (IDevice::ConstPtr dev = DeviceKitAspect::device(target->kit()))
executable = dev->filePath(executable.path());
return CommandLine{executable, arguments, CommandLine::Raw}; return CommandLine{executable, arguments, CommandLine::Raw};
}; };

View File

@@ -25,7 +25,9 @@
#include "runconfigurationaspects.h" #include "runconfigurationaspects.h"
#include "devicesupport/idevice.h"
#include "environmentaspect.h" #include "environmentaspect.h"
#include "kitinformation.h"
#include "project.h" #include "project.h"
#include "projectexplorer.h" #include "projectexplorer.h"
#include "projectexplorersettings.h" #include "projectexplorersettings.h"
@@ -515,39 +517,42 @@ void ArgumentsAspect::addToLayout(LayoutBuilder &builder)
by the build system's parsing results with an optional manual override. by the build system's parsing results with an optional manual override.
*/ */
ExecutableAspect::ExecutableAspect() ExecutableAspect::ExecutableAspect(Target *target)
: m_target(target)
{ {
setDisplayName(tr("Executable")); setDisplayName(tr("Executable"));
setId("ExecutableAspect"); setId("ExecutableAspect");
setExecutablePathStyle(HostOsInfo::hostOs());
addDataExtractor(this, &ExecutableAspect::executable, &Data::executable); addDataExtractor(this, &ExecutableAspect::executable, &Data::executable);
m_executable.setPlaceHolderText(tr("<unknown>")); m_executable.setPlaceHolderText(tr("<unknown>"));
m_executable.setLabelText(tr("Executable:")); m_executable.setLabelText(tr("Executable:"));
m_executable.setDisplayStyle(StringAspect::LabelDisplay); m_executable.setDisplayStyle(StringAspect::LabelDisplay);
connect(&m_executable, &StringAspect::changed, updateDevice();
this, &ExecutableAspect::changed);
connect(&m_executable, &StringAspect::changed, this, &ExecutableAspect::changed);
} }
/*! /*!
\internal \internal
*/ */
static IDevice::ConstPtr deviceForTarget(Target *target)
{
return target ? DeviceKitAspect::device(target->kit()) : IDevice::ConstPtr();
}
ExecutableAspect::~ExecutableAspect() ExecutableAspect::~ExecutableAspect()
{ {
delete m_alternativeExecutable; delete m_alternativeExecutable;
m_alternativeExecutable = nullptr; m_alternativeExecutable = nullptr;
} }
/*! void ExecutableAspect::updateDevice()
Sets the display style of the paths to the default used on \a osType,
backslashes on Windows, forward slashes elsewhere.
\sa Utils::StringAspect::setDisplayFilter()
*/
void ExecutableAspect::setExecutablePathStyle(OsType osType)
{ {
const IDevice::ConstPtr dev = deviceForTarget(m_target);
const OsType osType = dev ? dev->osType() : HostOsInfo::hostOs();
m_executable.setDisplayFilter([osType](const QString &pathName) { m_executable.setDisplayFilter([osType](const QString &pathName) {
return OsSpecificAspects::pathWithNativeSeparators(osType, pathName); return OsSpecificAspects::pathWithNativeSeparators(osType, pathName);
}); });
@@ -632,10 +637,14 @@ void ExecutableAspect::makeOverridable(const QString &overridingKey, const QStri
*/ */
FilePath ExecutableAspect::executable() const FilePath ExecutableAspect::executable() const
{ {
if (m_alternativeExecutable && m_alternativeExecutable->isChecked()) FilePath exe = m_alternativeExecutable && m_alternativeExecutable->isChecked()
return m_alternativeExecutable->filePath(); ? m_alternativeExecutable->filePath()
: m_executable.filePath();
return m_executable.filePath(); if (const IDevice::ConstPtr dev = deviceForTarget(m_target))
exe = dev->filePath(exe.path());
return exe;
} }
/*! /*!

View File

@@ -174,7 +174,7 @@ class PROJECTEXPLORER_EXPORT ExecutableAspect : public Utils::BaseAspect
Q_OBJECT Q_OBJECT
public: public:
ExecutableAspect(); explicit ExecutableAspect(Target *target); // Uses device from target if non-null.
~ExecutableAspect() override; ~ExecutableAspect() override;
Utils::FilePath executable() const; Utils::FilePath executable() const;
@@ -185,7 +185,6 @@ public:
void addToLayout(Utils::LayoutBuilder &builder) override; void addToLayout(Utils::LayoutBuilder &builder) override;
void setLabelText(const QString &labelText); void setLabelText(const QString &labelText);
void setPlaceHolderText(const QString &placeHolderText); void setPlaceHolderText(const QString &placeHolderText);
void setExecutablePathStyle(Utils::OsType osType);
void setHistoryCompleter(const QString &historyCompleterKey); void setHistoryCompleter(const QString &historyCompleterKey);
void setExpectedKind(const Utils::PathChooser::Kind expectedKind); void setExpectedKind(const Utils::PathChooser::Kind expectedKind);
void setEnvironmentChange(const Utils::EnvironmentChange &change); void setEnvironmentChange(const Utils::EnvironmentChange &change);
@@ -202,9 +201,11 @@ protected:
private: private:
QString executableText() const; QString executableText() const;
void updateDevice();
Utils::StringAspect m_executable; Utils::StringAspect m_executable;
Utils::StringAspect *m_alternativeExecutable = nullptr; Utils::StringAspect *m_alternativeExecutable = nullptr;
Target *m_target = nullptr;
}; };
class PROJECTEXPLORER_EXPORT SymbolFileAspect : public Utils::StringAspect class PROJECTEXPLORER_EXPORT SymbolFileAspect : public Utils::StringAspect

View File

@@ -47,9 +47,8 @@ namespace Internal {
QnxRunConfiguration::QnxRunConfiguration(Target *target, Utils::Id id) QnxRunConfiguration::QnxRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto exeAspect = addAspect<ExecutableAspect>(); auto exeAspect = addAspect<ExecutableAspect>(target);
exeAspect->setLabelText(tr("Executable on device:")); exeAspect->setLabelText(tr("Executable on device:"));
exeAspect->setExecutablePathStyle(OsTypeLinux);
exeAspect->setPlaceHolderText(tr("Remote path not set")); exeAspect->setPlaceHolderText(tr("Remote path not set"));
exeAspect->makeOverridable("RemoteLinux.RunConfig.AlternateRemoteExecutable", exeAspect->makeOverridable("RemoteLinux.RunConfig.AlternateRemoteExecutable",
"RemoteLinux.RunConfig.UseAlternateRemoteExecutable"); "RemoteLinux.RunConfig.UseAlternateRemoteExecutable");

View File

@@ -57,7 +57,7 @@ const char CleanInstallRootAspectId[] = "RemoteLinux.MakeInstall.CleanInstallRoo
const char FullCommandLineAspectId[] = "RemoteLinux.MakeInstall.FullCommandLine"; const char FullCommandLineAspectId[] = "RemoteLinux.MakeInstall.FullCommandLine";
const char CustomCommandLineAspectId[] = "RemoteLinux.MakeInstall.CustomCommandLine"; const char CustomCommandLineAspectId[] = "RemoteLinux.MakeInstall.CustomCommandLine";
MakeInstallStep::MakeInstallStep(BuildStepList *parent, Utils::Id id) : MakeStep(parent, id) MakeInstallStep::MakeInstallStep(BuildStepList *parent, Id id) : MakeStep(parent, id)
{ {
makeCommandAspect()->setVisible(false); makeCommandAspect()->setVisible(false);
buildTargetsAspect()->setVisible(false); buildTargetsAspect()->setVisible(false);
@@ -67,7 +67,7 @@ MakeInstallStep::MakeInstallStep(BuildStepList *parent, Utils::Id id) : MakeStep
jobCountAspect()->setVisible(false); jobCountAspect()->setVisible(false);
disabledForSubdirsAspect()->setVisible(false); disabledForSubdirsAspect()->setVisible(false);
const auto makeAspect = addAspect<ExecutableAspect>(); const auto makeAspect = addAspect<ExecutableAspect>(parent->target());
makeAspect->setId(MakeAspectId); makeAspect->setId(MakeAspectId);
makeAspect->setSettingsKey(MakeAspectId); makeAspect->setSettingsKey(MakeAspectId);
makeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); makeAspect->setDisplayStyle(StringAspect::PathChooserDisplay);

View File

@@ -59,10 +59,9 @@ RemoteLinuxCustomRunConfiguration::RemoteLinuxCustomRunConfiguration(Target *tar
{ {
auto envAspect = addAspect<RemoteLinuxEnvironmentAspect>(target); auto envAspect = addAspect<RemoteLinuxEnvironmentAspect>(target);
auto exeAspect = addAspect<ExecutableAspect>(); auto exeAspect = addAspect<ExecutableAspect>(target);
exeAspect->setSettingsKey("RemoteLinux.CustomRunConfig.RemoteExecutable"); exeAspect->setSettingsKey("RemoteLinux.CustomRunConfig.RemoteExecutable");
exeAspect->setLabelText(tr("Remote executable:")); exeAspect->setLabelText(tr("Remote executable:"));
exeAspect->setExecutablePathStyle(OsTypeLinux);
exeAspect->setDisplayStyle(StringAspect::LineEditDisplay); exeAspect->setDisplayStyle(StringAspect::LineEditDisplay);
exeAspect->setHistoryCompleter("RemoteLinux.CustomExecutable.History"); exeAspect->setHistoryCompleter("RemoteLinux.CustomExecutable.History");
exeAspect->setExpectedKind(PathChooser::Any); exeAspect->setExpectedKind(PathChooser::Any);

View File

@@ -59,9 +59,8 @@ RemoteLinuxRunConfiguration::RemoteLinuxRunConfiguration(Target *target, Id id)
{ {
auto envAspect = addAspect<RemoteLinuxEnvironmentAspect>(target); auto envAspect = addAspect<RemoteLinuxEnvironmentAspect>(target);
auto exeAspect = addAspect<ExecutableAspect>(); auto exeAspect = addAspect<ExecutableAspect>(target);
exeAspect->setLabelText(tr("Executable on device:")); exeAspect->setLabelText(tr("Executable on device:"));
exeAspect->setExecutablePathStyle(OsTypeLinux);
exeAspect->setPlaceHolderText(tr("Remote path not set")); exeAspect->setPlaceHolderText(tr("Remote path not set"));
exeAspect->makeOverridable("RemoteLinux.RunConfig.AlternateRemoteExecutable", exeAspect->makeOverridable("RemoteLinux.RunConfig.AlternateRemoteExecutable",
"RemoteLinux.RunConfig.UseAlternateRemoteExecutable"); "RemoteLinux.RunConfig.UseAlternateRemoteExecutable");