Boot2Qt: Use aspects more directly in QdbRunConfiguration

Change-Id: I8a199f449824ff973f5278f39172307be0e11438
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-07-07 19:27:39 +02:00
parent 323f29a3bd
commit 8ba6f11e9c

View File

@@ -25,106 +25,87 @@ using namespace Utils;
namespace Qdb::Internal { namespace Qdb::Internal {
// FullCommandLineAspect
class FullCommandLineAspect : public StringAspect
{
public:
explicit FullCommandLineAspect(RunConfiguration *rc)
{
setLabelText(Tr::tr("Full command line:"));
auto exeAspect = rc->aspect<ExecutableAspect>();
auto argumentsAspect = rc->aspect<ArgumentsAspect>();
auto updateCommandLine = [this, exeAspect, argumentsAspect] {
CommandLine plain{exeAspect->executable(), argumentsAspect->arguments(), CommandLine::Raw};
CommandLine cmd;
cmd.setExecutable(plain.executable().withNewPath(Constants::AppcontrollerFilepath));
cmd.addCommandLineAsArgs(plain);
setValue(cmd.toUserOutput());
};
connect(argumentsAspect, &ArgumentsAspect::changed, this, updateCommandLine);
connect(exeAspect, &ExecutableAspect::changed, this, updateCommandLine);
updateCommandLine();
}
};
// QdbRunConfiguration // QdbRunConfiguration
class QdbRunConfiguration : public RunConfiguration class QdbRunConfiguration : public RunConfiguration
{ {
public: public:
QdbRunConfiguration(Target *target, Utils::Id id); QdbRunConfiguration(Target *target, Id id)
private:
Tasks checkForIssues() const override;
QString defaultDisplayName() const;
};
QdbRunConfiguration::QdbRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto exeAspect = addAspect<ExecutableAspect>(); setDefaultDisplayName(Tr::tr("Run on Boot2Qt Device"));
exeAspect->setDeviceSelector(target, ExecutableAspect::RunDevice);
exeAspect->setSettingsKey("QdbRunConfig.RemoteExecutable"); executable.setDeviceSelector(target, ExecutableAspect::RunDevice);
exeAspect->setLabelText(Tr::tr("Executable on device:")); executable.setSettingsKey("QdbRunConfig.RemoteExecutable");
exeAspect->setPlaceHolderText(Tr::tr("Remote path not set")); executable.setLabelText(Tr::tr("Executable on device:"));
exeAspect->makeOverridable("QdbRunConfig.AlternateRemoteExecutable", executable.setPlaceHolderText(Tr::tr("Remote path not set"));
executable.makeOverridable("QdbRunConfig.AlternateRemoteExecutable",
"QdbRunCofig.UseAlternateRemoteExecutable"); "QdbRunCofig.UseAlternateRemoteExecutable");
auto symbolsAspect = addAspect<SymbolFileAspect>(); symbolFile.setSettingsKey("QdbRunConfig.LocalExecutable");
symbolsAspect->setSettingsKey("QdbRunConfig.LocalExecutable"); symbolFile.setLabelText(Tr::tr("Executable on host:"));
symbolsAspect->setLabelText(Tr::tr("Executable on host:")); symbolFile.setDisplayStyle(SymbolFileAspect::LabelDisplay);
symbolsAspect->setDisplayStyle(SymbolFileAspect::LabelDisplay);
auto envAspect = addAspect<RemoteLinux::RemoteLinuxEnvironmentAspect>(); environment.setDeviceSelector(target, EnvironmentAspect::RunDevice);
envAspect->setDeviceSelector(target, EnvironmentAspect::RunDevice);
auto argsAspect = addAspect<ArgumentsAspect>(); arguments.setMacroExpander(macroExpander());
argsAspect->setMacroExpander(macroExpander());
auto workingDirAspect = addAspect<WorkingDirectoryAspect>(); workingDir.setMacroExpander(macroExpander());
workingDirAspect->setMacroExpander(macroExpander()); workingDir.setEnvironment(&environment);
workingDirAspect->setEnvironment(envAspect); fullCommand.setLabelText(Tr::tr("Full command line:"));
addAspect<FullCommandLineAspect>(this); setUpdater([this, target] {
setUpdater([this, target, exeAspect, symbolsAspect] {
const BuildTargetInfo bti = buildTargetInfo(); const BuildTargetInfo bti = buildTargetInfo();
const FilePath localExecutable = bti.targetFilePath; const FilePath localExecutable = bti.targetFilePath;
const DeployableFile depFile = target->deploymentData().deployableForLocalFile(localExecutable); const DeployableFile depFile = target->deploymentData().deployableForLocalFile(localExecutable);
IDevice::ConstPtr dev = DeviceKitAspect::device(target->kit()); IDevice::ConstPtr dev = DeviceKitAspect::device(target->kit());
QTC_ASSERT(dev, return); QTC_ASSERT(dev, return);
exeAspect->setExecutable(dev->filePath(depFile.remoteFilePath())); executable.setExecutable(dev->filePath(depFile.remoteFilePath()));
symbolsAspect->setValue(localExecutable); symbolFile.setValue(localExecutable);
}); });
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
connect(target, &Target::deploymentDataChanged, this, &RunConfiguration::update); connect(target, &Target::deploymentDataChanged, this, &RunConfiguration::update);
connect(target, &Target::kitChanged, this, &RunConfiguration::update); connect(target, &Target::kitChanged, this, &RunConfiguration::update);
setDefaultDisplayName(Tr::tr("Run on Boot2Qt Device")); auto updateFullCommand = [this] {
CommandLine plain{executable(), arguments(), CommandLine::Raw};
CommandLine cmd;
cmd.setExecutable(plain.executable().withNewPath(Constants::AppcontrollerFilepath));
cmd.addCommandLineAsArgs(plain);
fullCommand.setValue(cmd.toUserOutput());
};
connect(&arguments, &BaseAspect::changed, this, updateFullCommand);
connect(&executable, &BaseAspect::changed, this, updateFullCommand);
updateFullCommand();
} }
Tasks QdbRunConfiguration::checkForIssues() const private:
Tasks checkForIssues() const override
{ {
Tasks tasks; Tasks tasks;
if (aspect<ExecutableAspect>()->executable().toString().isEmpty()) { if (executable().isEmpty()) {
tasks << BuildSystemTask(Task::Warning, Tr::tr("The remote executable must be set " tasks << BuildSystemTask(Task::Warning, Tr::tr("The remote executable must be set "
"in order to run on a Boot2Qt device.")); "in order to run on a Boot2Qt device."));
} }
return tasks; return tasks;
} }
QString QdbRunConfiguration::defaultDisplayName() const QString defaultDisplayName() const
{ {
return RunConfigurationFactory::decoratedTargetName(buildKey(), target()); return RunConfigurationFactory::decoratedTargetName(buildKey(), target());
} }
ExecutableAspect executable{this};
SymbolFileAspect symbolFile{this};
RemoteLinux::RemoteLinuxEnvironmentAspect environment{this};
ArgumentsAspect arguments{this};
WorkingDirectoryAspect workingDir{this};
StringAspect fullCommand{this};
};
// QdbRunConfigurationFactory // QdbRunConfigurationFactory
QdbRunConfigurationFactory::QdbRunConfigurationFactory() QdbRunConfigurationFactory::QdbRunConfigurationFactory()