summaryrefslogtreecommitdiffstats
path: root/src/tools/moc
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2013-08-20 09:02:17 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-13 11:48:08 +0200
commit31b4461097bd4bd0c128647bab896c2612ef82b0 (patch)
tree53710dab5d5f89650de71649b84589c212d1856f /src/tools/moc
parent209a5f1e8dc3e2275f225823ad9edfee09ba756c (diff)
moc: add -M<key=value> to ease static qml plugin linking
A module plugin in qml belongs to a URI/namespace. This uri is resolved run-time by QtDeclarative by knowing the path of the qmldir that references the plugin. For static plugins this becomes a problem, since we lost the information regarding which plugin belongs to which qmldir, since a static plugin has no file path. To avoid pushing the responsibility of clarifying this onto the application developer, it is better to embed this information into the meta data of the plugins themselves. Since this information can be resolved by the build system, a new option to moc has been added: -M<key=value> that will let you add meta tags to the meta data from the command line to each class that has an IID specified. For the URI case, we can then e.g do: -Muri=QtQuick.Controls -Muri=QtQuick.Controls.Private Change-Id: I81a156660148fc94db6f3cac0473e9e1c8458c58 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/tools/moc')
-rw-r--r--src/tools/moc/generator.cpp4
-rw-r--r--src/tools/moc/main.cpp23
-rw-r--r--src/tools/moc/moc.cpp4
-rw-r--r--src/tools/moc/moc.h4
4 files changed, 35 insertions, 0 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 50da6d2e54..cb18c2c4a5 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -1462,6 +1462,10 @@ void Generator::generatePluginMetaData()
data.insert(debugKey, QJsonValue(false));
data.insert(QStringLiteral("MetaData"), cdef->pluginData.metaData.object());
+ // Add -M args from the command line:
+ foreach (const QString &key, cdef->pluginData.metaArgs.keys())
+ data.insert(key, cdef->pluginData.metaArgs.value(key));
+
fputs("\nQT_PLUGIN_METADATA_SECTION const uint qt_section_alignment_dummy = 42;\n\n"
"#ifdef QT_NO_DEBUG\n", out);
writePluginMetaData(out, data);
diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp
index 999cae0e60..98472792f8 100644
--- a/src/tools/moc/main.cpp
+++ b/src/tools/moc/main.cpp
@@ -242,6 +242,11 @@ int runMoc(int argc, char **argv)
undefineOption.setValueName(QStringLiteral("macro"));
parser.addOption(undefineOption);
+ QCommandLineOption metadataOption(QStringLiteral("M"));
+ metadataOption.setDescription(QStringLiteral("Add key/value pair to plugin meta data"));
+ metadataOption.setValueName(QStringLiteral("key=value"));
+ parser.addOption(metadataOption);
+
QCommandLineOption noIncludeOption(QStringLiteral("i"));
noIncludeOption.setDescription(QStringLiteral("Do not generate an #include statement."));
parser.addOption(noIncludeOption);
@@ -385,6 +390,24 @@ int runMoc(int argc, char **argv)
moc.filename = filename.toLocal8Bit();
}
+ foreach (const QString &md, parser.values(metadataOption)) {
+ int split = md.indexOf(QLatin1Char('='));
+ QString key = md.left(split);
+ QString value = md.mid(split + 1);
+
+ if (split == -1 || key.isEmpty() || value.isEmpty()) {
+ error("missing key or value for option '-M'");
+ } else if (key.indexOf(QLatin1Char('.')) != -1) {
+ // Don't allow keys with '.' for now, since we might need this
+ // format later for more advanced meta data API
+ error("A key cannot contain the letter '.' for option '-M'");
+ } else {
+ QJsonArray array = moc.metaArgs.value(key);
+ array.append(value);
+ moc.metaArgs.insert(key, array);
+ }
+ }
+
moc.currentFilenames.push(filename.toLocal8Bit());
moc.includes = pp.includes;
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index 648723ebc1..8ff481d5b1 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -787,6 +787,10 @@ void Moc::parse()
if (!def.hasQObject && !def.hasQGadget)
error("Class declarations lacks Q_OBJECT macro.");
+ // Add meta tags to the plugin meta data:
+ if (!def.pluginData.iid.isEmpty())
+ def.pluginData.metaArgs = metaArgs;
+
checkSuperClasses(&def);
checkProperties(&def);
diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h
index f97a537215..2e22435653 100644
--- a/src/tools/moc/moc.h
+++ b/src/tools/moc/moc.h
@@ -47,6 +47,8 @@
#include <qmap.h>
#include <qpair.h>
#include <qjsondocument.h>
+#include <qjsonarray.h>
+#include <qjsonobject.h>
#include <stdio.h>
#include <ctype.h>
@@ -171,6 +173,7 @@ struct ClassDef {
struct PluginData {
QByteArray iid;
+ QMap<QString, QJsonArray> metaArgs;
QJsonDocument metaData;
} pluginData;
@@ -213,6 +216,7 @@ public:
QMap<QByteArray, QByteArray> interface2IdMap;
QList<QByteArray> metaTypes;
QSet<QByteArray> knownQObjectClasses;
+ QMap<QString, QJsonArray> metaArgs;
void parse();
void generate(FILE *out);