diff options
author | Simon McVittie <smcv@collabora.com> | 2022-09-05 09:21:38 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2022-09-05 17:35:57 +0100 |
commit | fdab4745424c7477e5257a4fc0fff4e14ef664ef (patch) | |
tree | 72964414a4d8a49b4456d5f0962ba6925d988543 | |
parent | 29ac041beba6fc299fd4b5434af2382c2473e456 (diff) | |
download | dbus-python-fdab4745424c7477e5257a4fc0fff4e14ef664ef.tar.gz |
Add a Meson build system
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | Makefile.am | 9 | ||||
-rw-r--r-- | doc/maintainer-update-website.sh | 12 | ||||
-rw-r--r-- | doc/meson.build | 56 | ||||
-rw-r--r-- | meson.build | 224 | ||||
-rw-r--r-- | meson_options.txt | 30 | ||||
-rw-r--r-- | test/compiled.test.in | 3 | ||||
-rw-r--r-- | test/installable/meson.build | 25 | ||||
-rw-r--r-- | test/meson.build | 191 | ||||
-rw-r--r-- | test/py.test.in | 3 | ||||
-rw-r--r-- | test/sh.test.in | 3 |
10 files changed, 556 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index d7e5975..3b00991 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,6 +25,8 @@ EXTRA_DIST = \ LICENSES/MIT.txt \ dbus-python.pc.in \ doc/_static/.gitignore \ + doc/maintainer-update-website.sh \ + doc/meson.build \ examples/example-async-client.py \ examples/example-client.py \ examples/example-service.py \ @@ -35,8 +37,15 @@ EXTRA_DIST = \ examples/list-system-services.py \ examples/unix-fd-client.py \ examples/unix-fd-service.py \ + meson.build \ + meson_options.txt \ setup.py \ test/TestSuitePythonService.service.in \ + test/compiled.test.in \ + test/installable/meson.build \ + test/meson.build \ + test/py.test.in \ + test/sh.test.in \ test/tmp-session-bus.conf.in \ tools/check-c-style.sh \ tools/check-coding-style.mk \ diff --git a/doc/maintainer-update-website.sh b/doc/maintainer-update-website.sh new file mode 100644 index 0000000..ce4f155 --- /dev/null +++ b/doc/maintainer-update-website.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +me="$(readlink -f "$0")" +here="$(dirname "$me")" +top="$(dirname "$here")" + +DBUS_TOP_SRCDIR="$top" python3 "$here/redirects.py" +rsync -rtvzPp --chmod=Dg+s,ug+rwX,o=rX \ + doc/_build/ \ + "${DOC_RSYNC_DEST-dbus.freedesktop.org:/srv/dbus.freedesktop.org/www/doc/dbus-python}/" diff --git a/doc/meson.build b/doc/meson.build new file mode 100644 index 0000000..e7bdd91 --- /dev/null +++ b/doc/meson.build @@ -0,0 +1,56 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +doc_sources = files( + 'API_CHANGES.txt', + 'conf.py', + 'dbus.bus.rst', + 'dbus.connection.rst', + 'dbus.decorators.rst', + 'dbus.exceptions.rst', + 'dbus.gi_service.rst', + 'dbus.glib.rst', + 'dbus.gobject_service.rst', + 'dbus.lowlevel.rst', + 'dbus.mainloop.rst', + 'dbus.proxies.rst', + 'dbus.rst', + 'dbus.server.rst', + 'dbus.service.rst', + 'dbus.types.rst', + 'index.rst', + 'news.rst', + 'PY3PORT.txt', + 'tutorial.txt', + ) + +sphinx = custom_target( + 'sphinx', + command: [ + py.full_path(), + '-m', 'sphinx', + '-b', 'html', + meson.current_source_dir(), + '@OUTPUT@', + ], + depends: [ + dbus_bindings, + dbus_glib_bindings, + ], + input: python_sources + doc_sources, + output: 'html', + build_by_default: true, + install: true, + install_dir: get_option('datadir') / 'doc' / meson.project_name(), +) + +custom_target( + 'maintainer-update-website', + command: [ + 'env', + '--chdir', '@BUILD_ROOT@', + files('maintainer-update-website.sh'), + ], + depends: [sphinx], + output: '_uploaded', +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..727c085 --- /dev/null +++ b/meson.build @@ -0,0 +1,224 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +project( + 'dbus-python', + 'c', + default_options: [ + 'warning_level=2', + ], + meson_version: '>=0.56', + version: '1.2.19', +) + +pc_mod = import('pkgconfig') +py_mod = import('python') + +project_include_directories = include_directories('include') + +cc = meson.get_compiler('c') +compile_warnings = [] +compile_warnings_c = [] + +if cc.get_id() != 'msvc' + # -fno-common makes the linker more strict: on some systems the linker + # is *always* this strict, so we want to behave like that everywhere. + # We treat this like a warning, since that's basically how we're using it. + compile_warnings += ['-fno-common'] + + compile_warnings += [ + # Intentionally disabled: missing field initializers being implicitly + # default-initialized is a feature, not a bug + '-Wno-missing-field-initializers', + + # Unfortunately the Python headers trigger various warnings + '-Wno-declaration-after-statement', + '-Wno-inline', + '-Wno-redundant-decls', + '-Wno-switch-default', + '-Wno-write-strings', + + # General warnings for both C and C++, excluding those that are part + # of -Wall or -Wextra + '-Wcast-align', + '-Wdouble-promotion', + '-Wduplicated-cond', + '-Wfloat-equal', + '-Wformat-nonliteral', + '-Wformat-security', + '-Wformat=2', + '-Winit-self', + '-Wlogical-op', + '-Wmissing-declarations', + '-Wmissing-format-attribute', + '-Wmissing-include-dirs', + '-Wmissing-noreturn', + '-Wnull-dereference', + '-Wpacked', + '-Wpointer-arith', + '-Wshadow', + '-Wswitch-enum', + '-Wundef', + '-Wunused-but-set-variable', + ] + + compile_warnings_c += [ + # Extra warnings just for C + '-Wjump-misses-init', + '-Wmissing-prototypes', + '-Wnested-externs', + '-Wold-style-definition', + '-Wpointer-sign', + '-Wstrict-prototypes', + ] +endif + +compile_warnings_c = cc.get_supported_arguments(compile_warnings + compile_warnings_c) +add_project_arguments(compile_warnings_c, language: 'c') + +conf_data = configuration_data() +conf_data.set_quoted('PACKAGE_VERSION', meson.project_version()) +configure_file( + output : '_dbus-python-config.h', + configuration: conf_data, +) +add_project_arguments(['-include', '_dbus-python-config.h'], language: 'c') + +# Bring dbus-gmain into our namespace +redefine_dgmain_name = '_dbus_py_glib_ ## name' + +add_project_arguments( + '-DDBUS_GMAIN_FUNCTION_NAME(name)=' + redefine_dgmain_name, + language: 'c', +) + +dbus_gmain = subproject( + 'dbus-gmain', + default_options: [ + 'redefine_function_name=' + redefine_dgmain_name, + 'tests=false', + ], +) +dbus_gmain_dep = dbus_gmain.get_variable('dbus_gmain_dep') + +if get_option('python') == '' + # This uses the same Python that was used to run Meson + py = py_mod.find_installation() +else + py = py_mod.find_installation(get_option('python')) +endif + +dbus_dep = dependency('dbus-1', version: '>=1.8') + +python_sources = files( + 'dbus/bus.py', + 'dbus/connection.py', + 'dbus/_compat.py', + 'dbus/_dbus.py', + 'dbus/decorators.py', + 'dbus/exceptions.py', + 'dbus/_expat_introspect_parser.py', + 'dbus/gi_service.py', + 'dbus/glib.py', + 'dbus/__init__.py', + 'dbus/lowlevel.py', + 'dbus/proxies.py', + 'dbus/server.py', + 'dbus/service.py', + 'dbus/types.py', +) +mainloop_sources = files( + 'dbus/mainloop/__init__.py', + 'dbus/mainloop/glib.py', +) + +py.install_sources( + python_sources, + subdir: 'dbus', + pure: false, +) +py.install_sources( + mainloop_sources, + subdir: 'dbus/mainloop', + pure: false, +) + +dbus_bindings = py.extension_module( + '_dbus_bindings', + sources: [ + 'dbus_bindings/abstract.c', + 'dbus_bindings/bus.c', + 'dbus_bindings/bytes.c', + 'dbus_bindings/conn.c', + 'dbus_bindings/conn-methods.c', + 'dbus_bindings/containers.c', + 'dbus_bindings/debug.c', + 'dbus_bindings/exceptions.c', + 'dbus_bindings/float.c', + 'dbus_bindings/generic.c', + 'dbus_bindings/int.c', + 'dbus_bindings/unixfd.c', + 'dbus_bindings/libdbusconn.c', + 'dbus_bindings/mainloop.c', + 'dbus_bindings/message-append.c', + 'dbus_bindings/message.c', + 'dbus_bindings/message-get-args.c', + 'dbus_bindings/module.c', + 'dbus_bindings/pending-call.c', + 'dbus_bindings/server.c', + 'dbus_bindings/signature.c', + 'dbus_bindings/string.c', + 'dbus_bindings/validation.c', + ], + dependencies: [ + dbus_dep, + py.dependency(), + ], + include_directories: project_include_directories, + install: true, + # Workaround for https://github.com/mesonbuild/meson/issues/6331 + # TODO: Remove this when we depend on Meson 0.60 + subdir: '', +) + +dbus_glib_bindings = py.extension_module( + '_dbus_glib_bindings', + sources: [ + 'dbus_glib_bindings/module.c', + ], + dependencies: [ + dbus_dep, + dbus_gmain_dep, + py.dependency(), + ], + include_directories: project_include_directories, + install: true, + # Workaround for https://github.com/mesonbuild/meson/issues/6331 + # TODO: Remove this when we depend on Meson 0.60 + subdir: '', +) + +install_headers( + 'include/dbus/dbus-python.h', + subdir: 'dbus-1.0/dbus', +) + +pc_mod.generate( + description: 'Python bindings for D-Bus', + filebase: 'dbus-python', + name: 'dbus-python', + requires: ['dbus-1 >= 1.8'], + subdirs: ['dbus-1.0'], + variables: { + 'exec_prefix': '${prefix}', + 'datarootdir': '${prefix}' / get_option('datadir'), + }, +) + +if get_option('doc') + subdir('doc') +endif + +if get_option('tests') + subdir('test') +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..7dc5218 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,30 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +option( + 'doc', + type: 'boolean', + value: false, + description: 'Enable documentation', +) + +option( + 'installed_tests', + type: 'boolean', + value: false, + description: 'Enable "as-installed" testing', +) + +option( + 'python', + type: 'string', + value: '', + description: 'Override the Python interpreter to use', +) + +option( + 'tests', + type: 'boolean', + value: true, + description: 'Enable unit tests', +) diff --git a/test/compiled.test.in b/test/compiled.test.in new file mode 100644 index 0000000..66bf7af --- /dev/null +++ b/test/compiled.test.in @@ -0,0 +1,3 @@ +[Test] +Type=session +Exec=@wrapper@ @program@ diff --git a/test/installable/meson.build b/test/installable/meson.build new file mode 100644 index 0000000..9b21425 --- /dev/null +++ b/test/installable/meson.build @@ -0,0 +1,25 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +installed_test_config = { + 'PYTHON': py.full_path(), + 'G_TEST_SRCDIR': get_option('prefix') / installed_testdir, + 'G_TEST_BUILDDIR': get_option('prefix') / installed_testdir, + 'configure_input': 'Generated by build system, do not edit', +} + +configure_file( + input: '../TestSuitePythonService.service.in', + output: 'TestSuitePythonService.service', + configuration: installed_test_config, + install: true, + install_dir: installed_test_testdir, +) + +configure_file( + input: '../tmp-session-bus.conf.in', + output: 'tmp-session-bus.conf', + configuration: installed_test_config, + install: true, + install_dir: installed_test_testdir, +) diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..3539f8d --- /dev/null +++ b/test/meson.build @@ -0,0 +1,191 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +installed_testdir = get_option('libexecdir') / 'installed-tests' / meson.project_name() +installed_test_testdir = installed_testdir / 'test' +installed_test_metadir = get_option('datadir') / 'installed-tests' / meson.project_name() +test_env = environment() +test_env.set('DBUS_TOP_SRCDIR', meson.project_source_root()) +test_env.set('DBUS_TOP_BUILDDIR', meson.project_build_root()) +test_env.set('DBUS_TEST_TMPDIR', meson.project_build_root() / 'test') +test_env.set('DBUS_TEST_UNINSTALLED', '1') +test_env.set('DBUS_PYTHON_VERSION', meson.project_version()) +test_env.set('PYTHON', py.full_path()) +test_env.set('DBUS_FATAL_WARNINGS', '1') +test_env.set( + 'PYTHONPATH', + ':'.join([ + meson.project_source_root(), + meson.project_source_root() / 'test', + meson.project_build_root(), + meson.project_build_root() / 'test', + ]) +) + +dbus_py_test = py.extension_module( + 'dbus_py_test', + sources: [ + 'dbus_py_test.c', + ], + dependencies: [ + dbus_dep, + py.dependency(), + ], + include_directories: project_include_directories, + install: get_option('installed_tests'), + install_dir: installed_test_testdir, +) + +build_time_test_config = { + 'PYTHON': py.full_path(), + 'G_TEST_SRCDIR': meson.project_source_root(), + 'G_TEST_BUILDDIR': meson.project_build_root(), + 'configure_input': 'Generated by build system, do not edit', +} + +configure_file( + input: 'TestSuitePythonService.service.in', + output: 'TestSuitePythonService.service', + configuration: build_time_test_config, +) + +tmp_session_bus_conf = configure_file( + input: 'tmp-session-bus.conf.in', + output: 'tmp-session-bus.conf', + configuration: build_time_test_config, +) + +if get_option('installed_tests') + subdir('installable') + + install_data( + 'cross-test-client.py', + 'cross-test-server.py', + 'crosstest.py', + 'dbus_test_utils.py', + 'test-service.py', + 'wait-for-name.py', + install_dir: installed_test_testdir, + ) +endif + +dbus_run_session = find_program('dbus-run-session', required: true) + +build_time_dbus_run_session_args = [ + '--config-file=@0@'.format(tmp_session_bus_conf), + '--', +] + +installed_wrapper = [ + dbus_run_session.full_path(), + '--config-file=@0@'.format( + get_option('prefix') / installed_test_testdir / 'tmp-session-bus.conf' + ), + '--', + 'env', + 'PYTHON=' + py.full_path(), + 'DBUS_TOP_SRCDIR=' + (get_option('prefix') / installed_testdir), + 'DBUS_TOP_BUILDDIR=' + (get_option('prefix') / installed_testdir), +] + +compiled_test_cases = ['import-repeatedly'] + +foreach test_case : compiled_test_cases + exe = executable( + 'test-' + test_case, + test_case + '.c', + dependencies: [ + py.dependency(embed: true), + ], + install: get_option('installed_tests'), + install_dir: installed_test_testdir, + ) + test( + test_case, + dbus_run_session, + args: build_time_dbus_run_session_args + [exe], + env: test_env, + ) + + if get_option('installed_tests') + configure_file( + input: 'compiled.test.in', + output: 'test-' + test_case + '.test', + configuration: { + 'wrapper': ' '.join(installed_wrapper), + 'program': get_option('prefix') / installed_test_testdir / 'test-' + test_case, + }, + install: true, + install_dir: installed_test_metadir, + ) + endif +endforeach + +py_test_cases = [ + 'client', + 'exception-py3', + 'p2p', + 'signals', + 'standalone', + 'unusable-main-loop', +] +install_test_sources = [] + +foreach test_case : py_test_cases + install_test_sources += ['test-@0@.py'.format(test_case)] + test( + test_case, + dbus_run_session, + args: build_time_dbus_run_session_args + [ + py.full_path(), + files('test-' + test_case + '.py'), + ], + env: test_env, + ) + + if get_option('installed_tests') + configure_file( + input: 'py.test.in', + output: 'test-' + test_case + '.py.test', + configuration: { + 'wrapper': ' '.join(installed_wrapper), + 'python': py.full_path(), + 'program': get_option('prefix') / installed_test_testdir / 'test-' + test_case + '.py', + }, + install: true, + install_dir: installed_test_metadir, + ) + endif +endforeach + +sh_test_cases = ['run-test'] + +foreach test_case : sh_test_cases + install_test_sources += ['@0@.sh'.format(test_case)] + test( + test_case + '.sh', + dbus_run_session, + args: build_time_dbus_run_session_args + [files(test_case + '.sh')], + env: test_env, + ) + + if get_option('installed_tests') + configure_file( + input: 'sh.test.in', + output: test_case + '.sh.test', + configuration: { + 'wrapper': ' '.join(installed_wrapper), + 'program': get_option('prefix') / installed_test_testdir / test_case + '.sh', + }, + install: true, + install_dir: installed_test_metadir, + ) + endif +endforeach + +if get_option('installed_tests') + install_data( + install_test_sources, + install_dir: installed_test_testdir, + ) +endif diff --git a/test/py.test.in b/test/py.test.in new file mode 100644 index 0000000..b73c083 --- /dev/null +++ b/test/py.test.in @@ -0,0 +1,3 @@ +[Test] +Type=session +Exec=@wrapper@ @python@ @program@ diff --git a/test/sh.test.in b/test/sh.test.in new file mode 100644 index 0000000..66bf7af --- /dev/null +++ b/test/sh.test.in @@ -0,0 +1,3 @@ +[Test] +Type=session +Exec=@wrapper@ @program@ |