baremetalrunconfiguration.cpp 6.01 KB
Newer Older
Tim Sander's avatar
Tim Sander committed
1
2
/****************************************************************************
**
3
4
** Copyright (C) 2016 Tim Sander <tim@krieglstein.org>
** Contact: https://www.qt.io/licensing/
Tim Sander's avatar
Tim Sander committed
5
6
7
8
9
10
11
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12
13
14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
Tim Sander's avatar
Tim Sander committed
15
**
16
17
18
19
20
21
22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Tim Sander's avatar
Tim Sander committed
23
24
25
26
27
28
29
30
31
32
33
**
****************************************************************************/

#include "baremetalrunconfiguration.h"

#include "baremetalrunconfigurationwidget.h"

#include <debugger/debuggerrunconfigurationaspect.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/project.h>
34
#include <projectexplorer/runconfigurationaspects.h>
Tim Sander's avatar
Tim Sander committed
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <projectexplorer/target.h>
#include <qtsupport/qtoutputformatter.h>

using namespace ProjectExplorer;
using namespace Utils;

namespace BareMetal {
namespace Internal {

const char ProFileKey[] = "Qt4ProjectManager.MaemoRunConfiguration.ProFile";
const char WorkingDirectoryKey[] = "BareMetal.RunConfig.WorkingDirectory";


hjk's avatar
hjk committed
48
49
50
51
BareMetalRunConfiguration::BareMetalRunConfiguration(Target *parent, BareMetalRunConfiguration *other)
    : RunConfiguration(parent, other),
      m_projectFilePath(other->m_projectFilePath),
      m_workingDirectory(other->m_workingDirectory)
Tim Sander's avatar
Tim Sander committed
52
53
54
55
56
57
58
{
    init();
}

BareMetalRunConfiguration::BareMetalRunConfiguration(Target *parent,
                                                     const Core::Id id,
                                                     const QString &projectFilePath)
hjk's avatar
hjk committed
59
60
    : RunConfiguration(parent, id),
      m_projectFilePath(projectFilePath)
Tim Sander's avatar
Tim Sander committed
61
{
62
    addExtraAspect(new ArgumentsAspect(this, QLatin1String("Qt4ProjectManager.MaemoRunConfiguration.Arguments")));
Tim Sander's avatar
Tim Sander committed
63
64
65
66
67
68
69
    init();
}

void BareMetalRunConfiguration::init()
{
    setDefaultDisplayName(defaultDisplayName());

hjk's avatar
hjk committed
70
71
72
73
74
75
    connect(target(), &Target::deploymentDataChanged,
            this, &BareMetalRunConfiguration::handleBuildSystemDataUpdated);
    connect(target(), &Target::applicationTargetsChanged,
            this, &BareMetalRunConfiguration::handleBuildSystemDataUpdated);
    connect(target(), &Target::kitChanged,
            this, &BareMetalRunConfiguration::handleBuildSystemDataUpdated); // Handles device changes, etc.
Tim Sander's avatar
Tim Sander committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
}

QWidget *BareMetalRunConfiguration::createConfigurationWidget()
{
    return new BareMetalRunConfigurationWidget(this);
}

OutputFormatter *BareMetalRunConfiguration::createOutputFormatter() const
{
    return new QtSupport::QtOutputFormatter(target()->project());
}

QVariantMap BareMetalRunConfiguration::toMap() const
{
    QVariantMap map(RunConfiguration::toMap());
91
    const QDir dir = QDir(target()->project()->projectDirectory().toString());
hjk's avatar
hjk committed
92
93
    map.insert(QLatin1String(ProFileKey), dir.relativeFilePath(m_projectFilePath));
    map.insert(QLatin1String(WorkingDirectoryKey), m_workingDirectory);
Tim Sander's avatar
Tim Sander committed
94
95
96
97
98
99
100
101
    return map;
}

bool BareMetalRunConfiguration::fromMap(const QVariantMap &map)
{
    if (!RunConfiguration::fromMap(map))
        return false;

102
    const QDir dir = QDir(target()->project()->projectDirectory().toString());
hjk's avatar
hjk committed
103
    m_projectFilePath
Tim Sander's avatar
Tim Sander committed
104
            = QDir::cleanPath(dir.filePath(map.value(QLatin1String(ProFileKey)).toString()));
hjk's avatar
hjk committed
105
    m_workingDirectory = map.value(QLatin1String(WorkingDirectoryKey)).toString();
Tim Sander's avatar
Tim Sander committed
106
107
108
109
110
111
112
113

    setDefaultDisplayName(defaultDisplayName());

    return true;
}

QString BareMetalRunConfiguration::defaultDisplayName()
{
hjk's avatar
hjk committed
114
    if (!m_projectFilePath.isEmpty())
Tim Sander's avatar
Tim Sander committed
115
        //: %1 is the name of the project run via hardware debugger
hjk's avatar
hjk committed
116
        return tr("%1 (via GDB server or hardware debugger)").arg(QFileInfo(m_projectFilePath).completeBaseName());
Tim Sander's avatar
Tim Sander committed
117
    //: Bare Metal run configuration default run name
118
    return tr("Run on GDB server or hardware debugger");
Tim Sander's avatar
Tim Sander committed
119
120
121
122
}

QString BareMetalRunConfiguration::localExecutableFilePath() const
{
123
124
    const QString targetName = QFileInfo(m_projectFilePath).completeBaseName();

Tim Sander's avatar
Tim Sander committed
125
    return target()->applicationTargets()
126
              .targetFilePath(FileName::fromString(targetName).toString()).toString();
Tim Sander's avatar
Tim Sander committed
127
128
129
130
}

QString BareMetalRunConfiguration::arguments() const
{
131
    return extraAspect<ArgumentsAspect>()->arguments();
Tim Sander's avatar
Tim Sander committed
132
133
134
135
}

QString BareMetalRunConfiguration::workingDirectory() const
{
hjk's avatar
hjk committed
136
    return m_workingDirectory;
Tim Sander's avatar
Tim Sander committed
137
138
139
140
}

void BareMetalRunConfiguration::setWorkingDirectory(const QString &wd)
{
hjk's avatar
hjk committed
141
    m_workingDirectory = wd;
Tim Sander's avatar
Tim Sander committed
142
143
144
145
}

QString BareMetalRunConfiguration::projectFilePath() const
{
hjk's avatar
hjk committed
146
    return m_projectFilePath;
Tim Sander's avatar
Tim Sander committed
147
148
}

149
150
151
QString BareMetalRunConfiguration::buildSystemTarget() const
{
    const BuildTargetInfoList targets = target()->applicationTargets();
152
153
    const Utils::FileName projectFilePath = Utils::FileName::fromString(QFileInfo(m_projectFilePath).path());
    const QString targetName = QFileInfo(m_projectFilePath).completeBaseName();
154
    auto bst = std::find_if(targets.list.constBegin(), targets.list.constEnd(),
155
                            [&projectFilePath,&targetName](const BuildTargetInfo &bti) { return bti.projectFilePath == projectFilePath && bti.targetName == targetName; });
156
157
158
    return (bst == targets.list.constEnd()) ? QString() : bst->targetName;
}

Tim Sander's avatar
Tim Sander committed
159
160
161
void BareMetalRunConfiguration::handleBuildSystemDataUpdated()
{
    emit targetInformationChanged();
162
    emit enabledChanged();
Tim Sander's avatar
Tim Sander committed
163
164
}

165
const char *BareMetalRunConfiguration::IdPrefix = "BareMetal";
Tim Sander's avatar
Tim Sander committed
166

hjk's avatar
hjk committed
167
} // namespace Internal
Tim Sander's avatar
Tim Sander committed
168
169
} // namespace BareMetal