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.
This commit is contained in:
Daan De Meyer committed 2026-10-19 13:59:44 +02:00
1 parent 1d4601422a
commit d7b1045ac8
11 files changed
+35 -25

No files matched your search

+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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]] : []
+5 -4
View File
@@ -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,
'.'])
#####################################################################
+5 -3
View File
@@ -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)
+4 -2
View File
@@ -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@',
-2
View File
@@ -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'
+1
View File
@@ -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(
+5 -3
View File
@@ -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@', '<netinet/in.h>'],
command : [python, generate_gperfs, 'ip_protocol', 'IPPROTO_', '@INPUT@', '<netinet/in.h>'],
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@'],
+8 -6
View File
@@ -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')
+2
View File
@@ -7,6 +7,8 @@ version_h = custom_target('version',
output : 'version.h',
capture : true,
command : [
env,
'bash',
vcs_tag_sh,
'@INPUT@',
get_option('mode'),
+2 -2
View File
@@ -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 }