aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/boot2qt/qdbrunconfiguration.cpp
blob: 8a4c3db6ae1f5645ff6c8839353cb56b3cfe13fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "qdbrunconfiguration.h"

#include "qdbconstants.h"
#include "qdbtr.h"

#include <projectexplorer/buildsystem.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/devicesupport/devicekitaspects.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>

#include <remotelinux/remotelinuxenvironmentaspect.h>

#include <utils/commandline.h>
#include <utils/qtcassert.h>

using namespace ProjectExplorer;
using namespace Utils;

namespace Qdb::Internal {

// QdbRunConfiguration

class QdbRunConfiguration : public RunConfiguration
{
public:
    QdbRunConfiguration(BuildConfiguration *bc, Id id)
        : RunConfiguration(bc, id)
    {
        setDefaultDisplayName(Tr::tr("Run on Boot to Qt Device"));

        executable.setDeviceSelector(kit(), ExecutableAspect::RunDevice);
        executable.setSettingsKey("QdbRunConfig.RemoteExecutable");
        executable.setLabelText(Tr::tr("Executable on device:"));
        executable.setPlaceHolderText(Tr::tr("Remote path not set"));
        executable.makeOverridable("QdbRunConfig.AlternateRemoteExecutable",
                                   "QdbRunCofig.UseAlternateRemoteExecutable");

        symbolFile.setSettingsKey("QdbRunConfig.LocalExecutable");
        symbolFile.setLabelText(Tr::tr("Executable on host:"));

        environment.setDeviceSelector(kit(), EnvironmentAspect::RunDevice);

        workingDir.setEnvironment(&environment);

        fullCommand.setLabelText(Tr::tr("Full command line:"));

        setUpdater([this] {
            const BuildTargetInfo bti = buildTargetInfo();
            const FilePath localExecutable = bti.targetFilePath;
            const DeployableFile depFile = buildSystem()->deploymentData().deployableForLocalFile(
                localExecutable);
            IDevice::ConstPtr dev = RunDeviceKitAspect::device(kit());
            QTC_ASSERT(dev, return);
            executable.setExecutable(dev->filePath(depFile.remoteFilePath()));
            symbolFile.setValue(localExecutable);
        });

        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());
        };

        arguments.addOnChanged(this, updateFullCommand);
        executable.addOnChanged(this, updateFullCommand);
        updateFullCommand();
    }

private:
    Tasks checkForIssues() const override
    {
        Tasks tasks;
        if (executable().isEmpty()) {
            tasks << BuildSystemTask(Task::Warning, Tr::tr("The remote executable must be set "
                                                           "to run on a Boot to Qt device."));
        }
        return tasks;
    }

    ExecutableAspect executable{this};
    SymbolFileAspect symbolFile{this};
    RemoteLinux::RemoteLinuxEnvironmentAspect environment{this};
    ArgumentsAspect arguments{this};
    WorkingDirectoryAspect workingDir{this};
    StringAspect fullCommand{this};
};

// QdbRunConfigurationFactory

QdbRunConfigurationFactory::QdbRunConfigurationFactory()
{
    registerRunConfiguration<QdbRunConfiguration>(Constants::QdbRunConfigurationId);
    addSupportedTargetDeviceType(Constants::QdbLinuxOsType);
}

} // Qdb::Internal