indexExt.py
1 #!/usr/bin/python3 2 # 3 # Copyright (c) 2017-2019 The Khronos Group Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Construct an HTML fragment indexing extension appendices in vkspec.html. 18 # This is run only when publishing an update spec, to update the Vulkan 19 # registry. 20 21 import argparse,io,os,re,string,sys,copy 22 import xml.etree.ElementTree as etree 23 24 def listExts(vendor, ext, tag): 25 prefix = ' <li> <b> ' 26 suffix = ' </b> </li>' 27 28 if vendor in tag: 29 desc = vendor + ' Extensions (' + tag[vendor] + ')' 30 else: 31 desc = vendor + ' Extensions (full vendor description unavailable)' 32 print(prefix, desc, suffix) 33 34 fmtString = ' <li> <a href="specs/1.1-extensions/html/vkspec.html#{0}"> {0} </a> </li>' 35 36 for name in sorted(ext[vendor]): 37 print(fmtString.format(name)) 38 39 # -extension name - may be a single extension name, a a space-separated list 40 # of names, or a regular expression. 41 if __name__ == '__main__': 42 parser = argparse.ArgumentParser() 43 44 parser.add_argument('-registry', action='store', 45 default='vk.xml', 46 help='Use specified registry file instead of vk.xml') 47 parser.add_argument('-quiet', action='store_true', default=False, 48 help='Suppress script output during normal execution.') 49 50 args = parser.parse_args() 51 52 tree = etree.parse(args.registry) 53 54 # Dictionary of vendor tags -> author name mappings 55 tag = {} 56 57 # Loop over all vendor tags, tracking the full corresponding author name 58 for elem in tree.findall('tags/tag'): 59 vendor = elem.get('name') 60 author = elem.get('author') 61 62 tag[vendor] = author 63 64 # Dictionary of supported extensions, indexed by vendor prefix 65 ext = {} 66 67 # Loop over all extensions, add supported names to the dictionary 68 for elem in tree.findall('extensions/extension'): 69 name = elem.get('name') 70 supported = elem.get('supported') 71 72 if supported == 'vulkan': 73 # Relies on name being in the form VK_<vendor>_stuff 74 (vk, vendor) = name.split('_')[0:2] 75 76 if not vendor in ext: 77 ext[vendor] = [] 78 ext[vendor].append(name) 79 80 # Emit HTML fragment indexing the extensions 81 82 print('<ul>') 83 84 for vendor in ['KHR', 'EXT']: 85 if vendor in ext: 86 listExts(vendor, ext, tag) 87 del ext[vendor] 88 89 for vendor in sorted(ext.keys()): 90 listExts(vendor, ext, tag) 91 del ext[vendor] 92 93 print('</ul>')