1#!/usr/bin/python3 2# 3# Copyright 2017-2023 The Khronos Group Inc. 4# 5# SPDX-License-Identifier: Apache-2.0 6 7# testSpecVersion - check if SPEC_VERSION values for an unpublished 8# extension branch meet the requirement of being 1. 9# 10# Usage: textSpecVersion.py [-branch branchname] [-registry file] 11# 12# Checks for an XML <extension> matching the branch name specified 13# on the command line, or the current branch if not specified. 14# 15# If not found, the branch is not an extension staging branch; succeed. 16# If found, but extension is disabled, do not run the test; succeed. 17# If found, and extension SPEC_VERSION has a value of '1', succeed. 18# Otherwise, fail. 19 20import argparse 21import sys 22import xml.etree.ElementTree as etree 23from reflib import getBranch 24 25if __name__ == '__main__': 26 parser = argparse.ArgumentParser() 27 28 parser.add_argument('-branch', action='store', 29 default=None, 30 help='Specify branch to check against') 31 parser.add_argument('-registry', action='store', 32 default='xml/vk.xml', 33 help='Use specified registry file instead of vk.xml') 34 args = parser.parse_args() 35 36 try: 37 tree = etree.parse(args.registry) 38 except: 39 print('ERROR - cannot open registry XML file', args.registry) 40 sys.exit(1) 41 42 errors = '' 43 if args.branch is None: 44 (args.branch, errors) = getBranch() 45 if args.branch is None: 46 print('ERROR - Cannot determine current git branch:', errors) 47 sys.exit(1) 48 49 elem = tree.find('extensions/extension[@name="' + args.branch + '"]') 50 51 if elem == None: 52 print('Success - assuming', args.branch, 'is not an extension branch') 53 sys.exit(0) 54 55 supported = elem.get('supported') 56 if supported == 'disabled': 57 print('Success - branch name', args.branch, 'matches, but extension is disabled') 58 sys.exit(0) 59 60 for enum in elem.findall('require/enum'): 61 name = enum.get('name') 62 63 if name is not None and name[-13:] == '_SPEC_VERSION': 64 value = enum.get('value') 65 if value >= '1': 66 print('Success - {} = {} for branch {}'.format( 67 name, value, args.branch)) 68 sys.exit(0) 69 else: 70 print('ERROR - {} = {} for branch {}, but must be >= 1'.format( 71 name, value, args.branch)) 72 sys.exit(1) 73 74 print('ERROR - no SPEC_VERSION token found for branch', args.branch) 75 sys.exit(1) 76