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