summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/main.cpp
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/main.cpp
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/main.cpp')
-rw-r--r--src/tools/moc/main.cpp23
1 files changed, 23 insertions, 0 deletions
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;