]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
meson: Introduce message_bus and tools command line option
authorDaniel Wagner <dwagner@suse.de>
Thu, 24 Nov 2022 08:17:45 +0000 (09:17 +0100)
committerDaniel Wagner <dwagner@suse.de>
Wed, 4 Jan 2023 08:35:06 +0000 (09:35 +0100)
To make the consume libdbus via Meson's subproject use case more useful,
introduce message_bus and tools command line options which control if
the D-Bus daemon and/or the tools are build. The idea here is that
depending projects are interested only in the library.

The strong recommendation is only to build libdbus as static library:

  libdbus_dep = dependency(
    'dbus-1',
    required: get_option('libdbus'),
    fallback: ['dbus', 'libdbus_dep'],
    default_options: [
      'default_library=static',
      'embedded_tests=false',
      'message_bus=false',
      'modular_tests=disabled',
      'tools=false',
    ],
  )

This ensures that any installed D-Bus infrastructure on the target
system is not overwritten.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
meson.build
meson_options.txt
test/data/meson.build
test/meson.build
tools/meson.build

index 33294e2e6b111742215994dd1d0ea93dbda4cdcc..fdb54e77dea50e3185359ef19f4b171998976e31 100644 (file)
@@ -333,25 +333,44 @@ config.set(
     and cc.has_header_symbol('time.h', 'clock_getres', args: compile_args_c),
 )
 
-glib = dependency(
-    'glib-2.0', version: '>=2.40',
-    required: get_option('modular_tests'),
-    fallback: ['glib', 'libglib_dep'],
-    default_options: [
-        'tests=false',
-    ],
-)
-if platform_windows
-    gio = dependency('gio-windows-2.0', required: glib.found())
-    have_gio_unix = false
+# Controls whether message bus daemon is built. Tests which depend on
+# a running dbus-daemon will be disabled if message_bus is not set.
+message_bus = get_option('message_bus')
+
+if get_option('modular_tests').disabled()
+    glib = dependency('', required: false)
+else
+    glib = dependency(
+        'glib-2.0', version: '>=2.40',
+        required: get_option('modular_tests'),
+        fallback: ['glib', 'libglib_dep'],
+        default_options: [
+           'tests=false',
+        ],
+    )
+endif
+
+if glib.found()
+    if platform_windows
+        gio = dependency('gio-windows-2.0', required: glib.found())
+        have_gio_unix = false
+    else
+        gio = dependency('gio-unix-2.0',    required: glib.found())
+        have_gio_unix = gio.found()
+    endif
 else
-    gio = dependency('gio-unix-2.0',    required: glib.found())
-    have_gio_unix = gio.found()
+    gio = dependency('', required: false)
+    have_gio_unix = false
 endif
 use_glib = glib.found() and gio.found()
 config.set('DBUS_WITH_GLIB', use_glib)
 
-expat = dependency('expat')
+if message_bus
+    expat = dependency('expat')
+else
+    expat = dependency('', required: false)
+endif
+
 if expat.type_name() == 'internal'
     # Configure-time checks can't act on subprojects that haven't been
     # built yet, but we know that subprojects/expat.wrap is a new enough
@@ -473,7 +492,7 @@ data_config.set('SYSTEMCTL', systemctl)
 
 
 
-use_traditional_activation = get_option('traditional_activation')
+use_traditional_activation = message_bus and get_option('traditional_activation')
 config.set('ENABLE_TRADITIONAL_ACTIVATION', use_traditional_activation)
 
 if not (use_systemd or use_traditional_activation)
@@ -761,6 +780,9 @@ config.set('GLIB_VERSION_MAX_ALLOWED', 'G_ENCODE_VERSION(2,44)')
 windows_output_debug = get_option('windows_output_debug_string')
 config.set('DBUS_USE_OUTPUT_DEBUG_STRING', windows_output_debug)
 
+# Controls whether the tools are built.
+tools = get_option('tools')
+
 # DBUS_ENABLE_EMBEDDED_TESTS controls unit tests built in to .c files
 # and some stuff in the test/ subdir.
 embedded_tests = get_option('embedded_tests')
@@ -1115,8 +1137,12 @@ if platform_unix
 endif
 
 subdir('dbus')
-subdir('bus')
-subdir('tools')
+if message_bus
+    subdir('bus')
+endif
+if tools
+    subdir('tools')
+endif
 subdir('test')
 subdir('doc')
 subdir('cmake')
@@ -1242,6 +1268,8 @@ summary_dict += {
     'Building Ducktype docs':   ducktype.found(),
     'Building XML docs':        build_xml_docs,
     'Building launchd support': use_launchd,
+    'Building dbus-daemon':     message_bus,
+    'Building tools':           tools,
     'System bus socket':        data_config.get('DBUS_SYSTEM_SOCKET'),
     'System bus address':       config.get('DBUS_SYSTEM_BUS_DEFAULT_ADDRESS'),
     'System bus PID file':      data_config.get('DBUS_SYSTEM_PID_FILE'),
index 68f91f1994d0e9d443854bdf0e44bca6da78ec45..83c1c9217933cb6d38a961b61cef6d6ca5ec2c52 100644 (file)
@@ -143,6 +143,13 @@ option(
   description: 'Audit logging support for SELinux and AppArmor'
 )
 
+option(
+  'message_bus',
+  type: 'boolean',
+  value: 'true',
+  description: 'Enable dbus-daemon'
+)
+
 option(
   'modular_tests',
   type: 'feature',
@@ -250,6 +257,13 @@ option(
   value: 'nobody'
 )
 
+option(
+  'tools',
+  type: 'boolean',
+  value: 'true',
+  description: 'Enable CLI tools such as dbus-send and dbus-monitor'
+)
+
 option(
   'traditional_activation',
   type: 'boolean',
index e3646c9f3bfa814f84e88e78d3ace4acd9a7f407..ef5704923911001b57eafa21135776b6f3b7bd0f 100644 (file)
@@ -198,15 +198,16 @@ foreach file : data_in_to_install
     files += dst
 endforeach
 
-files += meson.project_build_root() / 'bus' / 'session.conf'
-files += meson.current_build_dir() / 'valid-config-files/session.conf'
+if message_bus
+    files += meson.project_build_root() / 'bus' / 'session.conf'
+    files += meson.current_build_dir() / 'valid-config-files/session.conf'
 
-if platform_unix
-    files += meson.project_build_root() / 'bus' / 'system.conf'
-    files += meson.current_build_dir() / 'valid-config-files-system/system.conf'
+    if platform_unix
+        files += meson.project_build_root() / 'bus' / 'system.conf'
+        files += meson.current_build_dir() / 'valid-config-files-system/system.conf'
+    endif
 endif
 
-
 run_result = run_command(find_program('copy_data_for_tests.py'), files, check: true)
 
 files_not_found = run_result.stdout().split()
index 2a3c346d12e6d95c4b0814f747e25bc208bc0ac9..966e8ab7eeb060b3c000688a03a19ddb7734f32a 100644 (file)
@@ -54,13 +54,21 @@ test_env.set('G_TEST_BUILDDIR',     meson.current_build_dir())
 test_env.set('DBUS_TEST_EXEC',      meson.current_build_dir())
 test_env.set('DBUS_TEST_DATA',      meson.current_build_dir() / 'data')
 
-test_env.set('DBUS_TEST_DAEMON',        dbus_daemon.full_path())
-test_env.set('DBUS_TEST_DBUS_LAUNCH',   dbus_launch.full_path())
-test_env.set('DBUS_TEST_DBUS_MONITOR',  dbus_monitor.full_path())
-test_env.set('DBUS_TEST_DBUS_SEND',     dbus_send.full_path())
+if message_bus
+    test_env.set('DBUS_TEST_DAEMON',        dbus_daemon.full_path())
+endif
+
+if tools
+    test_env.set('DBUS_TEST_DBUS_MONITOR',  dbus_monitor.full_path())
+    test_env.set('DBUS_TEST_DBUS_SEND',     dbus_send.full_path())
+endif
+
+if message_bus and tools
+    test_env.set('DBUS_TEST_DBUS_LAUNCH',   dbus_launch.full_path())
+endif
 
-if platform_unix
-    test_env.set('DBUS_TEST_DBUS_UUIDGEN', dbus_uuidgen.full_path())
+if platform_unix and tools
+    test_env.set('DBUS_TEST_DBUS_UUIDGEN',  dbus_uuidgen.full_path())
 endif
 
 if platform_windows
@@ -204,7 +212,7 @@ else
     test_data_config.set('TEST_LAUNCH_HELPER_BINARY', '/bin/false')
 endif
 
-if platform_unix and use_glib
+if message_bus and tools and platform_unix and use_glib
     test_apparmor_activation = executable('test-apparmor-activation',
         'sd-activation.c',
         include_directories: root_include,
@@ -226,26 +234,15 @@ subdir('data')
 
 # the "name-test" subdir in fact contains a bunch of tests now that need a
 # temporary bus to be running to do stuff with. The directory should be renamed.
-subdir('name-test')
+if message_bus and tools
+    subdir('name-test')
+endif
 
 tests = []
 
 if embedded_tests
 
     tests += [
-        {
-            'name': 'bus',
-            'srcs': [ 'bus/main.c', 'bus/common.c' ],
-            'link': [ libdbus_testutils, libdbus_daemon_internal, ],
-            'install': false,
-        },
-        {
-            'name': 'bus-dispatch-sha1',
-            'srcs': [ 'bus/dispatch-sha1.c', 'bus/common.c' ],
-            'link': [ libdbus_testutils, libdbus_daemon_internal, ],
-            'install': false,
-            'suite': ['slow'],
-        },
         {
             'name': 'marshal-recursive',
             'srcs': [
@@ -270,6 +267,24 @@ if embedded_tests
         },
     ]
 
+    if message_bus
+       tests += [
+           {
+               'name': 'bus',
+               'srcs': [ 'bus/main.c', 'bus/common.c' ],
+               'link': [ libdbus_testutils, libdbus_daemon_internal, ],
+               'install': false,
+           },
+           {
+               'name': 'bus-dispatch-sha1',
+               'srcs': [ 'bus/dispatch-sha1.c', 'bus/common.c' ],
+               'link': [ libdbus_testutils, libdbus_daemon_internal, ],
+               'install': false,
+               'suite': ['slow'],
+           },
+       ]
+    endif
+
     if use_traditional_activation
         tests += [
             {
@@ -575,6 +590,10 @@ foreach test: tests
     suites = test.get('suite', ['dbus'])
     install = test.get('install', true)
 
+    if suites.contains('runs-dbus-daemon') and not (message_bus and tools)
+        continue
+    endif
+
     if test.get('test', true)
         exe_name = 'test-' + name
     else
@@ -626,7 +645,7 @@ endforeach
 
 scripts = []
 
-if platform_unix and use_glib
+if message_bus and tools and platform_unix and use_glib
     scripts += [
         {   'name': 'test-dbus-daemon-fork.sh', },
         {   'name': 'transient-services.sh',
index 4c3d9d2289e4de57053840684c3b56751fafbe04..5d78d93a0fd69f99535581f4c7ba8192e59c36ca 100644 (file)
@@ -39,14 +39,15 @@ else
     ]
 endif
 
-dbus_launch = executable('dbus-launch',
-    dbus_launch_sources,
-    include_directories: root_include,
-    link_with: libdbus,
-    dependencies: [ x11, ],
-    install: true,
-)
-
+if message_bus
+    dbus_launch = executable('dbus-launch',
+        dbus_launch_sources,
+        include_directories: root_include,
+        link_with: libdbus,
+        dependencies: [ x11, ],
+        install: true,
+    )
+endif
 
 dbus_monitor = executable('dbus-monitor',
     'dbus-print-message.c',
@@ -57,13 +58,15 @@ dbus_monitor = executable('dbus-monitor',
     install: true,
 )
 
-dbus_run_session = executable('dbus-run-session',
-    'dbus-run-session.c',
-    'tool-common.c',
-    include_directories: root_include,
-    link_with: libdbus_internal,
-    install: true,
-)
+if message_bus
+    dbus_run_session = executable('dbus-run-session',
+        'dbus-run-session.c',
+        'tool-common.c',
+        include_directories: root_include,
+        link_with: libdbus_internal,
+        install: true,
+    )
+endif
 
 dbus_send = executable('dbus-send',
     'dbus-print-message.c',