mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-30 15:31:34 +00:00
777435c470
When we reconfigure, `configure_file()` is called again, and `*.gresource.xml` files are regenerated, which causes many (all?) binaries to be relinked. Now we only write those out if the contents actually changed (or if the output didn't already exist). This is exactly what Meson already does with `configure_file()` when `command:` is not used. While we're at it, also do the same for `gen-c-array.py` and `gentypefuncs.py` for completeness. Now even if the input to those changes, re-building of those custom targets may not result in relinking if the outputted C files have the same contents.
68 lines
1.5 KiB
Python
68 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Generate gsk.resources.xml
|
|
#
|
|
# Usage: gen-gsk-gresources-xml OUTPUT-FILE [INPUT-FILE1] [INPUT-FILE2] ...
|
|
|
|
import os, sys
|
|
import filecmp
|
|
|
|
def replace_if_changed(new, old):
|
|
'''
|
|
Compare contents and only replace if changed to avoid triggering a rebuild.
|
|
'''
|
|
try:
|
|
changed = not filecmp.cmp(new, old, shallow=False)
|
|
except FileNotFoundError:
|
|
changed = True
|
|
if changed:
|
|
os.replace(new, old)
|
|
else:
|
|
os.remove(new)
|
|
|
|
source_shaders = []
|
|
vulkan_compiled_shaders = []
|
|
vulkan_shaders = []
|
|
|
|
for f in sys.argv[2:]:
|
|
if f.endswith('.glsl'):
|
|
source_shaders.append(f)
|
|
elif f.endswith('.spv'):
|
|
vulkan_compiled_shaders.append(f)
|
|
elif f.endswith('.frag') or f.endswith('.vert'):
|
|
vulkan_shaders.append(f)
|
|
else:
|
|
sys.exit(-1) # FIXME: error message
|
|
|
|
xml = '''<?xml version='1.0' encoding='UTF-8'?>
|
|
<gresources>
|
|
<gresource prefix='/org/gtk/libgsk'>
|
|
|
|
'''
|
|
|
|
for f in source_shaders:
|
|
xml += ' <file alias=\'glsl/{0}\'>resources/glsl/{0}</file>\n'.format(os.path.basename(f))
|
|
|
|
xml += '\n'
|
|
|
|
for f in vulkan_compiled_shaders:
|
|
xml += ' <file alias=\'vulkan/{0}\'>resources/vulkan/{0}</file>\n'.format(os.path.basename(f))
|
|
|
|
xml += '\n'
|
|
|
|
for f in vulkan_shaders:
|
|
xml += ' <file alias=\'vulkan/{0}\'>resources/vulkan/{0}</file>\n'.format(os.path.basename(f))
|
|
|
|
xml += '''
|
|
</gresource>
|
|
</gresources>'''
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] != '-':
|
|
outfile = sys.argv[1]
|
|
tmpfile = outfile + '~'
|
|
with open(tmpfile, 'w') as f:
|
|
f.write(xml)
|
|
replace_if_changed(tmpfile, outfile)
|
|
else:
|
|
print(xml)
|