2017-03-19 15:46:55 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Generate gdk.gresources.xml
|
|
|
|
#
|
|
|
|
# Usage: gen-gdk-gresources-xml SRCDIR_GDK [OUTPUT-FILE]
|
|
|
|
|
|
|
|
import os, sys
|
2020-04-03 11:58:18 +00:00
|
|
|
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)
|
2017-03-19 15:46:55 +00:00
|
|
|
|
|
|
|
srcdir = sys.argv[1]
|
|
|
|
|
|
|
|
xml = '''<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<gresources>
|
|
|
|
<gresource prefix='/org/gtk/libgdk'>
|
2020-04-26 18:41:52 +00:00
|
|
|
<file alias='cursor/default'>default_cursor.png</file>
|
2017-03-19 15:46:55 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
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]
|
2020-04-03 11:58:18 +00:00
|
|
|
tmpfile = outfile + '~'
|
|
|
|
with open(tmpfile, 'w') as f:
|
|
|
|
f.write(xml)
|
|
|
|
replace_if_changed(tmpfile, outfile)
|
2017-03-19 15:46:55 +00:00
|
|
|
else:
|
|
|
|
print(xml)
|