Skip to content

Commit e3c6892

Browse files
igo95862keszybz
authored andcommitted
Export D-Bus interfaces to /usr/share/dbus-1/interfaces
Pass -Ddbus-interfaces-dir=no to meson to disable export Interfaces from: org.freedesktop.home1 org.freedesktop.hostname1 org.freedesktop.import1 org.freedesktop.locale1 org.freedesktop.LogControl1 org.freedesktop.login1 org.freedesktop.machine1 org.freedesktop.oom1 org.freedesktop.portable1 org.freedesktop.resolve1 org.freedesktop.systemd1 org.freedesktop.timedate1
1 parent 082c676 commit e3c6892

File tree

3 files changed

+90
-11
lines changed

3 files changed

+90
-11
lines changed

meson.build

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,7 @@ update_hwdb_sh = find_program('tools/update-hwdb.sh')
16931693
update_hwdb_autosuspend_sh = find_program('tools/update-hwdb-autosuspend.sh')
16941694
update_syscall_tables_sh = find_program('tools/update-syscall-tables.sh')
16951695
xml_helper_py = find_program('tools/xml_helper.py')
1696+
export_dbus_interfaces_py = find_program('tools/dbus_exporter.py')
16961697

16971698
#####################################################################
16981699

@@ -1708,6 +1709,13 @@ add_project_arguments('-include', 'config.h', language : 'c')
17081709
# usually, but not always, installed in /bin.
17091710
public_programs = []
17101711

1712+
# D-Bus introspection XML export
1713+
dbus_programs = []
1714+
dbus_interfaces_dir = get_option('dbus-interfaces-dir')
1715+
if dbus_interfaces_dir == ''
1716+
dbus_interfaces_dir = get_option('datadir') + '/dbus-1'
1717+
endif
1718+
17111719
tests = []
17121720
fuzzers = []
17131721

@@ -1975,7 +1983,7 @@ endforeach
19751983

19761984
############################################################
19771985

1978-
executable(
1986+
dbus_programs += executable(
19791987
'systemd',
19801988
systemd_sources,
19811989
include_directories : includes,
@@ -2144,7 +2152,7 @@ if conf.get('HAVE_BLKID') == 1
21442152
endif
21452153

21462154
if conf.get('ENABLE_RESOLVE') == 1
2147-
executable(
2155+
dbus_programs += executable(
21482156
'systemd-resolved',
21492157
systemd_resolved_sources,
21502158
include_directories : resolve_includes,
@@ -2181,7 +2189,7 @@ if conf.get('ENABLE_RESOLVE') == 1
21812189
endif
21822190

21832191
if conf.get('ENABLE_LOGIND') == 1
2184-
executable(
2192+
dbus_programs += executable(
21852193
'systemd-logind',
21862194
systemd_logind_sources,
21872195
include_directories : includes,
@@ -2327,7 +2335,7 @@ public_programs += executable(
23272335
install_dir : rootbindir)
23282336

23292337
if conf.get('ENABLE_PORTABLED') == 1
2330-
executable(
2338+
dbus_programs += executable(
23312339
'systemd-portabled',
23322340
systemd_portabled_sources,
23332341
include_directories : includes,
@@ -2407,7 +2415,7 @@ if conf.get('ENABLE_HOMED') == 1
24072415
install : true,
24082416
install_dir : rootlibexecdir)
24092417

2410-
executable(
2418+
dbus_programs += executable(
24112419
'systemd-homed',
24122420
systemd_homed_sources,
24132421
include_directories : home_includes,
@@ -2610,7 +2618,7 @@ if conf.get('ENABLE_XDG_AUTOSTART') == 1
26102618
endif
26112619

26122620
if conf.get('ENABLE_HOSTNAMED') == 1
2613-
executable(
2621+
dbus_programs += executable(
26142622
'systemd-hostnamed',
26152623
'src/hostname/hostnamed.c',
26162624
include_directories : includes,
@@ -2637,7 +2645,7 @@ if conf.get('ENABLE_LOCALED') == 1
26372645
deps = []
26382646
endif
26392647

2640-
executable(
2648+
dbus_programs += executable(
26412649
'systemd-localed',
26422650
systemd_localed_sources,
26432651
include_directories : includes,
@@ -2657,7 +2665,7 @@ if conf.get('ENABLE_LOCALED') == 1
26572665
endif
26582666

26592667
if conf.get('ENABLE_TIMEDATED') == 1
2660-
executable(
2668+
dbus_programs += executable(
26612669
'systemd-timedated',
26622670
'src/timedate/timedated.c',
26632671
include_directories : includes,
@@ -2701,7 +2709,7 @@ if conf.get('ENABLE_TIMESYNCD') == 1
27012709
endif
27022710

27032711
if conf.get('ENABLE_MACHINED') == 1
2704-
executable(
2712+
dbus_programs += executable(
27052713
'systemd-machined',
27062714
systemd_machined_sources,
27072715
include_directories : includes,
@@ -2726,7 +2734,7 @@ if conf.get('ENABLE_MACHINED') == 1
27262734
endif
27272735

27282736
if conf.get('ENABLE_IMPORTD') == 1
2729-
executable(
2737+
dbus_programs += executable(
27302738
'systemd-importd',
27312739
systemd_importd_sources,
27322740
include_directories : includes,
@@ -2885,7 +2893,7 @@ if conf.get('ENABLE_PSTORE') == 1
28852893
endif
28862894

28872895
if conf.get('ENABLE_OOMD') == 1
2888-
executable('systemd-oomd',
2896+
dbus_programs += executable('systemd-oomd',
28892897
systemd_oomd_sources,
28902898
include_directories : includes,
28912899
link_with : [libshared],
@@ -3829,6 +3837,13 @@ run_target(
38293837
alias_target('update-dbus-docs', update_dbus_docs)
38303838
alias_target('update-man-rules', update_man_rules)
38313839

3840+
custom_target(
3841+
'export-dbus-interfaces',
3842+
output : 'interfaces',
3843+
install : dbus_interfaces_dir != 'no',
3844+
install_dir : dbus_interfaces_dir,
3845+
command : [export_dbus_interfaces_py, '@OUTPUT@', dbus_programs])
3846+
38323847
############################################################
38333848

38343849
alt_time_epoch = run_command('date', '-Is', '-u', '-d', '@@0@'.format(time_epoch),

meson_options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,6 @@ option('analyze', type: 'boolean', value: 'true',
479479

480480
option('bpf-framework', type : 'combo', choices : ['auto', 'true', 'false'],
481481
description: 'build BPF programs from source code in restricted C')
482+
483+
option('dbus-interfaces-dir', type : 'string',
484+
description : 'export D-Bus introspection XML as standalone files')

tools/dbus_exporter.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
from argparse import ArgumentParser
4+
from pathlib import Path
5+
from subprocess import run, PIPE
6+
7+
8+
def extract_interfaces_xml(output_dir, executable):
9+
list_interfaces_process = run(
10+
args=[executable.absolute(), '--bus-introspect', 'list'],
11+
stdout=PIPE,
12+
check=True,
13+
universal_newlines=True,
14+
)
15+
16+
interfaces_lines = list_interfaces_process.stdout.splitlines()
17+
18+
interface_names = [x.split()[1] for x in interfaces_lines]
19+
20+
for interface_name in interface_names:
21+
interface_introspection_run = run(
22+
args=[executable.absolute(), '--bus-introspect', interface_name],
23+
stdout=PIPE,
24+
check=True,
25+
universal_newlines=True,
26+
)
27+
28+
interface_file_name = output_dir / (interface_name + '.xml')
29+
with open(interface_file_name, mode='w') as f:
30+
f.write(interface_introspection_run.stdout)
31+
interface_file_name.chmod(0o644)
32+
33+
34+
def iterate_executables(output_dir, executables):
35+
output_dir.mkdir(mode=0o755, exist_ok=True)
36+
37+
for exe in executables:
38+
extract_interfaces_xml(output_dir, exe)
39+
40+
41+
def main():
42+
parser = ArgumentParser()
43+
44+
parser.add_argument(
45+
'output',
46+
type=Path,
47+
)
48+
49+
parser.add_argument(
50+
'executables',
51+
type=Path,
52+
nargs='+',
53+
)
54+
55+
args = parser.parse_args()
56+
57+
iterate_executables(args.output, args.executables)
58+
59+
60+
if __name__ == '__main__':
61+
main()

0 commit comments

Comments
 (0)