From 383032c70068938575f609fef0d442ba3e4d7c68 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 17 Feb 2017 16:59:42 -0800 Subject: [PATCH] anv: anv_entrypoints_gen.py: directly write files instead of piping MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This changes the output to be written as a file rather than being piped. This had one critical advantage, it encapsulates the encoding. This prevents bugs where a symbol (generally unicode like © [copyright]) is printed and the system being built on doesn't have a unicode locale. v2: - Update Android.mk v3: - Don't generate both files at once - Fix Android.mk - drop --outdir, since the filename is passed in as an argument Signed-off-by: Dylan Baker --- src/intel/Android.vulkan.mk | 5 +++-- src/intel/Makefile.vulkan.am | 4 ++-- src/intel/vulkan/anv_entrypoints_gen.py | 31 +++++++++++++++++-------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/intel/Android.vulkan.mk b/src/intel/Android.vulkan.mk index 0b6462e..bcf1455 100644 --- a/src/intel/Android.vulkan.mk +++ b/src/intel/Android.vulkan.mk @@ -59,7 +59,8 @@ $(intermediates)/vulkan/dummy.c: $(hide) touch $@ $(intermediates)/vulkan/anv_entrypoints.h: - $(VK_ENTRYPOINTS_SCRIPT) header --xml $(MESA_TOP)/src/vulkan/registry/vk.xml > $@ + $(VK_ENTRYPOINTS_SCRIPT) header $@ --xml $(MESA_TOP)/src/vulkan/registry/vk.xml + LOCAL_EXPORT_C_INCLUDE_DIRS := \ $(intermediates) @@ -179,7 +180,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \ LOCAL_GENERATED_SOURCES += $(intermediates)/vulkan/anv_entrypoints.c $(intermediates)/vulkan/anv_entrypoints.c: - $(VK_ENTRYPOINTS_SCRIPT) code --xml $(MESA_TOP)/src/vulkan/registry/vk.xml > $@ + $(VK_ENTRYPOINTS_SCRIPT) code $@ --xml $(MESA_TOP)/src/vulkan/registry/vk.xml LOCAL_SHARED_LIBRARIES := libdrm_intel diff --git a/src/intel/Makefile.vulkan.am b/src/intel/Makefile.vulkan.am index bf6b25b..9696286 100644 --- a/src/intel/Makefile.vulkan.am +++ b/src/intel/Makefile.vulkan.am @@ -25,10 +25,10 @@ vulkan_api_xml = $(top_srcdir)/src/vulkan/registry/vk.xml vulkan/anv_entrypoints.h : vulkan/anv_entrypoints_gen.py $(vulkan_api_xml) - $(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_entrypoints_gen.py header --xml $(vulkan_api_xml) > $@ + $(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_entrypoints_gen.py header $@ --xml $(vulkan_api_xml) vulkan/anv_entrypoints.c : vulkan/anv_entrypoints_gen.py $(vulkan_api_xml) - $(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_entrypoints_gen.py code --xml $(vulkan_api_xml) > $@ + $(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_entrypoints_gen.py code $@ --xml $(vulkan_api_xml) BUILT_SOURCES += $(VULKAN_GENERATED_FILES) CLEANFILES += \ diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py index bf6b209..47dc44b 100644 --- a/src/intel/vulkan/anv_entrypoints_gen.py +++ b/src/intel/vulkan/anv_entrypoints_gen.py @@ -86,7 +86,7 @@ TEMPLATE_H = Template(textwrap.dedent("""\ #endif // ${guard} % endif % endfor - """)) + """), output_encoding='utf-8') TEMPLATE_C = Template(textwrap.dedent(u"""\ /* @@ -340,22 +340,23 @@ def gen_code(entrypoints): collisions[level] += 1 mapping[h & HASH_MASK] = num - print TEMPLATE_C.render(entrypoints=entrypoints, - offsets=offsets, - collisions=collisions, - mapping=mapping, - hash_mask=HASH_MASK, - prime_step=PRIME_STEP, - prime_factor=PRIME_FACTOR, - none=NONE, - hash_size=HASH_SIZE, - filename=os.path.basename(__file__)) + return TEMPLATE_C.render(entrypoints=entrypoints, + offsets=offsets, + collisions=collisions, + mapping=mapping, + hash_mask=HASH_MASK, + prime_step=PRIME_STEP, + prime_factor=PRIME_FACTOR, + none=NONE, + hash_size=HASH_SIZE, + filename=os.path.basename(__file__)) def main(): parser = argparse.ArgumentParser() parser.add_argument('target', choices=['header', 'code'], help='Which file to generate.') + parser.add_argument('file', help='Where to write the file.') parser.add_argument('--xml', help='Vulkan API XML file.') args = parser.parse_args() @@ -375,10 +376,12 @@ def main(): # For outputting entrypoints.h we generate a anv_EntryPoint() prototype # per entry point. if args.target == 'header': - print TEMPLATE_H.render(entrypoints=entrypoints, - filename=os.path.basename(__file__)) + with open(args.file, 'wb') as f: + f.write(TEMPLATE_H.render(entrypoints=entrypoints, + filename=os.path.basename(__file__))) else: - gen_code(entrypoints) + with open(args.file, 'wb') as f: + f.write(gen_code(entrypoints)) if __name__ == '__main__': -- 2.7.4