[Mesa-dev] [PATCH v3 09/15] anv: anv_entrypoints_gen.py: directly write files instead of piping
Dylan Baker
dylan at pnwbakers.com
Fri Feb 24 18:21:37 UTC 2017
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 <dylanx.c.baker at intel.com>
---
src/intel/vulkan/Android.mk | 5 ++--
src/intel/vulkan/Makefile.am | 10 ++++----
src/intel/vulkan/anv_entrypoints_gen.py | 31 ++++++++++++++------------
3 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/intel/vulkan/Android.mk b/src/intel/vulkan/Android.mk
index 9dabf1c..13b4846 100644
--- a/src/intel/vulkan/Android.mk
+++ b/src/intel/vulkan/Android.mk
@@ -61,7 +61,8 @@ $(intermediates)/dummy.c:
$(hide) touch $@
$(intermediates)/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)
@@ -177,7 +178,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libmesa_anv_entrypoints libmesa_genxml
LOCAL_GENERATED_SOURCES += $(intermediates)/anv_entrypoints.c
$(intermediates)/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/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am
index 565559c..f3ae4a0 100644
--- a/src/intel/vulkan/Makefile.am
+++ b/src/intel/vulkan/Makefile.am
@@ -145,11 +145,13 @@ libvulkan_intel_la_SOURCES = $(VULKAN_GEM_FILES)
vulkan_api_xml = $(top_srcdir)/src/vulkan/registry/vk.xml
-anv_entrypoints.h : anv_entrypoints_gen.py $(vulkan_api_xml)
- $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py header --xml $(vulkan_api_xml) > $@
+anv_entrypoints.h: anv_entrypoints_gen.py $(vulkan_api_xml)
+ $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py \
+ --xml $(vulkan_api_xml) header $@
-anv_entrypoints.c : anv_entrypoints_gen.py $(vulkan_api_xml)
- $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py code --xml $(vulkan_api_xml) > $@
+anv_entrypoints.c: anv_entrypoints_gen.py $(vulkan_api_xml)
+ $(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py \
+ --xml $(vulkan_api_xml) code $@
BUILT_SOURCES = $(VULKAN_GENERATED_FILES)
CLEANFILES = $(BUILT_SOURCES) dev_icd.json intel_icd. at host_cpu@.json
diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index e4bf002..156a14f 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -84,7 +84,7 @@ TEMPLATE_H = Template(textwrap.dedent("""\
#endif // ${guard}
% endif
% endfor
- """))
+ """), output_encoding='utf-8')
TEMPLATE_C = Template(textwrap.dedent(u"""\
/*
@@ -338,22 +338,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()
@@ -373,10 +374,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__':
--
git-series 0.9.1
More information about the mesa-dev
mailing list