From 688f65aaf86a74e6b947bebc1cb03790bbfba8fb Mon Sep 17 00:00:00 2001 From: Kevin Petit Date: Thu, 25 Nov 2021 09:54:05 +0000 Subject: [PATCH 1/2] Add a script to check for orphan definitions in the XML Signed-off-by: Kevin Petit Change-Id: I041e48869da1ffd261ff6292819ed308136a7afd --- scripts/check_orphan_definitions.py | 87 +++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 scripts/check_orphan_definitions.py diff --git a/scripts/check_orphan_definitions.py b/scripts/check_orphan_definitions.py new file mode 100755 index 00000000..30ae91a7 --- /dev/null +++ b/scripts/check_orphan_definitions.py @@ -0,0 +1,87 @@ +#!/usr/bin/python3 + +# Copyright 2019-2021 The Khronos Group Inc. +# SPDX-License-Identifier: Apache-2.0 + +import argparse +import sys +import urllib +import xml.etree.ElementTree as etree +import urllib.request + +def parse_xml(path): + file = urllib.request.urlopen(path) if path.startswith("http") else open(path, 'r') + with file: + tree = etree.parse(file) + return tree + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + + parser.add_argument('-registry', action='store', + default='cl.xml', + help='Use specified registry file instead of cl.xml') + + args = parser.parse_args() + + specpath = args.registry + #specpath = "https://raw.githubusercontent.com/KhronosGroup/OpenCL-Registry/master/xml/cl.xml" + + print('Looking for orphan definitions in ' + specpath) + + spec = parse_xml(specpath) + + REQUIRE_PREFIXES = ( + 'feature/require', + 'extensions/extension/require', + ) + + orphan_commands = 0 + orphan_enums = 0 + orphan_types = 0 + + # Check commands + used_commands = set() + for prefix in REQUIRE_PREFIXES: + for cmd in spec.findall(prefix + '/command'): + used_commands.add(cmd.get('name')) + for cmdname in spec.findall('commands/command/proto/name'): + if cmdname.text not in used_commands: + orphan_commands += 1 + print("Command '{}' is defined but not used in any core version or extension!".format(cmdname.text)) + + # Check enums + used_enums = set() + for prefix in REQUIRE_PREFIXES: + for enum in spec.findall(prefix + '/enum'): + used_enums.add(enum.get('name')) + for enum in spec.findall('enums/enum'): + if enum.get('name') not in used_enums: + orphan_enums += 1 + print("Enum '{}' is defined but not used in any core version or extension!".format(enum.get('name'))) + + # Check types + used_types = set() + for prefix in REQUIRE_PREFIXES: + for ty in spec.findall(prefix + '/type'): + used_types.add(ty.get('name')) + for ty in spec.findall('types/type'): + cat = ty.get('category') + if cat == 'define': + name = ty.findall('name')[0].text + else: + name = ty.get('name') + if name not in used_types: + orphan_types += 1 + print("Type '{}' is defined but not used in any core version or extension!".format(name)) + + print() + print("Found {} orphan commands.".format(orphan_commands)) + print("Found {} orphan enums.".format(orphan_enums)) + print("Found {} orphan types.".format(orphan_types)) + + if orphan_commands != 0 or orphan_enums != 0 or orphan_types != 0: + sys.exit(1) + else: + sys.exit(0) + From 945f5ceff28b0c518ff39a36459e3cd42edd11c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Petit?= Date: Wed, 2 Mar 2022 09:11:09 +0000 Subject: [PATCH 2/2] Update scripts/check_orphan_definitions.py Co-authored-by: Alastair Murray --- scripts/check_orphan_definitions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_orphan_definitions.py b/scripts/check_orphan_definitions.py index 30ae91a7..d46acb44 100755 --- a/scripts/check_orphan_definitions.py +++ b/scripts/check_orphan_definitions.py @@ -25,7 +25,7 @@ def parse_xml(path): args = parser.parse_args() specpath = args.registry - #specpath = "https://raw.githubusercontent.com/KhronosGroup/OpenCL-Registry/master/xml/cl.xml" + #specpath = "https://raw.githubusercontent.com/KhronosGroup/OpenCL-Registry/main/xml/cl.xml" print('Looking for orphan definitions in ' + specpath)