-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathcheck_orphan_definitions.py
More file actions
executable file
·87 lines (70 loc) · 2.68 KB
/
check_orphan_definitions.py
File metadata and controls
executable file
·87 lines (70 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/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)