diff options
author | Cristian Le <[email protected]> | 2025-04-08 13:24:26 +0200 |
---|---|---|
committer | Cristian Le <[email protected]> | 2025-06-26 17:32:00 +0200 |
commit | fa3d468b0e4a16ee6bc11214a1817e22bb457997 (patch) | |
tree | b8869502754f1ba1a0cd55132b99730085de2ecc | |
parent | df1126dd0dfbfd067e1fdac975413a692bfc9d80 (diff) |
Add the Json schema for the modules.json
Change-Id: Id2c821a9e0abd067a8eb66348baff0f2f657bd75
Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r-- | cmake/QtBaseGlobalTargets.cmake | 5 | ||||
-rw-r--r-- | cmake/QtModuleHelpers.cmake | 1 | ||||
-rwxr-xr-x | util/json_schema/check_qt_module_json_schemas.py | 51 | ||||
-rw-r--r-- | util/json_schema/modules.json | 251 |
4 files changed, 306 insertions, 2 deletions
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index e11e04f2901..afee7b94c5d 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -454,3 +454,8 @@ if(QT_INSTALL_CI_FILES) qt_copy_or_install(PROGRAMS "util/json_schema/check_qt_module_json_schemas.py" DESTINATION "${__qt_libexec_install_dir}") endif() + +# Install json schemas for the users as well +qt_copy_or_install(FILES + "util/json_schema/modules.json" + DESTINATION "${INSTALL_QT_SHAREDIR}/json_schema/") diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index b354b10cc1d..d9f377a2baa 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -1433,6 +1433,7 @@ function(qt_internal_list_to_json_array out_var list_var) endfunction() # Generate a module description file based on the template in ModuleDescription.json.in +# Keep this in sync with `utils/json_schema/modules.json` function(qt_describe_module target) set(path_suffix "${INSTALL_DESCRIPTIONSDIR}") qt_path_join(build_dir ${QT_BUILD_DIR} ${path_suffix}) diff --git a/util/json_schema/check_qt_module_json_schemas.py b/util/json_schema/check_qt_module_json_schemas.py index 5d01e3d56ce..ba30c61285d 100755 --- a/util/json_schema/check_qt_module_json_schemas.py +++ b/util/json_schema/check_qt_module_json_schemas.py @@ -11,8 +11,13 @@ from __future__ import annotations from pathlib import Path import click +from check_jsonschema import main as check_jsonschema_main +SCHEMA_FILES = [ + "modules.json", +] + @click.command( context_settings=dict( ignore_unknown_options=True, @@ -30,18 +35,60 @@ import click metavar="PATH", help="Path to the Qt install prefix.", ) +# TODO: Use qtpaths to extract these paths instead + "--qt-sharedir", + default="share/qt6", + metavar="PATH", + help="The equivalent INSTALL_QT_SHAREDIR that was used.", +) + "--descriptionsdir", + default="modules", + metavar="PATH", + help="The equivalent INSTALL_DESCRIPTIONSDIR that was used.", +) @click.argument( "check_jsonschema_args", nargs=-1, type=click.UNPROCESSED, ) -def run(install_prefix: Path, check_jsonschema_args: list[str]): +def run( + install_prefix: Path, + check_jsonschema_args: list[str], + qt_sharedir: str, + descriptionsdir: str, +): """ Validate the module json files after installation. Unknown options are passed directly to check-jsonschema. """ - # TODO: Do the actual validation + + # Get the appropriate directory containing the schemas (order is important) + # If we run the script directly from source, we take the schemas available next to the script + # to simplify editing the schemas, otherwise we use the installed schema files + for schemas_dir in [ + Path(__file__).parent, + install_prefix / f"{qt_sharedir}/json_schema", + ]: + # check that all expected schema files are present + if all((schemas_dir/file).exists() for file in SCHEMA_FILES): + break + else: + click.secho("Error: missing schema files", fg="red") + raise SystemExit(1) + + module_files = [str(file) for file in (install_prefix / descriptionsdir).glob("*.json")] + click.echo("Checking modules") + check_jsonschema_main( + [ + "--schemafile", + str(schemas_dir / "modules.json"), + *check_jsonschema_args, + *module_files, + ], + ) if __name__ == "__main__": diff --git a/util/json_schema/modules.json b/util/json_schema/modules.json new file mode 100644 index 00000000000..3226924d3d4 --- /dev/null +++ b/util/json_schema/modules.json @@ -0,0 +1,251 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Qt modules", + "description": "Schema for the modules/*.json files", + "$comment": "Implemented in qt_describe_module() function from QtModuleHelpers.cmake", + "type": "object", + "oneOf": [ + { + "$ref": "#/$defs/modules_v2" + }, + { + "$ref": "#/$defs/modules_v3" + } + ], + "$defs": { + "modules_base": { + "$comment": "Common schema fields for all modules versions", + "allOf": [ + { + "type": "object", + "properties": { + "name": { + "description": "Name of the Qt module", + "type": "string" + }, + "version": { + "description": "Qt project version that built the module", + "type": "string" + }, + "repository": { + "description": "Qt repository where the module is defined in", + "type": "string" + } + }, + "required": [ + "name", + "version", + "repository" + ] + }, + { + "$ref": "#/$defs/extra_module_information" + } + ] + }, + "modules_v2": { + "$comment": "Introduced in https://codereview.qt-project.org/c/qt/qtbase/+/602617", + "allOf": [ + { + "$ref": "#/$defs/modules_base" + }, + { + "type": "object", + "properties": { + "schema_version": { + "const": 2 + }, + "platforms": { + "description": "", + "type": "array", + "items": { + "$ref": "#/$defs/platform_v2" + } + } + }, + "required": [ + "schema_version", + "platforms" + ] + } + ], + "unevaluatedProperties": false + }, + "modules_v3": { + "$comment": "Introduced in https://codereview.qt-project.org/c/qt/qtbase/+/654550", + "allOf": [ + { + "$ref": "#/$defs/modules_base" + }, + { + "type": "object", + "properties": { + "schema_version": { + "const": 3 + }, + "platforms": { + "description": "", + "type": "array", + "items": { + "$ref": "#/$defs/platform_v3" + } + } + }, + "required": [ + "schema_version", + "platforms" + ] + } + ], + "unevaluatedProperties": false + }, + "platform_base": { + "description": "", + "type": "object", + "properties": { + "name": { + "description": "", + "type": "string" + }, + "variant": { + "description": "", + "type": "string" + }, + "compiler_id": { + "description": "", + "type": "string" + }, + "compiler_version": { + "description": "", + "type": "string" + }, + "targets": { + "description": "", + "type": "array", + "items": { + "$ref": "#/$defs/platform_target" + } + } + }, + "required": [ + "name", + "compiler_id", + "compiler_version", + "targets" + ] + }, + "platform_v2": { + "allOf": [ + { + "$ref": "#/$defs/platform_base" + }, + { + "type": "object", + "properties": { + "version": { + "description": "The CMAKE_SYSTEM_VERSION of the builder if available", + "type": "string" + } + } + } + ], + "unevaluatedProperties": false + }, + "platform_v3": { + "allOf": [ + { + "$ref": "#/$defs/platform_base" + }, + { + "type": "object", + "properties": { + "version": { + "description": "The CMAKE_SYSTEM_VERSION. Maybe null if it cannot be shared, see: https://codereview.qt-project.org/c/qt/qtbase/+/654550", + "type": [ + "string", + "null" + ] + } + }, + "required": [ + "version" + ] + } + ], + "unevaluatedProperties": false + }, + "platform_target": { + "description": "", + "type": "object", + "properties": { + "architecture": { + "description": "", + "type": "string" + }, + "abi": { + "description": "", + "type": "string" + }, + "static": { + "description": "", + "type": "boolean" + }, + "api_version": { + "description": "", + "type": "string" + }, + "ndk_version": { + "description": "", + "type": "string" + } + }, + "required": [ + "architecture", + "abi" + ], + "additionalProperties": false + }, + "extra_module_information": { + "$comment": "Constructed from extra_module_information in QtModuleHelpers.cmake", + "type": "object", + "properties": { + "plugin_types": { + "description": "", + "type": "array", + "items": { + "type": "string" + } + }, + "internal": { + "description": "", + "type": "boolean" + }, + "bundle_type": { + "description": "", + "type": "string" + }, + "namespace": { + "description": "", + "type": "string" + }, + "qpa": { + "description": "", + "type": "object", + "properties": { + "platforms": { + "description": "", + "type": "array", + "items": { + "type": "string" + } + }, + "default_platform": { + "description": "", + "type": "string" + } + } + } + } + } + } +} |