From cb86341829d6fb3873ad7e160dca8f3fff033c1b Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Tue, 7 Oct 2025 17:55:31 +0200 Subject: [PATCH] meson: remove '--outdir' argument in script Usage of '--outdir' argument in python scripts makes it very complicated for tools like ninja-to-soong to generate the Android equivalent build file. This is because the option is less clear on what will be generated. Instead, change it for '--out' where we give the full path of the file to generate. This has the good point of deduplicating the locations of the file name to have it only in 'meson.build'. Part-of: --- src/compiler/nir/meson.build | 6 +++--- src/compiler/nir/nir_intrinsics_c.py | 7 +++---- src/compiler/nir/nir_intrinsics_h.py | 7 +++---- src/compiler/nir/nir_intrinsics_indices_h.py | 7 +++---- src/intel/compiler/brw_device_sha1_gen_c.py | 7 +++---- src/intel/compiler/meson.build | 2 +- src/vulkan/util/gen_enum_to_str.py | 16 +++++++++++----- src/vulkan/util/meson.build | 6 ++++-- src/vulkan/util/vk_struct_type_cast_gen.py | 6 +++--- 9 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build index b2ce4c4e38b..640619049ed 100644 --- a/src/compiler/nir/meson.build +++ b/src/compiler/nir/meson.build @@ -53,7 +53,7 @@ nir_intrinsics_h = custom_target( 'nir_intrinsics.h', input : 'nir_intrinsics_h.py', output : 'nir_intrinsics.h', - command : [prog_python, '@INPUT@', '--outdir', meson.current_build_dir()], + command : [prog_python, '@INPUT@', '--out', '@OUTPUT@'], capture : false, depend_files : files('nir_intrinsics.py'), ) @@ -62,7 +62,7 @@ nir_intrinsics_indices_h = custom_target( 'nir_intrinsics_indices.h', input : 'nir_intrinsics_indices_h.py', output : 'nir_intrinsics_indices.h', - command : [prog_python, '@INPUT@', '--outdir', meson.current_build_dir()], + command : [prog_python, '@INPUT@', '--out', '@OUTPUT@'], capture : false, depend_files : files('nir_intrinsics.py'), ) @@ -71,7 +71,7 @@ nir_intrinsics_c = custom_target( 'nir_intrinsic.c', input : 'nir_intrinsics_c.py', output : 'nir_intrinsics.c', - command : [prog_python, '@INPUT@', '--outdir', meson.current_build_dir()], + command : [prog_python, '@INPUT@', '--out', '@OUTPUT@'], capture: false, depend_files : files('nir_intrinsics.py'), ) diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py index 51e6de763fa..72a591dc35a 100644 --- a/src/compiler/nir/nir_intrinsics_c.py +++ b/src/compiler/nir/nir_intrinsics_c.py @@ -72,13 +72,12 @@ import os def main(): parser = argparse.ArgumentParser() - parser.add_argument('--outdir', required=True, - help='Directory to put the generated files in') + parser.add_argument('--out', required=True, + help='Output C file') args = parser.parse_args() - path = os.path.join(args.outdir, 'nir_intrinsics.c') - with open(path, 'w', encoding='utf-8') as f: + with open(args.out, 'w', encoding='utf-8') as f: f.write(Template(template).render( INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES, reduce=reduce, operator=operator)) diff --git a/src/compiler/nir/nir_intrinsics_h.py b/src/compiler/nir/nir_intrinsics_h.py index 64e7425941a..a7beb84a8d5 100644 --- a/src/compiler/nir/nir_intrinsics_h.py +++ b/src/compiler/nir/nir_intrinsics_h.py @@ -56,13 +56,12 @@ import os def main(): parser = argparse.ArgumentParser() - parser.add_argument('--outdir', required=True, - help='Directory to put the generated files in') + parser.add_argument('--out', required=True, + help='Output H file') args = parser.parse_args() - path = os.path.join(args.outdir, 'nir_intrinsics.h') - with open(path, 'w', encoding='utf-8') as f: + with open(args.out, 'w', encoding='utf-8') as f: f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES)) if __name__ == '__main__': diff --git a/src/compiler/nir/nir_intrinsics_indices_h.py b/src/compiler/nir/nir_intrinsics_indices_h.py index 9f20814b1b7..115cd5d0304 100644 --- a/src/compiler/nir/nir_intrinsics_indices_h.py +++ b/src/compiler/nir/nir_intrinsics_indices_h.py @@ -80,13 +80,12 @@ import os def main(): parser = argparse.ArgumentParser() - parser.add_argument('--outdir', required=True, - help='Directory to put the generated files in') + parser.add_argument('--out', required=True, + help='Output H file') args = parser.parse_args() - path = os.path.join(args.outdir, 'nir_intrinsics_indices.h') - with open(path, 'w', encoding='utf-8') as f: + with open(args.out, 'w', encoding='utf-8') as f: f.write(Template(template).render(INTR_INDICES=INTR_INDICES)) if __name__ == '__main__': diff --git a/src/intel/compiler/brw_device_sha1_gen_c.py b/src/intel/compiler/brw_device_sha1_gen_c.py index be4ce3ac4f3..24e28d41038 100755 --- a/src/intel/compiler/brw_device_sha1_gen_c.py +++ b/src/intel/compiler/brw_device_sha1_gen_c.py @@ -63,13 +63,12 @@ brw_device_sha1_update(struct mesa_sha1 *ctx, def main(): """print intel_device_serialize.c at the specified path""" parser = argparse.ArgumentParser() - parser.add_argument('--outdir', required=True, - help='Directory to put the generated files in') + parser.add_argument('--out', required=True, + help='Output C file') args = parser.parse_args() - path = os.path.join(args.outdir, 'brw_device_sha1_gen.c') device_members = intel_device_info.TYPES_BY_NAME["intel_device_info"].members compiler_fields = [field for field in device_members if field.compiler_field] - with open(path, 'w', encoding='utf-8') as f: + with open(args.out, 'w', encoding='utf-8') as f: try: f.write(Template(template).render(compiler_fields=compiler_fields)) except: diff --git a/src/intel/compiler/meson.build b/src/intel/compiler/meson.build index 89d23645fe0..0b82ad39d2c 100644 --- a/src/intel/compiler/meson.build +++ b/src/intel/compiler/meson.build @@ -127,7 +127,7 @@ libintel_compiler_brw_files = files( brw_device_sha1_gen_src = custom_target('brw_device_sha1_gen.c', input : ['brw_device_sha1_gen_c.py', '../dev/intel_device_info.py'], output : ['brw_device_sha1_gen.c'], - command : [prog_python, '@INPUT0@', '--outdir', meson.current_build_dir()]) + command : [prog_python, '@INPUT0@', '--out', '@OUTPUT@']) brw_nir_lower_fsign = custom_target( diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py index a2a04a29b5d..d034c7fb7a7 100644 --- a/src/vulkan/util/gen_enum_to_str.py +++ b/src/vulkan/util/gen_enum_to_str.py @@ -538,8 +538,14 @@ def main(): help='Vulkan API XML files', action='append', dest='xml_files') - parser.add_argument('--outdir', - help='Directory to put the generated files in', + parser.add_argument('--out-c', + help='Output C file', + required=True) + parser.add_argument('--out-h', + help='Output H file', + required=True) + parser.add_argument('--out-d', + help='Output defines H file', required=True) args = parser.parse_args() @@ -559,9 +565,9 @@ def main(): bitmasks = sorted(bitmask_factory.registry.values(), key=lambda e: e.name) object_types = sorted(obj_type_factory.registry.values(), key=lambda e: e.name) - for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')), - (H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h')), - (H_DEFINE_TEMPLATE, os.path.join(args.outdir, 'vk_enum_defines.h'))]: + for template, file_ in [(C_TEMPLATE, args.out_c), + (H_TEMPLATE, args.out_h), + (H_DEFINE_TEMPLATE, args.out_d)]: with open(file_, 'w', encoding='utf-8') as f: f.write(template.render( file=os.path.basename(__file__), diff --git a/src/vulkan/util/meson.build b/src/vulkan/util/meson.build index 8e88c7971b2..4915fc80f30 100644 --- a/src/vulkan/util/meson.build +++ b/src/vulkan/util/meson.build @@ -90,7 +90,9 @@ vk_enum_to_str = custom_target( output : ['vk_enum_to_str.c', 'vk_enum_to_str.h', 'vk_enum_defines.h'], command : [ prog_python, '@INPUT0@', '--xml', '@INPUT1@', - '--outdir', meson.current_build_dir(), + '--out-c', '@OUTPUT0@', + '--out-h', '@OUTPUT1@', + '--out-d', '@OUTPUT2@', '--beta', with_vulkan_beta.to_string() ], depend_files : vk_enum_to_str_depend_files, @@ -102,7 +104,7 @@ vk_struct_type_cast = custom_target( output : ['vk_struct_type_cast.h'], command : [ prog_python, '@INPUT0@', '--xml', '@INPUT1@', - '--outdir', meson.current_build_dir(), + '--out', '@OUTPUT@', '--beta', with_vulkan_beta.to_string() ], depend_files : vk_struct_type_cast_depend_files, diff --git a/src/vulkan/util/vk_struct_type_cast_gen.py b/src/vulkan/util/vk_struct_type_cast_gen.py index 9cd0e884979..df5f61ef944 100644 --- a/src/vulkan/util/vk_struct_type_cast_gen.py +++ b/src/vulkan/util/vk_struct_type_cast_gen.py @@ -91,8 +91,8 @@ def main(): help='Vulkan API XML files', action='append', dest='xml_files') - parser.add_argument('--outdir', - help='Directory to put the generated files in', + parser.add_argument('--out', + help='Output H file', required=True) parser.add_argument('--beta', required=True, help='Enable beta extensions.') @@ -105,7 +105,7 @@ def main(): structs = sorted(structs, key=lambda s: s.name) - for template, file_ in [(H_TEMPLATE, os.path.join(args.outdir, 'vk_struct_type_cast.h'))]: + for template, file_ in [(H_TEMPLATE, args.out)]: with open(file_, 'w', encoding='utf-8') as f: f.write(template.render( file=os.path.basename(__file__),