diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2020-03-05 16:42:04 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2020-03-09 12:40:18 +0000 |
commit | 2382a5e8e917013725977b37bbe227d9a19b1d39 (patch) | |
tree | d3ea94f18fb37792b9943131c49d625b0abd858b /share | |
parent | 1b3f4b0ac80c0b66eef2c03df4c4385044aa7ba6 (diff) |
Qt: Add support for the new QML type registration mechanism
This implements the Qt 5.15 type registration approach via
the qmltyperegistrar tool.
Fixes: QBS-1531
Change-Id: Id77572a521513dc1759b02a7f7299377c2bcaabb
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/module-providers/Qt/setup-qt.js | 15 | ||||
-rw-r--r-- | share/qbs/module-providers/Qt/templates/qml.qbs | 70 |
2 files changed, 83 insertions, 2 deletions
diff --git a/share/qbs/module-providers/Qt/setup-qt.js b/share/qbs/module-providers/Qt/setup-qt.js index 4ade17627..67a4369ed 100644 --- a/share/qbs/module-providers/Qt/setup-qt.js +++ b/share/qbs/module-providers/Qt/setup-qt.js @@ -1413,10 +1413,21 @@ function replaceSpecialValues(content, module, qtProps, abi) { dict.className = toJSLiteral(module.pluginData.className); dict["extends"] = toJSLiteral(module.pluginData["extends"]); } + indent = " "; + var metaTypesFile = qtProps.libraryPath + "/metatypes/qt" + + qtProps.qtMajorVersion + module.qbsName + "_metatypes.json"; + if (File.exists(metaTypesFile)) { + if (additionalContent) + additionalContent += "\n" + indent; + additionalContent += "Group {\n"; + additionalContent += indent + indent + "files: " + JSON.stringify(metaTypesFile) + "\n" + + indent + indent + "filesAreTargets: true\n" + + indent + indent + "fileTags: [\"qt.core.metatypes\"]\n" + + indent + "}"; + } if (module.hasLibrary && !isFramework(module, qtProps)) { if (additionalContent) - additionalContent += "\n"; - indent = " "; + additionalContent += "\n" + indent; additionalContent += "Group {\n"; if (module.isPlugin) { additionalContent += indent + indent diff --git a/share/qbs/module-providers/Qt/templates/qml.qbs b/share/qbs/module-providers/Qt/templates/qml.qbs index c95c0f367..f6d3fbb1f 100644 --- a/share/qbs/module-providers/Qt/templates/qml.qbs +++ b/share/qbs/module-providers/Qt/templates/qml.qbs @@ -60,6 +60,60 @@ QtModule { fileTags: ["qt.qml.js"] } + // Type registration + property string importName + property string importVersion: product.version + readonly property stringList _importVersionParts: (importVersion || "").split(".") + property string typesFileName: { + if (product.type && product.type.contains("application")) + return "app.qmltypes"; + return "plugins.qmltypes"; + } + property string typesInstallDir + property stringList extraMetaTypesFiles + Properties { + condition: importName + Qt.core.generateMetaTypesFile: true + } + Qt.core.generateMetaTypesFile: original + Rule { + condition: importName + inputs: "qt.core.metatypes" + multiplex: true + explicitlyDependsOnFromDependencies: "qt.core.metatypes" + Artifact { + filePath: product.targetName.toLowerCase() + "_qmltyperegistrations.cpp" + fileTags: ["cpp", "unmocable"] + } + Artifact { + filePath: product.Qt.qml.typesFileName + fileTags: "qt.qml.types" + qbs.install: product.Qt.qml.typesInstallDir + qbs.installDir: product.Qt.qml.typesInstallDir + } + prepare: { + var versionParts = product.Qt.qml._importVersionParts; + var args = [ + "--generate-qmltypes=" + outputs["qt.qml.types"][0].filePath, + "--import-name=" + product.Qt.qml.importName, + "--major-version=" + versionParts[0], + "--minor-version=" + (versionParts.length > 1 ? versionParts[1] : "0") + ]; + var foreignTypes = product.Qt.qml.extraMetaTypesFiles || []; + var metaTypeArtifactsFromDeps = explicitlyDependsOn["qt.core.metatypes"] || []; + var filePathFromArtifact = function(a) { return a.filePath; }; + foreignTypes = foreignTypes.concat(metaTypeArtifactsFromDeps.map(filePathFromArtifact)); + if (foreignTypes.length > 0) + args.push("--foreign-types=" + foreignTypes.join(",")); + args.push("-o", outputs.cpp[0].filePath); + args = args.concat(inputs["qt.core.metatypes"].map(filePathFromArtifact)); + var cmd = new Command(product.Qt.core.binPath + "/qmltyperegistrar", args); + cmd.description = "running qmltyperegistrar"; + cmd.highlight = "codegen"; + return cmd; + } + } + Rule { condition: linkPlugins multiplex: true @@ -130,4 +184,20 @@ QtModule { return [cmd]; } } + + validate: { + if (importName) { + if (!importVersion) + throw "Qt.qml.importVersion must be set if Qt.qml.importName is set."; + var isInt = function(value) { + return !isNaN(value) && parseInt(Number(value)) == value + && !isNaN(parseInt(value, 10)); + } + if (!isInt(_importVersionParts[0]) + || (_importVersionParts.length > 1 && !isInt(_importVersionParts[1]))) { + throw "Qt.qml.importVersion must be of the form x.y, where x and y are integers."; + } + + } + } } |