I also prefer Jason's approach of moving just the creation of the mako Template
inside the if __main__ block, but leaving the actual string at the top level.

Alternatively we could split anv_extensions.py into two files: one that has the
constant data, and one that generates anv_extensions.c. I think either way that
would be a nice cleanup, since it would help separate concerns.

Dylan

Quoting Jason Ekstrand (2018-01-10 09:16:31)
> On Wed, Jan 10, 2018 at 4:09 AM, Andres Gomez <ago...@igalia.com> wrote:
> 
>     anv_extensions usage from anv_icd was bringing the unwanted dependency
>     of mako templates for the latter. We don't want that since it will
>     force the dependency even for distributable tarballs which was not
>     needed until now.
> 
>     Jason suggested this approach.
> 
>     Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104551
>     Fixes: 0ab04ba979b ("anv: Use python to generate ICD json files")
>     Cc: Jason Ekstrand <jason.ekstr...@intel.com>
>     Cc: Emil Velikov <emil.veli...@collabora.com>
>     Signed-off-by: Andres Gomez <ago...@igalia.com>
>     ---
>      src/intel/vulkan/anv_extensions.py | 50 +++++++++++++++++++-----------
>     --------
>      1 file changed, 25 insertions(+), 25 deletions(-)
> 
>     diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_
>     extensions.py
>     index 16e5582598e..21e28530e9a 100644
>     --- a/src/intel/vulkan/anv_extensions.py
>     +++ b/src/intel/vulkan/anv_extensions.py
>     @@ -29,8 +29,6 @@ import copy
>      import re
>      import xml.etree.cElementTree as et
> 
>     -from mako.template import Template
>     -
>      MAX_API_VERSION = '1.0.57'
> 
>      class Extension:
>     @@ -160,7 +158,31 @@ def _init_exts_from_xml(xml):
>              ext = ext_name_map[ext_name]
>              ext.type = ext_elem.attrib['type']
> 
>     -_TEMPLATE = Template(COPYRIGHT + """
> 
> 
> A simpler patch would be to simply do
> 
> _TEMPLATE = COPYRIGHT + """
> /* Stuff */
> """
> 
> And then do f.write(Template(_TEMPLATE)).render(**template_env) in the "if
> __name__ == '__main__'".  That way we don't have to move as much code around.
>  
> 
>     +if __name__ == '__main__':
>     +    parser = argparse.ArgumentParser()
>     +    parser.add_argument('--out', help='Output C file.', required=True)
>     +    parser.add_argument('--xml',
>     +                        help='Vulkan API XML file.',
>     +                        required=True,
>     +                        action='append',
>     +                        dest='xml_files')
>     +    args = parser.parse_args()
>     +
>     +    for filename in args.xml_files:
>     +        _init_exts_from_xml(filename)
>     +
>     +    for ext in EXTENSIONS:
>     +        assert ext.type == 'instance' or ext.type == 'device'
>     +
>     +    template_env = {
>     +        'MAX_API_VERSION': MAX_API_VERSION,
>     +        'instance_extensions': [e for e in EXTENSIONS if e.type ==
>     'instance'],
>     +        'device_extensions': [e for e in EXTENSIONS if e.type ==
>     'device'],
>     +    }
>     +
>     +    from mako.template import Template
>     +
>     +    _TEMPLATE = Template(COPYRIGHT + """
>      #include "anv_private.h"
> 
>      #include "vk_util.h"
>     @@ -260,27 +282,5 @@ VkResult anv_EnumerateDeviceExtensionProperties(
>      }
>      """)
> 
>     -if __name__ == '__main__':
>     -    parser = argparse.ArgumentParser()
>     -    parser.add_argument('--out', help='Output C file.', required=True)
>     -    parser.add_argument('--xml',
>     -                        help='Vulkan API XML file.',
>     -                        required=True,
>     -                        action='append',
>     -                        dest='xml_files')
>     -    args = parser.parse_args()
>     -
>     -    for filename in args.xml_files:
>     -        _init_exts_from_xml(filename)
>     -
>     -    for ext in EXTENSIONS:
>     -        assert ext.type == 'instance' or ext.type == 'device'
>     -
>     -    template_env = {
>     -        'MAX_API_VERSION': MAX_API_VERSION,
>     -        'instance_extensions': [e for e in EXTENSIONS if e.type ==
>     'instance'],
>     -        'device_extensions': [e for e in EXTENSIONS if e.type ==
>     'device'],
>     -    }
>     -
>          with open(args.out, 'w') as f:
>              f.write(_TEMPLATE.render(**template_env))
>     --
>     2.15.1
> 
>     _______________________________________________
>     mesa-dev mailing list
>     mesa-dev@lists.freedesktop.org
>     https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 
> 

Attachment: signature.asc
Description: signature

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to