import sys
# make it possible to import glapi
import os
-GLAPI = os.path.join(".", os.path.dirname(sys.argv[0]), "glapi/gen")
-sys.path.append(GLAPI)
+GLAPI = os.path.join(".", os.path.dirname(__file__), "glapi", "gen")
+sys.path.insert(0, GLAPI)
+from operator import attrgetter
import re
from optparse import OptionParser
import gl_XML
def __str__(self):
return self.c_prototype()
- def __cmp__(self, other):
+ def __lt__(self, other):
# compare slot, alias, and then name
- res = cmp(self.slot, other.slot)
- if not res:
+ if self.slot == other.slot:
if not self.alias:
- res = -1
+ return True
elif not other.alias:
- res = 1
+ return False
- if not res:
- res = cmp(self.name, other.name)
+ return self.name < other.name
+
+ return self.slot < other.slot
- return res
def abi_parse_xml(xml):
"""Parse a GLAPI XML file for ABI entries."""
return entries
-def abi_parse_line(line):
- cols = [col.strip() for col in line.split(',')]
-
- attrs = {
- 'slot': -1,
- 'hidden': False,
- 'alias': None,
- 'handcode': None,
- }
-
- # extract attributes from the first column
- vals = cols[0].split(':')
- while len(vals) > 1:
- val = vals.pop(0)
- if val.startswith('slot='):
- attrs['slot'] = int(val[5:])
- elif val == 'hidden':
- attrs['hidden'] = True
- elif val.startswith('alias='):
- attrs['alias'] = val[6:]
- elif val.startswith('handcode='):
- attrs['handcode'] = val[9:]
- elif not val:
- pass
- else:
- raise Exception('unknown attribute %s' % val)
- cols[0] = vals[0]
-
- return (attrs, cols)
-
-def abi_parse(filename):
- """Parse a CSV file for ABI entries."""
- fp = open(filename) if filename != '-' else sys.stdin
- lines = [line.strip() for line in fp.readlines()
- if not line.startswith('#') and line.strip()]
-
- entry_dict = {}
- next_slot = 0
- for line in lines:
- attrs, cols = abi_parse_line(line)
-
- # post-process attributes
- if attrs['alias']:
- try:
- alias = entry_dict[attrs['alias']]
- except KeyError:
- raise Exception('failed to alias %s' % attrs['alias'])
- if alias.alias:
- raise Exception('recursive alias %s' % ent.name)
- slot = alias.slot
- attrs['alias'] = alias
- else:
- slot = next_slot
- next_slot += 1
-
- if attrs['slot'] < 0:
- attrs['slot'] = slot
- elif attrs['slot'] != slot:
- raise Exception('invalid slot in %s' % (line))
-
- ent = ABIEntry(cols, attrs)
- if ent.name in entry_dict:
- raise Exception('%s is duplicated' % (ent.name))
- entry_dict[ent.name] = ent
-
- entries = sorted(entry_dict.values())
-
- return entries
-
def abi_sanity_check(entries):
if not entries:
return
self.entries = entries
# sort entries by their names
- self.entries_sorted_by_names = self.entries[:]
- self.entries_sorted_by_names.sort(lambda x, y: cmp(x.name, y.name))
+ self.entries_sorted_by_names = sorted(self.entries, key=attrgetter('name'))
self.indent = ' ' * 3
self.noop_warn = 'noop_warn'
if not self.need_entry_point(ent):
continue
export = self.api_call if not ent.hidden else ''
- decls.append(self._c_decl(ent, prefix, True, export) + ';')
+ if not ent.hidden or not self.lib_need_non_hidden_entries:
+ decls.append(self._c_decl(ent, prefix, True, export) + ';')
return "\n".join(decls)
def c_stub_string_pool(self):
"""Return the string pool for use by stubs."""
# sort entries by their names
- sorted_entries = self.entries[:]
- sorted_entries.sort(lambda x, y: cmp(x.name, y.name))
+ sorted_entries = sorted(self.entries, key=attrgetter('name'))
pool = []
offsets = {}
#define GLAPI_PREFIX_STR(func) "gl"#func
#endif /* USE_MGL_NAMESPACE */
-typedef int GLclampx;
-#endif /* _GLAPI_TMP_H_ */"""
-
- return header
-
-class ES1APIPrinter(GLAPIPrinter):
- """OpenGL ES 1.x API Printer"""
-
- def __init__(self, entries):
- super(ES1APIPrinter, self).__init__(entries)
- self.prefix_lib = 'gl'
- self.prefix_warn = 'gl'
-
- def _override_for_api(self, ent):
- if ent.xml_data is None:
- raise Exception('ES2 API printer requires XML input')
- ent.hidden = (ent.name not in \
- ent.xml_data.entry_points_for_api_version('es1')) \
- or ent.hidden
- ent.handcode = False
-
- def _get_c_header(self):
- header = """#ifndef _GLAPI_TMP_H_
-#define _GLAPI_TMP_H_
-typedef int GLclampx;
-#endif /* _GLAPI_TMP_H_ */"""
-
- return header
-
-class ES2APIPrinter(GLAPIPrinter):
- """OpenGL ES 2.x API Printer"""
-
- def __init__(self, entries):
- super(ES2APIPrinter, self).__init__(entries)
- self.prefix_lib = 'gl'
- self.prefix_warn = 'gl'
-
- def _override_for_api(self, ent):
- if ent.xml_data is None:
- raise Exception('ES2 API printer requires XML input')
- ent.hidden = (ent.name not in \
- ent.xml_data.entry_points_for_api_version('es2')) \
- or ent.hidden
-
- # This is hella ugly. The same-named function in desktop OpenGL is
- # hidden, but it needs to be exposed by libGLESv2 for OpenGL ES 3.0.
- # There's no way to express in the XML that a function should be be
- # hidden in one API but exposed in another.
- if ent.name == 'GetInternalformativ':
- ent.hidden = False
-
- ent.handcode = False
-
- def _get_c_header(self):
- header = """#ifndef _GLAPI_TMP_H_
-#define _GLAPI_TMP_H_
typedef int GLclampx;
#endif /* _GLAPI_TMP_H_ */"""
def parse_args():
printers = ['glapi', 'es1api', 'es2api', 'shared-glapi']
- parser = OptionParser(usage='usage: %prog [options] <filename>')
+ parser = OptionParser(usage='usage: %prog [options] <xml_file>')
parser.add_option('-p', '--printer', dest='printer',
help='printer to use: %s' % (", ".join(printers)))
parser.print_help()
sys.exit(1)
+ if not args[0].endswith('.xml'):
+ parser.print_help()
+ sys.exit(1)
+
return (args[0], options)
def main():
printers = {
'glapi': GLAPIPrinter,
- 'es1api': ES1APIPrinter,
- 'es2api': ES2APIPrinter,
'shared-glapi': SharedGLAPIPrinter,
}
filename, options = parse_args()
- if filename.endswith('.xml'):
- entries = abi_parse_xml(filename)
- else:
- entries = abi_parse(filename)
+ entries = abi_parse_xml(filename)
abi_sanity_check(entries)
printer = printers[options.printer](entries)