2017-03-18 12:14:12 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Generate gsk.resources.xml
|
|
|
|
#
|
2017-04-19 13:08:13 +00:00
|
|
|
# Usage: gen-gsk-gresources-xml OUTPUT-FILE [INPUT-FILE1] [INPUT-FILE2] ...
|
2017-03-18 12:14:12 +00:00
|
|
|
|
|
|
|
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-18 12:14:12 +00:00
|
|
|
|
2021-03-12 02:31:31 +00:00
|
|
|
gl_source_shaders = []
|
|
|
|
ngl_source_shaders = []
|
2017-03-18 12:14:12 +00:00
|
|
|
vulkan_compiled_shaders = []
|
2023-08-21 00:18:37 +00:00
|
|
|
gpu_vulkan_compiled_shaders = []
|
2017-03-18 12:14:12 +00:00
|
|
|
vulkan_shaders = []
|
|
|
|
|
|
|
|
for f in sys.argv[2:]:
|
|
|
|
if f.endswith('.glsl'):
|
2023-08-21 00:18:37 +00:00
|
|
|
if f.find('gsk/gpu') > -1:
|
|
|
|
ngl_source_shaders.append(f)
|
2021-03-12 02:31:31 +00:00
|
|
|
else:
|
|
|
|
gl_source_shaders.append(f)
|
2017-03-18 12:14:12 +00:00
|
|
|
elif f.endswith('.spv'):
|
2023-08-21 00:18:37 +00:00
|
|
|
if f.find('gsk/gpu') > -1:
|
|
|
|
gpu_vulkan_compiled_shaders.append(f)
|
|
|
|
else:
|
|
|
|
vulkan_compiled_shaders.append(f)
|
2017-03-18 12:14:12 +00:00
|
|
|
elif f.endswith('.frag') or f.endswith('.vert'):
|
|
|
|
vulkan_shaders.append(f)
|
|
|
|
else:
|
2023-08-21 00:18:37 +00:00
|
|
|
raise Exception(f"No idea what XML to generate for {f}")
|
2017-03-18 12:14:12 +00:00
|
|
|
|
|
|
|
xml = '''<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<gresources>
|
|
|
|
<gresource prefix='/org/gtk/libgsk'>
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
2021-03-12 02:31:31 +00:00
|
|
|
for f in gl_source_shaders:
|
2021-04-03 12:16:50 +00:00
|
|
|
xml += ' <file alias=\'gl/{0}\'>gl/resources/{0}</file>\n'.format(os.path.basename(f))
|
2017-03-18 12:14:12 +00:00
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2021-03-12 02:31:31 +00:00
|
|
|
for f in ngl_source_shaders:
|
2023-08-21 00:18:37 +00:00
|
|
|
xml += ' <file alias=\'shaders/gl/{0}\'>gpu/shaders/{0}</file>\n'.format(os.path.basename(f))
|
2021-03-12 02:31:31 +00:00
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2017-03-18 12:14:12 +00:00
|
|
|
for f in vulkan_compiled_shaders:
|
2021-04-03 12:16:50 +00:00
|
|
|
xml += ' <file alias=\'vulkan/{0}\'>vulkan/resources/{0}</file>\n'.format(os.path.basename(f))
|
2017-03-18 12:14:12 +00:00
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
for f in gpu_vulkan_compiled_shaders:
|
|
|
|
xml += ' <file alias=\'shaders/vulkan/{0}\'>gpu/shaders/{0}</file>\n'.format(os.path.basename(f))
|
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2017-03-18 12:14:12 +00:00
|
|
|
for f in vulkan_shaders:
|
2021-04-03 12:16:50 +00:00
|
|
|
xml += ' <file alias=\'vulkan/{0}\'>vulkan/resources/{0}</file>\n'.format(os.path.basename(f))
|
2017-03-18 12:14:12 +00:00
|
|
|
|
|
|
|
xml += '''
|
|
|
|
</gresource>
|
|
|
|
</gresources>'''
|
|
|
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] != '-':
|
|
|
|
outfile = sys.argv[1]
|
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-18 12:14:12 +00:00
|
|
|
else:
|
|
|
|
print(xml)
|