]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
build: Change how we create symlinks from Meson
authorSimon McVittie <smcv@collabora.com>
Mon, 27 Jun 2022 14:12:54 +0000 (15:12 +0100)
committerSimon McVittie <smcv@collabora.com>
Wed, 13 Jul 2022 19:36:13 +0000 (20:36 +0100)
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>
Makefile.am
bus/meson.build
meson.build
meson_post_install_systemd.py [deleted file]
tools/Makefile.am
tools/meson-compat-install-symlink.py [new file with mode: 0755]

index f37865e87797961d98a6f70d8080a814595a9b06..6fb53c9afaf4e8f3f674b78e10cc34c3af01bd53 100644 (file)
@@ -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 \
index 7d09e7381509115ffe38cdcb821e3c12bbc6e074..06e293b84ebb801d2e81fba7b286e4398c4a3cff 100644 (file)
@@ -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
index 937f64381982c905630496158e10a1aeb7732dc3..edd20dfa8cde487a0f0753d40ac47a62f22e8c08 100644 (file)
@@ -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 (file)
index 9530e27..0000000
+++ /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()
index 2a5f7df37dbd6ceca7a4ee445e95b57e4eed28de..e9c066badda615e07c15f89f516bb502372ec416 100644 (file)
@@ -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 (executable)
index 0000000..6e7ac33
--- /dev/null
@@ -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))