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>
This commit is contained in:
Simon McVittie 2022-06-27 15:12:54 +01:00
parent abef795081
commit e2f2c5dd42
6 changed files with 75 additions and 63 deletions

View 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 \

View 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

View 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'),

View file

@ -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()

View file

@ -154,3 +154,4 @@ installcheck-local:
EXTRA_DIST += build-timestamp.py
EXTRA_DIST += meson.build
EXTRA_DIST += meson-compat-install-symlink.py

View file

@ -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))