diff options
author | Simon McVittie <smcv@collabora.com> | 2022-06-27 15:12:54 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2022-07-13 20:36:13 +0100 |
commit | e2f2c5dd42e193d4bddb0bda49b07bf254cff248 (patch) | |
tree | 57901dda3003f9496e9e9c7dfd98fba19dca89d9 | |
parent | abef7950816d423b3b65fcf36bfa0cf0e36c4ebf (diff) | |
download | dbus-e2f2c5dd42e193d4bddb0bda49b07bf254cff248.tar.gz |
build: Change how we create symlinks from Meson
Use install_symlink() in Meson versions that support it, or a script
with similar invocation in versions that do not. This will make it
straightforward to migrate to install_symlink() when we drop support
for Meson versions older than 0.61.0.
Based on an implementation in the game-data-packager package, which used
a shell script.
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | bus/meson.build | 25 | ||||
-rw-r--r-- | meson.build | 34 | ||||
-rw-r--r-- | meson_post_install_systemd.py | 55 | ||||
-rw-r--r-- | tools/Makefile.am | 1 | ||||
-rwxr-xr-x | tools/meson-compat-install-symlink.py | 22 |
6 files changed, 75 insertions, 63 deletions
diff --git a/Makefile.am b/Makefile.am index f37865e8..6fb53c9a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,6 @@ EXTRA_DIST = \ meson.build \ meson_options.txt \ meson_post_install.py \ - meson_post_install_systemd.py \ subprojects/expat.wrap \ subprojects/glib.wrap \ test/CMakeLists.txt \ diff --git a/bus/meson.build b/bus/meson.build index 7d09e738..06e293b8 100644 --- a/bus/meson.build +++ b/bus/meson.build @@ -183,3 +183,28 @@ if platform_unix and use_traditional_activation install_dir: get_option('libexecdir'), ) endif + +if use_systemd + install_symlinks += [ + { + 'link_name': 'dbus.service', + 'install_dir': systemd_system_unitdir / 'multi-user.target.wants', + 'pointing_to': '../dbus.service', + }, + { + 'link_name': 'dbus.socket', + 'install_dir': systemd_system_unitdir / 'sockets.target.wants', + 'pointing_to': '../dbus.socket', + }, + ] +endif + +if use_systemd and get_option('user_session') + install_symlinks += [ + { + 'link_name': 'dbus.socket', + 'install_dir': systemd_user_unitdir / 'sockets.target.wants', + 'pointing_to': '../dbus.socket', + }, + ] +endif diff --git a/meson.build b/meson.build index 937f6438..edd20dfa 100644 --- a/meson.build +++ b/meson.build @@ -42,6 +42,8 @@ data_config = configuration_data() compile_args = [] link_args = [] +install_symlinks = [] + ############################################################################### # Project configuration @@ -983,13 +985,6 @@ meson.add_install_script('meson_post_install.py', '@0@'.format(use_systemd), ) -if use_systemd - meson.add_install_script('meson_post_install_systemd.py', - systemd_system_unitdir, - systemd_user_unitdir, - ) -endif - pkgconfig.generate( libdbus, name: 'dbus', @@ -1016,6 +1011,31 @@ pkgconfig.generate( } ) +foreach symlink : install_symlinks + if not platform_unix + warning( + 'Not creating symbolic link @0@/@1@ -> @2@'.format( + symlink['install_dir'], + symlink['link_name'], + symlink['pointing_to'], + ) + ) + elif meson.version().version_compare('>=0.61.0') + install_symlink( + symlink['link_name'], + install_dir : symlink['install_dir'], + pointing_to : symlink['pointing_to'], + ) + else + meson.add_install_script( + 'tools/meson-compat-install-symlink.py', + symlink['link_name'], + symlink['install_dir'], + symlink['pointing_to'], + ) + endif +endforeach + summary_dict = { 'prefix': get_option('prefix'), 'exec_prefix': get_option('prefix'), diff --git a/meson_post_install_systemd.py b/meson_post_install_systemd.py deleted file mode 100644 index 9530e271..00000000 --- a/meson_post_install_systemd.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python3 -# Copyright © 2019-2020 Salamandar <felix@piedallu.me> -# SPDX-License-Identifier: MIT -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -from meson_post_install import * - -import os, sys - -############################################################################### - -systemd_system_dir = to_destdir(sys.argv[1]) -systemd_user_dir = to_destdir(sys.argv[2]) - -def force_symlink(src, dst): - try: - os.unlink(dst) - except OSError: - pass - os.symlink(src, dst) - -def post_install_data(): - # Install dbus.socket as default implementation of a D-Bus stack. - # Unconditionally enable D-Bus on systemd installations - # - # TODO meson >=0.61 has install_symlink() - - (systemd_system_dir / 'sockets.target.wants') .mkdir(parents=True, exist_ok=True) - (systemd_system_dir / 'multi-user.target.wants').mkdir(parents=True, exist_ok=True) - force_symlink('../dbus.socket', systemd_system_dir / 'sockets.target.wants' / 'dbus.socket') - force_symlink('../dbus.service', systemd_system_dir / 'multi-user.target.wants' / 'dbus.service') - - if get_option('user_session'): - (systemd_user_dir / 'sockets.target.wants') .mkdir(parents=True, exist_ok=True) - force_symlink('../dbus.socket',systemd_user_dir / 'sockets.target.wants' / 'dbus.socket') - -if __name__ == "__main__": - post_install_data() diff --git a/tools/Makefile.am b/tools/Makefile.am index 2a5f7df3..e9c066ba 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -154,3 +154,4 @@ installcheck-local: EXTRA_DIST += build-timestamp.py EXTRA_DIST += meson.build +EXTRA_DIST += meson-compat-install-symlink.py diff --git a/tools/meson-compat-install-symlink.py b/tools/meson-compat-install-symlink.py new file mode 100755 index 00000000..6e7ac333 --- /dev/null +++ b/tools/meson-compat-install-symlink.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +# Copyright 2022 Simon McVittie +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +# Compatibility shim for installing symlinks with Meson < 0.61 + +import os +import sys +from pathlib import Path + +link_name, d, pointing_to = sys.argv[1:] + +if os.path.isabs(d): + p = Path(d) + d = p.relative_to(p.anchor) + dest = os.path.join(os.environ['DESTDIR'], d) +else: + dest = os.path.join(os.environ['MESON_INSTALL_DESTDIR_PREFIX'], d) + +os.makedirs(dest, mode=0o755, exist_ok=True) +os.symlink(pointing_to, os.path.join(dest, link_name)) |