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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qbsnodes.h"
#include "qbsnodetreebuilder.h"
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsprojectmanagerplugin.h"
#include "qbssession.h"
#include <android/androidconstants.h>
#include <coreplugin/idocument.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <qtsupport/qtsupportconstants.h>
#include <resourceeditor/resourcenode.h>
#include <utils/algorithm.h>
#include <utils/fsengine/fileiconprovider.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <QtDebug>
#include <QDir>
#include <QIcon>
#include <QJsonArray>
using namespace ProjectExplorer;
using namespace Utils;
// ----------------------------------------------------------------------
// Helpers:
// ----------------------------------------------------------------------
namespace QbsProjectManager {
namespace Internal {
const QbsProductNode *parentQbsProductNode(const ProjectExplorer::Node *node)
{
for (; node; node = node->parentFolderNode()) {
const auto prdNode = dynamic_cast<const QbsProductNode *>(node);
if (prdNode)
return prdNode;
}
return nullptr;
}
// --------------------------------------------------------------------
// QbsGroupNode:
// --------------------------------------------------------------------
QbsGroupNode::QbsGroupNode(const QJsonObject &grp) : ProjectNode(FilePath()), m_groupData(grp)
{
setIcon(ProjectExplorer::Constants::FILEOVERLAY_GROUP);
setDisplayName(grp.value("name").toString());
setEnabled(grp.value("is-enabled").toBool());
}
FolderNode::AddNewInformation QbsGroupNode::addNewInformation(const FilePaths &files,
Node *context) const
{
AddNewInformation info = ProjectNode::addNewInformation(files, context);
if (context != this)
--info.priority;
return info;
}
QVariant QbsGroupNode::data(Id role) const
{
if (role == ProjectExplorer::Constants::QT_KEYWORDS_ENABLED) {
QJsonObject modProps = m_groupData.value("module-properties").toObject();
if (modProps.isEmpty()) {
const QbsProductNode * const prdNode = parentQbsProductNode(this);
QTC_ASSERT(prdNode, return QVariant());
modProps = prdNode->productData().value("module-properties").toObject();
}
return modProps.value("Qt.core.enableKeywords").toBool();
}
return QVariant();
}
// --------------------------------------------------------------------
// QbsProductNode:
// --------------------------------------------------------------------
QbsProductNode::QbsProductNode(const QJsonObject &prd) : ProjectNode(FilePath()), m_productData(prd)
{
setIcon(DirectoryIcon(ProjectExplorer::Constants::FILEOVERLAY_PRODUCT));
if (prd.value("is-runnable").toBool()) {
setProductType(ProductType::App);
} else {
const QJsonArray type = prd.value("type").toArray();
if (type.contains("dynamiclibrary") || type.contains("staticlibrary"))
setProductType(ProductType::Lib);
else
setProductType(ProductType::Other);
}
setEnabled(prd.value("is-enabled").toBool());
setDisplayName(prd.value("full-display-name").toString());
}
void QbsProductNode::build()
{
buildNamedProduct(static_cast<QbsProject *>(getProject()),
m_productData.value("full-display-name").toString());
}
QStringList QbsProductNode::targetApplications() const
{
return QStringList{m_productData.value("target-executable").toString()};
}
QString QbsProductNode::fullDisplayName() const
{
return m_productData.value("full-display-name").toString();
}
QString QbsProductNode::buildKey() const
{
return getBuildKey(productData());
}
QString QbsProductNode::getBuildKey(const QJsonObject &product)
{
return product.value("name").toString() + '.'
+ product.value("multiplex-configuration-id").toString();
}
bool QbsProductNode::isAggregated() const
{
return m_productData.value("is-multiplexed").toBool()
&& m_productData.value("multiplex-configuration-id").toString().isEmpty();
}
const QList<const QbsProductNode*> QbsProductNode::aggregatedProducts() const
{
if (!isAggregated())
return {};
const ProjectNode *parentNode = managingProject();
QTC_ASSERT(parentNode != nullptr && parentNode != this, return {});
QSet<QString> dependencies;
for (const auto &a : m_productData.value("dependencies").toArray())
dependencies << a.toString();
QList<const QbsProductNode*> qbsProducts;
parentNode->forEachProjectNode([&qbsProducts, dependencies](const ProjectNode *node) {
if (const auto qbsChildNode = dynamic_cast<const QbsProductNode *>(node)) {
if (dependencies.contains(qbsChildNode->fullDisplayName()))
qbsProducts << qbsChildNode;
}
});
return qbsProducts;
}
QVariant QbsProductNode::data(Id role) const
{
if (role == Android::Constants::AndroidDeploySettingsFile) {
for (const auto &a : m_productData.value("generated-artifacts").toArray()) {
const QJsonObject artifact = a.toObject();
if (artifact.value("file-tags").toArray().contains("qt_androiddeployqt_input"))
return artifact.value("file-path").toString();
}
return {};
}
if (role == Android::Constants::AndroidSoLibPath) {
QStringList ret{m_productData.value("build-directory").toString()};
if (!isAggregated()) {
forAllArtifacts(m_productData, ArtifactType::Generated,
[&ret](const QJsonObject &artifact) {
if (artifact.value("file-tags").toArray().contains("dynamiclibrary"))
ret << QFileInfo(artifact.value("file-path").toString()).path();
});
} else {
for (const auto &a : aggregatedProducts())
ret += a->data(Android::Constants::AndroidSoLibPath).toStringList();
}
ret.removeDuplicates();
return ret;
}
if (role == Android::Constants::AndroidManifest) {
for (const auto &a : m_productData.value("generated-artifacts").toArray()) {
const QJsonObject artifact = a.toObject();
if (artifact.value("file-tags").toArray().contains("android.manifest_final"))
return artifact.value("file-path").toString();
}
return {};
}
if (role == Android::Constants::AndroidApk)
return m_productData.value("target-executable").toString();
if (role == ProjectExplorer::Constants::QT_KEYWORDS_ENABLED)
return m_productData.value("module-properties").toObject()
.value("Qt.core.enableKeywords").toBool();
if (role == Android::Constants::AndroidAbis) {
// Try using qbs.architectures
QStringList qbsAbis;
QMap<QString, QString> archToAbi {
{"armv7a", ProjectExplorer::Constants::ANDROID_ABI_ARMEABI_V7A},
{"arm64", ProjectExplorer::Constants::ANDROID_ABI_ARM64_V8A},
{"x86", ProjectExplorer::Constants::ANDROID_ABI_X86},
{"x86_64", ProjectExplorer::Constants::ANDROID_ABI_X86_64}};
for (const auto &a : m_productData.value("module-properties").toObject()
.value(Constants::QBS_ARCHITECTURES).toArray()) {
if (archToAbi.contains(a.toString()))
qbsAbis << archToAbi[a.toString()];
}
if (!qbsAbis.empty())
return qbsAbis;
// Try using qbs.architecture
QString architecture = m_productData.value("module-properties").toObject()
.value(Constants::QBS_ARCHITECTURE).toString();
if (archToAbi.contains(architecture))
qbsAbis << archToAbi[architecture];
return qbsAbis;
}
if (role == Android::Constants::AndroidPackageSourceDir) {
return m_productData.value("properties").toObject()
.value("sourceDirectory").toString();
}
if (role == Android::Constants::AndroidClassPaths) {
QStringList paths;
for (const auto &p : m_productData.value("module-properties").toObject()
.value(Constants::JAVA_ADDITIONAL_CLASSPATHS).toArray()) {
if (p.isString())
paths << p.toString();
}
return paths;
}
return {};
}
QJsonObject QbsProductNode::mainGroup() const
{
for (const QJsonValue &g : m_productData.value("groups").toArray()) {
const QJsonObject grp = g.toObject();
if (grp.value("name") == m_productData.value("name")
&& grp.value("location") == m_productData.value("location")) {
return grp;
}
}
return {};
}
// --------------------------------------------------------------------
// QbsProjectNode:
// --------------------------------------------------------------------
QbsProjectNode::QbsProjectNode(const QJsonObject &projectData)
: ProjectNode(FilePath()), m_projectData(projectData)
{
setIcon(DirectoryIcon(ProjectExplorer::Constants::FILEOVERLAY_QT));
setDisplayName(projectData.value("name").toString());
}
} // namespace Internal
} // namespace QbsProjectManager
|