Make to-array.py list itself as a dependency of its outputs

This causes these dependencies to be rebuilt if the script chanages, which is heaps better than having to remember to clean the build directory every time.
This commit is contained in:
Tamás Bálint Misius
2024-08-07 10:20:43 +02:00
parent 295aad1800
commit 281dbfa283
2 changed files with 19 additions and 1 deletions

View File

@@ -22,7 +22,8 @@ fs = import('fs')
to_array = generator( to_array = generator(
python3_prog, python3_prog,
output: [ '@PLAINNAME@.cpp', '@PLAINNAME@.h' ], output: [ '@PLAINNAME@.cpp', '@PLAINNAME@.h' ],
arguments: [ join_paths(meson.current_source_dir(), 'resources/to-array.py'), '@OUTPUT0@', '@OUTPUT1@', '@INPUT@', '@EXTRA_ARGS@' ] depfile: '@PLAINNAME@.dep',
arguments: [ join_paths(meson.current_source_dir(), 'resources/to-array.py'), '@OUTPUT0@', '@OUTPUT1@', '@DEPFILE@', '@INPUT@', '@EXTRA_ARGS@' ]
) )
render_icons_with_inkscape = get_option('render_icons_with_inkscape') render_icons_with_inkscape = get_option('render_icons_with_inkscape')

View File

@@ -1,13 +1,17 @@
import os
import sys import sys
( (
script, script,
output_cpp_path, output_cpp_path,
output_h_path, output_h_path,
output_dep_path,
input_path, input_path,
symbol_name, symbol_name,
) = sys.argv ) = sys.argv
script_path = os.path.realpath(__file__)
with open(input_path, 'rb') as input_f: with open(input_path, 'rb') as input_f:
data = input_f.read() data = input_f.read()
data_size = len(data) data_size = len(data)
@@ -26,3 +30,16 @@ with open(output_h_path, 'w') as output_h_f:
extern const unsigned char {symbol_name}[]; extern const unsigned char {symbol_name}[];
extern const unsigned int {symbol_name}_size; extern const unsigned int {symbol_name}_size;
''') ''')
def dep_escape(s):
t = ''
for c in s:
if c in [ ' ', '\n', '\\', ':', '$' ]:
t += '$'
t += c
return t
with open(output_dep_path, 'w') as output_dep_f:
output_dep_f.write(f'''
{dep_escape(output_cpp_path)} {dep_escape(output_h_path)}: {dep_escape(input_path)} {dep_escape(script_path)}
''')