def main(header_output_path, source_output_path): xml = registry_xml.RegistryXML('gl.xml', 'gl_angle_ext.xml') # build a map from GLenum name to its value all_gl_enums = dict() for enums_node in xml.root.findall('enums'): for enum in enums_node.findall('enum'): name = enum.attrib['name'] value = int(enum.attrib['value'], base=16) all_gl_enums[name] = value # Parse groups of GLenums to build a {group, name} -> value mapping. gl_enum_in_groups = dict() enums_has_group = set() for enums_group_node in xml.root.findall('groups/group'): group_name = enums_group_node.attrib['name'] if group_name in exclude_gl_enum_groups: continue if group_name not in gl_enum_in_groups: gl_enum_in_groups[group_name] = dict() for enum_node in enums_group_node.findall('enum'): enum_name = enum_node.attrib['name'] enums_has_group.add(enum_name) gl_enum_in_groups[group_name][enum_name] = all_gl_enums[enum_name] # Find relevant GLenums according to enabled APIs and extensions. exporting_enums = set() # export all the apis xpath = "./feature/require/enum" for enum_tag in xml.root.findall(xpath): enum_name = enum_tag.attrib['name'] if enum_name not in exclude_gl_enums: exporting_enums.add(enum_name) for extension in registry_xml.supported_extensions: xpath = "./extensions/extension[@name='%s']/require/enum" % extension for enum_tag in xml.root.findall(xpath): enum_name = enum_tag.attrib['name'] if enum_name not in exclude_gl_enums: exporting_enums.add(enum_name) # For enums that do not have a group, add them to a default group default_group_name = registry_xml.default_enum_group_name gl_enum_in_groups[default_group_name] = dict() default_group = gl_enum_in_groups[default_group_name] for enum_name in exporting_enums: if enum_name not in enums_has_group: default_group[enum_name] = all_gl_enums[enum_name] # Write GLenum groups into the header file. header_content = template_gl_enums_header.format( script_name=os.path.basename(sys.argv[0]), data_source_name="gl.xml and gl_angle_ext.xml", year=date.today().year, gl_enum_groups=',\n'.join(sorted(gl_enum_in_groups.iterkeys()))) header_output_path = registry_xml.script_relative(header_output_path) with open(header_output_path, 'w') as f: f.write(header_content) # Write mapping to source file gl_enums_value_to_string_table = dump_value_to_string_mapping(gl_enum_in_groups, exporting_enums) source_content = template_gl_enums_source.format( script_name=os.path.basename(sys.argv[0]), data_source_name="gl.xml and gl_angle_ext.xml", year=date.today().year, gl_enums_value_to_string_table=gl_enums_value_to_string_table, ) source_output_path = registry_xml.script_relative(source_output_path) with open(source_output_path, 'w') as f: f.write(source_content) return 0
source_output_path = registry_xml.script_relative(source_output_path) with open(source_output_path, 'w') as f: f.write(source_content) return 0 if __name__ == '__main__': inputs = [ 'gl.xml', 'gl_angle_ext.xml', 'registry_xml.py', ] gl_enum_utils_autogen_base_path = '../src/libANGLE/gl_enum_utils_autogen' outputs = [ gl_enum_utils_autogen_base_path + '.h', gl_enum_utils_autogen_base_path + '.cpp', ] if len(sys.argv) > 1: if sys.argv[1] == 'inputs': print ','.join(inputs) elif sys.argv[1] == 'outputs': print ','.join(outputs) else: sys.exit( main( registry_xml.script_relative(outputs[0]), registry_xml.script_relative(outputs[1])))