build: Port meson-make-symlink script to Python

Instead of using non-portable features of GNU ln command, such as -T
and --relative, use Python os.path.relpath function to handle it. This
fixes installation failure on FreeBSD.
This commit is contained in:
Ting-Wei Lan 2019-12-02 22:33:59 +08:00
parent aaa141f28b
commit 8b7d4e46de
3 changed files with 36 additions and 13 deletions

View File

@ -13,7 +13,7 @@ gnome = import('gnome')
i18n = import('i18n')
pkgconfig = import('pkgconfig')
meson_make_symlink = join_paths(meson.source_root(), 'tools', 'meson-make-symlink.sh')
meson_make_symlink = join_paths(meson.source_root(), 'tools', 'meson-make-symlink.py')
po_dir = join_paths(meson.source_root(), 'po')
prefix = get_option('prefix')

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
import os
import sys
destdir = os.environ.get('DESTDIR')
source = sys.argv[1]
target = sys.argv[2]
def prepend_destdir(path):
if destdir is not None:
if os.path.isabs(path):
return os.path.join(destdir, path[1:])
else:
return os.path.join(destdir, path)
else:
return path
def call_symlink(src, dst):
try:
os.remove(dst)
except:
pass
os.symlink(src, dst)
os.makedirs(os.path.dirname(prepend_destdir(target)), exist_ok=True)
if os.path.dirname(source) == '.':
destdir_target = prepend_destdir(target)
call_symlink(source, destdir_target)
else:
destdir_source = prepend_destdir(source)
destdir_target = prepend_destdir(target)
destdir_target_dir = os.path.dirname(destdir_target)
relative_source = os.path.relpath(destdir_source, destdir_target_dir)
call_symlink(relative_source, destdir_target)

View File

@ -1,12 +0,0 @@
#!/bin/sh
set -eu
# this is needed mostly because $DESTDIR is provided as a variable,
# and we need to create the target directory...
mkdir -vp "$(dirname "${DESTDIR:-}$2")"
if [ "$(dirname $1)" = . ]; then
ln -vfs -T "$1" "${DESTDIR:-}$2"
else
ln -vfs -T --relative "${DESTDIR:-}$1" "${DESTDIR:-}$2"
fi