From 31b4461097bd4bd0c128647bab896c2612ef82b0 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 20 Aug 2013 09:02:17 +0200 Subject: moc: add -M 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 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 --- src/tools/moc/generator.cpp | 4 ++++ src/tools/moc/main.cpp | 23 +++++++++++++++++++++++ src/tools/moc/moc.cpp | 4 ++++ src/tools/moc/moc.h | 4 ++++ 4 files changed, 35 insertions(+) (limited to 'src/tools/moc') 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 #include #include +#include +#include #include #include @@ -171,6 +173,7 @@ struct ClassDef { struct PluginData { QByteArray iid; + QMap metaArgs; QJsonDocument metaData; } pluginData; @@ -213,6 +216,7 @@ public: QMap interface2IdMap; QList metaTypes; QSet knownQObjectClasses; + QMap metaArgs; void parse(); void generate(FILE *out); -- cgit v1.2.3