aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/baremetal/baremetalrunconfiguration.cpp
blob: 8b16aadb533e21b5e9ac8416661940f09f86c1cc (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
// Copyright (C) 2016 Tim Sander <tim@krieglstein.org>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "baremetalconstants.h"
#include "baremetalrunconfiguration.h"

#include <projectexplorer/buildsystem.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>

using namespace ProjectExplorer;
using namespace Utils;

namespace BareMetal {
namespace Internal {

// RunConfigurations

class BareMetalRunConfiguration final : public RunConfiguration
{
    Q_DECLARE_TR_FUNCTIONS(BareMetal::Internal::BareMetalRunConfiguration)

public:
    explicit BareMetalRunConfiguration(Target *target, Id id)
        : RunConfiguration(target, id)
    {
        const auto exeAspect = addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
        exeAspect->setDisplayStyle(StringAspect::LabelDisplay);
        exeAspect->setPlaceHolderText(tr("Unknown"));

        addAspect<ArgumentsAspect>(macroExpander());
        addAspect<WorkingDirectoryAspect>(macroExpander(), nullptr);

        setUpdater([this, exeAspect] {
            const BuildTargetInfo bti = buildTargetInfo();
            exeAspect->setExecutable(bti.targetFilePath);
        });

        connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
    }
};

class BareMetalCustomRunConfiguration final : public RunConfiguration
{
    Q_DECLARE_TR_FUNCTIONS(BareMetal::Internal::BareMetalCustomRunConfiguration)

public:
    explicit BareMetalCustomRunConfiguration(Target *target, Id id)
        : RunConfiguration(target, id)
    {
        const auto exeAspect = addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
        exeAspect->setSettingsKey("BareMetal.CustomRunConfig.Executable");
        exeAspect->setPlaceHolderText(tr("Unknown"));
        exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay);
        exeAspect->setHistoryCompleter("BareMetal.CustomRunConfig.History");
        exeAspect->setExpectedKind(PathChooser::Any);

        addAspect<ArgumentsAspect>(macroExpander());
        addAspect<WorkingDirectoryAspect>(macroExpander(), nullptr);

        setDefaultDisplayName(RunConfigurationFactory::decoratedTargetName(tr("Custom Executable"), target));
    }

public:
    Tasks checkForIssues() const final;
};

Tasks BareMetalCustomRunConfiguration::checkForIssues() const
{
    Tasks tasks;
    if (aspect<ExecutableAspect>()->executable().isEmpty()) {
        tasks << createConfigurationIssue(tr("The remote executable must be set in order to run "
                                             "a custom remote run configuration."));
    }
    return tasks;
}

// BareMetalRunConfigurationFactory

BareMetalRunConfigurationFactory::BareMetalRunConfigurationFactory()
{
    registerRunConfiguration<BareMetalRunConfiguration>("BareMetalCustom");
    setDecorateDisplayNames(true);
    addSupportedTargetDeviceType(BareMetal::Constants::BareMetalOsType);
}

// BaseMetalCustomRunConfigurationFactory

BareMetalCustomRunConfigurationFactory::BareMetalCustomRunConfigurationFactory()
    : FixedRunConfigurationFactory(BareMetalCustomRunConfiguration::tr("Custom Executable"), true)
{
    registerRunConfiguration<BareMetalCustomRunConfiguration>("BareMetal");
    addSupportedTargetDeviceType(BareMetal::Constants::BareMetalOsType);
}

} // namespace Internal
} // namespace BareMetal