forked from AuroraMiddleware/gtk
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.
49 lines
1.0 KiB
Python
49 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Generate gdk.gresources.xml
|
|
#
|
|
# Usage: gen-gdk-gresources-xml SRCDIR_GDK [OUTPUT-FILE]
|
|
|
|
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)
|
|
|
|
srcdir = sys.argv[1]
|
|
|
|
xml = '''<?xml version='1.0' encoding='UTF-8'?>
|
|
<gresources>
|
|
<gresource prefix='/org/gtk/libgdk'>
|
|
|
|
'''
|
|
|
|
def get_files(subdir,extension):
|
|
return sorted(filter(lambda x: x.endswith((extension)), os.listdir(os.path.join(srcdir,subdir))))
|
|
|
|
for f in get_files('resources/glsl', '.glsl'):
|
|
xml += ' <file alias=\'glsl/{0}\'>resources/glsl/{0}</file>\n'.format(f)
|
|
|
|
xml += '''
|
|
</gresource>
|
|
</gresources>'''
|
|
|
|
if len(sys.argv) > 2:
|
|
outfile = sys.argv[2]
|
|
tmpfile = outfile + '~'
|
|
with open(tmpfile, 'w') as f:
|
|
f.write(xml)
|
|
replace_if_changed(tmpfile, outfile)
|
|
else:
|
|
print(xml)
|