[Mesa-dev] [PATCH 18/18] mapi: remove machinery handling CSV files

Erik Faye-Lund erik.faye-lund at collabora.com
Thu Dec 6 17:10:13 UTC 2018


On Wed, 2018-11-21 at 12:04 +0000, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
> 
> We haven't have one in years, so just drop the code.
> 
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
>  src/mapi/mapi_abi.py | 80 ++++------------------------------------
> ----
>  1 file changed, 6 insertions(+), 74 deletions(-)
> 
> diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py
> index 3cfede56880..846c69c8b70 100644
> --- a/src/mapi/mapi_abi.py
> +++ b/src/mapi/mapi_abi.py
> @@ -184,75 +184,6 @@ def abi_parse_xml(xml):
>  
>      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
> @@ -714,7 +645,7 @@ typedef int GLclampx;
>  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)))
>  
> @@ -723,6 +654,10 @@ def parse_args():
>          parser.print_help()
>          sys.exit(1)
>  
> +    if not args[0].endswith('.xml'):
> +        parser.print_help()
> +        sys.exit(1)
> +

These two last hunks feels a bit silly on their own, but I suppose the
point is to catch any potential left-over cases of csv-files here
early... So, yeah:

Reviewed-by: Erik Faye-Lun <erik.faye-lund at collabora.com>

>      return (args[0], options)
>  
>  def main():
> @@ -733,10 +668,7 @@ def main():
>  
>      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)



More information about the mesa-dev mailing list