From d7b1045ac8b9c2c010973d833c27f382ae224a3f Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 19 Oct 2026 13:42:45 +0200 Subject: [PATCH] meson: run build scripts through their interpreter When a script declared with files() is the first element of a command, meson replaces it with the script's absolute path. When the source and build directories are reconfigured at a different absolute path, the command lines of the jinja2 templates and of most generators change. ninja then runs the templates and generators again. Some of the generators also get absolute directories as arguments. Let's run the scripts through python or bash, the same way most of our generators already do. meson then passes the script relative to the build directory. We also pass the directory arguments relative to the build directory. --- hwdb.d/meson.build | 2 +- man/meson.build | 4 ++-- meson.build | 9 +++++---- src/basic/meson.build | 8 +++++--- src/boot/meson.build | 6 ++++-- src/libsystemd/meson.build | 2 -- src/libudev/meson.build | 1 + src/shared/meson.build | 8 +++++--- src/test/meson.build | 14 ++++++++------ src/version/meson.build | 2 ++ test/fuzz/meson.build | 4 ++-- 11 files changed, 35 insertions(+), 25 deletions(-) diff --git a/hwdb.d/meson.build b/hwdb.d/meson.build index b031bd1d924..8767945a1ce 100644 --- a/hwdb.d/meson.build +++ b/hwdb.d/meson.build @@ -49,7 +49,7 @@ hwdb_files_test = files( if conf.get('ENABLE_HWDB') == 1 auto_suspend_rules = custom_target( output : '60-autosuspend-chromiumos.hwdb', - command : make_autosuspend_rules_py, + command : [python, make_autosuspend_rules_py], capture : true, install : true, install_dir: udevhwdbdir, diff --git a/man/meson.build b/man/meson.build index 7e30e2f1137..6ec948af031 100644 --- a/man/meson.build +++ b/man/meson.build @@ -120,13 +120,13 @@ systemd_directives_xml = custom_target( input : ['directives-template.xml', source_xml_files], output : 'systemd.directives.xml', depends : man_page_depends, - command : [make_directive_index_py, '@OUTPUT@', '@INPUT@']) + command : [python, make_directive_index_py, '@OUTPUT@', '@INPUT@']) nonindex_xml_files = source_xml_files + [systemd_directives_xml] systemd_index_xml = custom_target( input : nonindex_xml_files, output : 'systemd.index.xml', - command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files) + command : [python, make_man_index_py, '@OUTPUT@'] + nonindex_xml_files) foreach tuple : xsltproc.found() and have_lxml ? [['systemd.directives', '7', systemd_directives_xml], ['systemd.index', '7', systemd_index_xml]] : [] diff --git a/meson.build b/meson.build index 693517ce100..0bce338e338 100644 --- a/meson.build +++ b/meson.build @@ -1847,7 +1847,7 @@ config_h = configure_file( userspace_c_args += ['-include', 'config.h'] -jinja2_cmdline = [meson_render_jinja2_py, config_h] +jinja2_cmdline = [python, meson_render_jinja2_py, config_h] userspace = declare_dependency( compile_args : userspace_c_args, @@ -3076,7 +3076,7 @@ if not meson.is_cross_build() output : fs.name(dbus_interfaces_dir), install : dbus_interfaces_dir != 'no', install_dir : fs.parent(dbus_interfaces_dir), - command : [dbus_exporter_py, '@OUTPUT@', dbus_programs]) + command : [python, dbus_exporter_py, '@OUTPUT@', dbus_programs]) endif custom_target( @@ -3084,8 +3084,9 @@ custom_target( capture : true, install : want_tests != 'no' and install_tests, install_dir : testdata_dir, - command : [meson_extract_unit_files_py, - meson.project_build_root()]) + command : [python, + meson_extract_unit_files_py, + '.']) ##################################################################### diff --git a/src/basic/meson.build b/src/basic/meson.build index e47d74c3f7b..18cd6a5a7d0 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -158,7 +158,7 @@ foreach item : [ gperf_file = custom_target( input : list_txt, output : '@0@-from-name.gperf'.format(item[0]), - command : [generate_gperfs, item[0], item[2], '@INPUT@'] + item[3], + command : [python, generate_gperfs, item[0], item[2], '@INPUT@'] + item[3], capture : true) target = custom_target( @@ -184,7 +184,8 @@ basic_sources += generated_gperf_headers filesystem_sets_py = files('filesystem-sets.py') filesystem_sets_c = custom_target( output : 'filesystem-sets.c', - command : [filesystem_sets_py, + command : [python, + filesystem_sets_py, 'fs-type-to-string', 'filesystem-sets', 'fs-in-group'], @@ -192,7 +193,8 @@ filesystem_sets_c = custom_target( filesystems_gperf_gperf = custom_target( output : 'filesystems-gperf.gperf', - command : [filesystem_sets_py, + command : [python, + filesystem_sets_py, 'gperf'], capture : true) diff --git a/src/boot/meson.build b/src/boot/meson.build index 75f5b46dc08..0aa6526de1c 100644 --- a/src/boot/meson.build +++ b/src/boot/meson.build @@ -31,8 +31,9 @@ if conf.get('ENABLE_UKIFY') == 1 test_hwids_section_c = custom_target( input : ['hwids/test/device1.json', 'hwids/test/device2.json', 'hwids/test/device3.json', 'hwids/test/device4.json'], output : 'test-hwids-section.c', - command : [files('generate-hwids-section.py'), - meson.current_source_dir()/'hwids/test'], + command : [python, + files('generate-hwids-section.py'), + relative_source_path / 'src/boot/hwids/test'], capture : true, build_by_default : want_tests != 'false') install_subdir('hwids', @@ -470,6 +471,7 @@ foreach efi_elf_binary : efi_elf_binaries install_dir : bootlibdir, install_tag : 'systemd-boot', command : [ + pyelftools, elf2efi_py, f'--version-major=@project_major_version@', f'--version-minor=@project_minor_version@', diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index 6c855270d50..1f2db927e8d 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -161,8 +161,6 @@ libsystemd_static = static_library( userspace], build_by_default : false) -libsystemd_dir_path = meson.current_source_dir() - libsystemd_sym = files('libsystemd.sym') libsystemd_sym_path = relative_source_path / 'src/libsystemd/libsystemd.sym' diff --git a/src/libudev/meson.build b/src/libudev/meson.build index 1bf9813e18b..6feb85f9b9d 100644 --- a/src/libudev/meson.build +++ b/src/libudev/meson.build @@ -23,6 +23,7 @@ libudev_sym = files('libudev.sym') libudev_sym_path = relative_source_path / 'src/libudev/libudev.sym' install_headers('libudev.h') +libudev_h = files('libudev.h') libudev_h_path = libudev_dir_path / 'libudev.h' libudev_basic = static_library( diff --git a/src/shared/meson.build b/src/shared/meson.build index ba5e0d1c101..e8a3fc23940 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -293,7 +293,8 @@ endif syscall_list_inc = custom_target( input : syscall_list_txt, output : 'syscall-list.inc', - command : [files('generate-syscall-list.py'), + command : [python, + files('generate-syscall-list.py'), '@INPUT@'], capture : true) @@ -330,7 +331,7 @@ ip_protocol_list_txt = custom_target( gperf_file = custom_target( input : ip_protocol_list_txt, output : 'ip-protocol-from-name.gperf', - command : [generate_gperfs, 'ip_protocol', 'IPPROTO_', '@INPUT@', ''], + command : [python, generate_gperfs, 'ip_protocol', 'IPPROTO_', '@INPUT@', ''], capture : true) target1 = custom_target( @@ -381,7 +382,8 @@ dns_type_list_txt = custom_target( gperf_file = custom_target( input : dns_type_list_txt, output : 'dns_type-from-name.gperf', - command : [files('generate-dns_type-gperf.py'), + command : [python, + files('generate-dns_type-gperf.py'), 'dns_type', 'DNS_TYPE_', '@INPUT@'], diff --git a/src/test/meson.build b/src/test/meson.build index 71b48b96219..7f73c2126b8 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -32,22 +32,24 @@ test_libsystemd_sym_c = custom_target( systemd_headers, libsystemd_sources], output : 'test-libsystemd-sym.c', - command : [generate_sym_test_py, + command : [python, + generate_sym_test_py, '@INPUT0@', - libsystemd_dir_path, + relative_source_path / 'src/libsystemd', systemd_headers], capture : true, build_by_default : want_tests != 'false') test_libudev_sym_c = custom_target( input : [libudev_sym, - libudev_h_path, + libudev_h, libudev_sources], output : 'test-libudev-sym.c', - command : [generate_sym_test_py, + command : [python, + generate_sym_test_py, '@INPUT0@', - libudev_dir_path, - libudev_h_path], + relative_source_path / 'src/libudev', + '@INPUT1@'], capture : true, build_by_default : want_tests != 'false') diff --git a/src/version/meson.build b/src/version/meson.build index a0b03f41a65..85bfb0a94eb 100644 --- a/src/version/meson.build +++ b/src/version/meson.build @@ -7,6 +7,8 @@ version_h = custom_target('version', output : 'version.h', capture : true, command : [ + env, + 'bash', vcs_tag_sh, '@INPUT@', get_option('mode'), diff --git a/test/fuzz/meson.build b/test/fuzz/meson.build index 2aac54b43f0..ea3e966bdfb 100644 --- a/test/fuzz/meson.build +++ b/test/fuzz/meson.build @@ -12,7 +12,7 @@ directives = [['fuzz-network-parser', 'directives.network', networkd_network_gpe foreach tuple : directives directive = custom_target( output: tuple[1], - command: [generate_directives_py, tuple[2]], + command: [python, generate_directives_py, tuple[2]], capture: true) dict = { 'directives' : [directive] } @@ -26,7 +26,7 @@ foreach section : ['Automount', 'Mount', 'Path', 'Scope', 'Service', 'Slice', 'S name = f'directives.@unit_type@' unit_directives += custom_target( output: name, - command: [generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type], + command: [python, generate_directives_py, load_fragment_gperf_gperf, sec_rx, unit_type], capture: true) endforeach dict = { 'directives' : unit_directives }