2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-06-04 14:22:35 +02:00
|
|
|
|
|
|
|
|
#include "qdbmakedefaultappstep.h"
|
|
|
|
|
|
2020-02-20 13:51:49 +01:00
|
|
|
#include "qdbconstants.h"
|
2023-01-18 08:42:48 +01:00
|
|
|
#include "qdbtr.h"
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2022-06-22 15:43:33 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2019-06-13 18:25:17 +02:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
2022-05-04 08:01:57 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2019-06-13 18:25:17 +02:00
|
|
|
|
2020-02-20 13:51:49 +01:00
|
|
|
#include <remotelinux/abstractremotelinuxdeploystep.h>
|
|
|
|
|
|
2022-05-04 08:01:57 +02:00
|
|
|
#include <utils/commandline.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2022-05-04 08:01:57 +02:00
|
|
|
|
2019-06-13 18:25:17 +02:00
|
|
|
using namespace ProjectExplorer;
|
2020-09-18 12:11:40 +02:00
|
|
|
using namespace Utils;
|
2022-11-24 17:57:15 +01:00
|
|
|
using namespace Utils::Tasking;
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2023-01-18 08:42:48 +01:00
|
|
|
namespace Qdb::Internal {
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
class QdbMakeDefaultAppStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep
|
2020-02-20 13:51:49 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2023-03-21 16:07:20 +01:00
|
|
|
QdbMakeDefaultAppStep(BuildStepList *bsl, Id id)
|
|
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
|
|
|
|
{
|
|
|
|
|
auto selection = addAspect<SelectionAspect>();
|
|
|
|
|
selection->setSettingsKey("QdbMakeDefaultDeployStep.MakeDefault");
|
|
|
|
|
selection->addOption(Tr::tr("Set this application to start by default"));
|
|
|
|
|
selection->addOption(Tr::tr("Reset default application"));
|
|
|
|
|
|
|
|
|
|
setInternalInitializer([this, selection] {
|
|
|
|
|
m_makeDefault = selection->value() == 0;
|
|
|
|
|
return isDeploymentPossible();
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-04 08:01:57 +02:00
|
|
|
|
|
|
|
|
private:
|
2022-11-24 21:45:00 +01:00
|
|
|
Group deployRecipe() final
|
2022-05-04 08:01:57 +02:00
|
|
|
{
|
2023-05-03 16:00:22 +02:00
|
|
|
const auto setupHandler = [this](Process &process) {
|
2022-11-24 17:57:15 +01:00
|
|
|
QString remoteExe;
|
|
|
|
|
if (RunConfiguration *rc = target()->activeRunConfiguration()) {
|
|
|
|
|
if (auto exeAspect = rc->aspect<ExecutableAspect>())
|
2022-12-02 12:00:51 +01:00
|
|
|
remoteExe = exeAspect->executable().nativePath();
|
2022-11-24 17:57:15 +01:00
|
|
|
}
|
2022-12-12 11:26:08 +01:00
|
|
|
CommandLine cmd{deviceConfiguration()->filePath(Constants::AppcontrollerFilepath)};
|
|
|
|
|
if (m_makeDefault && !remoteExe.isEmpty())
|
|
|
|
|
cmd.addArgs({"--make-default", remoteExe});
|
|
|
|
|
else
|
|
|
|
|
cmd.addArg("--remove-default");
|
|
|
|
|
process.setCommand(cmd);
|
2023-05-03 16:00:22 +02:00
|
|
|
Process *proc = &process;
|
|
|
|
|
connect(proc, &Process::readyReadStandardError, this, [this, proc] {
|
2023-03-22 09:34:34 +01:00
|
|
|
handleStdErrData(proc->readAllStandardError());
|
2022-11-24 17:57:15 +01:00
|
|
|
});
|
|
|
|
|
};
|
2023-05-03 16:00:22 +02:00
|
|
|
const auto doneHandler = [this](const Process &) {
|
2022-11-24 17:57:15 +01:00
|
|
|
if (m_makeDefault)
|
2023-03-22 09:34:34 +01:00
|
|
|
addProgressMessage(Tr::tr("Application set as the default one."));
|
2022-11-24 17:57:15 +01:00
|
|
|
else
|
2023-03-22 09:34:34 +01:00
|
|
|
addProgressMessage(Tr::tr("Reset the default application."));
|
2022-11-24 17:57:15 +01:00
|
|
|
};
|
2023-05-03 16:00:22 +02:00
|
|
|
const auto errorHandler = [this](const Process &process) {
|
2023-03-22 09:34:34 +01:00
|
|
|
addErrorMessage(Tr::tr("Remote process failed: %1").arg(process.errorString()));
|
2022-11-24 17:57:15 +01:00
|
|
|
};
|
2023-05-03 14:06:15 +02:00
|
|
|
return Group { ProcessTask(setupHandler, doneHandler, errorHandler) };
|
2022-05-04 08:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool m_makeDefault = true;
|
2020-02-20 13:51:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// QdbMakeDefaultAppStepFactory
|
2019-06-04 14:22:35 +02:00
|
|
|
|
2020-02-20 13:51:49 +01:00
|
|
|
QdbMakeDefaultAppStepFactory::QdbMakeDefaultAppStepFactory()
|
2019-06-04 14:22:35 +02:00
|
|
|
{
|
2020-02-20 13:51:49 +01:00
|
|
|
registerStep<QdbMakeDefaultAppStep>(Constants::QdbMakeDefaultAppStepId);
|
2023-01-18 08:42:48 +01:00
|
|
|
setDisplayName(Tr::tr("Change default application"));
|
2020-02-20 13:51:49 +01:00
|
|
|
setSupportedDeviceType(Qdb::Constants::QdbLinuxOsType);
|
|
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
|
2019-06-04 14:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-18 08:42:48 +01:00
|
|
|
} // Qdb::Internal
|