summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2017-01-26 11:47:54 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2017-01-26 14:18:00 +0000
commita1633aba4e6b0c17651b0a4938efc3f50767bd71 (patch)
tree728e80cd646ac8de8a3c73a834ac36b0c924f055 /src
parent13d737446fde43aae0c832d5ca091eb7ebe4f2d7 (diff)
downloadqbs-a1633aba4e6b0c17651b0a4938efc3f50767bd71.tar.gz
Clean up ArtifactBindingsExtractor
Let extractPropertyValues construct exactly what is needed in apply instead of converting from a string list into a similar but different string list. Change-Id: I947afe2170b44bce48ad2484e730e4360e21244c Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/lib/corelib/buildgraph/rulesapplicator.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/lib/corelib/buildgraph/rulesapplicator.cpp b/src/lib/corelib/buildgraph/rulesapplicator.cpp
index d8d29cbe3..708cb5fc2 100644
--- a/src/lib/corelib/buildgraph/rulesapplicator.cpp
+++ b/src/lib/corelib/buildgraph/rulesapplicator.cpp
@@ -64,6 +64,8 @@
#include <QtScript/qscriptvalueiterator.h>
+#include <vector>
+
namespace qbs {
namespace Internal {
@@ -411,8 +413,17 @@ QList<Artifact *> RulesApplicator::runOutputArtifactsScript(const ArtifactSet &i
class ArtifactBindingsExtractor
{
- typedef QPair<QStringList, QVariant> NameValuePair;
- QList<NameValuePair> m_propertyValues;
+ struct Entry
+ {
+ Entry(const QString &module, const QString &name, const QVariant &value)
+ : module(module), name(name), value(value)
+ {}
+
+ QString module;
+ QString name;
+ QVariant value;
+ };
+ std::vector<Entry> m_propertyValues;
static Set<QString> getArtifactItemPropertyNames()
{
@@ -426,13 +437,13 @@ class ArtifactBindingsExtractor
return s;
}
- void extractPropertyValues(const QScriptValue &obj, QStringList fullName = QStringList())
+ void extractPropertyValues(const QScriptValue &obj, QString moduleName = QString())
{
QScriptValueIterator svit(obj);
while (svit.hasNext()) {
svit.next();
const QString name = svit.name();
- if (fullName.isEmpty()) {
+ if (moduleName.isEmpty()) {
// Ignore property names that are part of the Artifact item.
static const Set<QString> artifactItemPropertyNames
= getArtifactItemPropertyNames();
@@ -441,36 +452,29 @@ class ArtifactBindingsExtractor
}
const QScriptValue value = svit.value();
- fullName.append(name);
- if (value.isObject() && !value.isArray() && !value.isError() && !value.isRegExp())
- extractPropertyValues(value, fullName);
- else
- m_propertyValues.append(NameValuePair(fullName, value.toVariant()));
- fullName.removeLast();
+ if (value.isObject() && !value.isArray() && !value.isError() && !value.isRegExp()) {
+ if (!moduleName.isEmpty())
+ moduleName.append(QLatin1Char('.'));
+ moduleName.append(name);
+ extractPropertyValues(value, moduleName);
+ } else {
+ m_propertyValues.emplace_back(moduleName, name, value.toVariant());
+ }
}
}
public:
void apply(Artifact *outputArtifact, const QScriptValue &obj)
{
extractPropertyValues(obj);
- if (m_propertyValues.isEmpty())
+ if (m_propertyValues.empty())
return;
outputArtifact->properties = outputArtifact->properties->clone();
QVariantMap artifactCfg = outputArtifact->properties->value();
- foreach (const NameValuePair &nvp, m_propertyValues)
- setConfigProperty(artifactCfg, constructValuePath(nvp.first), nvp.second);
+ for (const auto &e : m_propertyValues)
+ setConfigProperty(artifactCfg, {QStringLiteral("modules"), e.module, e.name}, e.value);
outputArtifact->properties->setValue(artifactCfg);
}
-
- static QStringList constructValuePath(const QStringList &nameParts)
- {
- return {
- QLatin1String("modules"),
- nameParts.mid(0, nameParts.length() - 1).join(QLatin1Char('.')),
- nameParts.last()
- };
- }
};
Artifact *RulesApplicator::createOutputArtifactFromScriptValue(const QScriptValue &obj,