Merge branch 'wip/lantw/build-Port-meson-make-symlink-script-to-Python' into 'master'

build: Port meson-make-symlink script to Python

See merge request pwithnall/malcontent!18
This commit is contained in:
Philip Withnall 2019-12-03 11:55:00 +00:00
commit c3fdc05d62
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