1#!/usr/bin/python3 2# 3# Copyright 2017-2024 The Khronos Group Inc. 4# 5# SPDX-License-Identifier: Apache-2.0 6 7# Construct an HTML fragment indexing extension appendices in vkspec.html. 8# This is run only when publishing an update spec, to update the Vulkan 9# registry. 10 11import argparse,io,os,re,string,sys,copy 12import xml.etree.ElementTree as etree 13from apiconventions import APIConventions 14 15def listExts(vendor, ext, tag): 16 prefix = ' <li> <b> ' 17 suffix = ' </b> </li>' 18 19 if vendor in tag: 20 desc = vendor + ' Extensions (' + tag[vendor] + ')' 21 else: 22 desc = vendor + ' Extensions (full vendor description unavailable)' 23 print(prefix, desc, suffix) 24 25 # (OLD) Links to the extension appendix in the single-page HTML document. 26 # This is very slow to load. 27 # fmtString = ' <li> <a href="specs/1.3-extensions/html/vkspec.html#{0}"> {0} </a> </li>' 28 29 # This links to the individual per-extension refpages, which are a 30 # slightly modified version of the extension appendices, and far faster 31 # to load. 32 if APIConventions().xml_api_name == 'vulkansc': 33 fmtString = ' <li> <a href="specs/1.0-extensions/man/html/{0}.html"> {0} </a> </li>' 34 else: 35 fmtString = ' <li> <a href="specs/1.3-extensions/man/html/{0}.html"> {0} </a> </li>' 36 37 for name in sorted(ext[vendor]): 38 print(fmtString.format(name)) 39 40# -extension name - may be a single extension name, a a space-separated list 41# of names, or a regular expression. 42if __name__ == '__main__': 43 parser = argparse.ArgumentParser() 44 45 parser.add_argument('-registry', action='store', 46 default='vk.xml', 47 help='Use specified registry file instead of vk.xml') 48 parser.add_argument('-quiet', action='store_true', default=False, 49 help='Suppress script output during normal execution.') 50 51 args = parser.parse_args() 52 53 tree = etree.parse(args.registry) 54 55 # Dictionary of vendor tags -> author name mappings 56 tag = {} 57 58 # Loop over all vendor tags, tracking the full corresponding author name 59 for elem in tree.findall('tags/tag'): 60 vendor = elem.get('name') 61 author = elem.get('author') 62 63 tag[vendor] = author 64 65 # Dictionary of supported extensions, indexed by vendor prefix 66 ext = {} 67 68 # Loop over all extensions, add supported names to the dictionary 69 for elem in tree.findall('extensions/extension'): 70 name = elem.get('name') 71 supported = elem.get('supported') 72 73 if APIConventions().xml_api_name in supported.split(','): 74 # Relies on name being in the form VK_<vendor>_stuff 75 (vk, vendor) = name.split('_')[0:2] 76 77 if not vendor in ext: 78 ext[vendor] = [] 79 ext[vendor].append(name) 80 81 # Emit HTML fragment indexing the extensions 82 83 print('<ul>') 84 85 for vendor in ['KHR', 'EXT']: 86 if vendor in ext: 87 listExts(vendor, ext, tag) 88 del ext[vendor] 89 90 for vendor in sorted(ext.keys()): 91 listExts(vendor, ext, tag) 92 del ext[vendor] 93 94 print('</ul>') 95