2020-07-31 09:26:11 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import argparse
|
2021-01-30 01:17:38 +01:00
|
|
|
import platform
|
2022-09-13 14:51:36 +02:00
|
|
|
from pathlib import PurePath
|
2020-07-31 09:26:11 +02:00
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('availpath')
|
|
|
|
parser.add_argument('confpath')
|
|
|
|
parser.add_argument('links', nargs='+')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-12-03 21:04:26 +01:00
|
|
|
if os.path.isabs(args.confpath):
|
|
|
|
destdir = os.environ.get('DESTDIR')
|
|
|
|
if destdir:
|
2022-09-13 14:51:36 +02:00
|
|
|
# c:\destdir + c:\prefix must produce c:\destdir\prefix
|
|
|
|
confpath = str(PurePath(destdir, *PurePath(args.confpath).parts[1:]))
|
2020-12-03 21:04:26 +01:00
|
|
|
else:
|
|
|
|
confpath = args.confpath
|
|
|
|
else:
|
|
|
|
confpath = os.path.join(os.environ['MESON_INSTALL_DESTDIR_PREFIX'], args.confpath)
|
2020-07-31 09:26:11 +02:00
|
|
|
|
|
|
|
if not os.path.exists(confpath):
|
|
|
|
os.makedirs(confpath)
|
|
|
|
|
|
|
|
for link in args.links:
|
|
|
|
src = os.path.join(args.availpath, link)
|
|
|
|
dst = os.path.join(confpath, link)
|
2021-03-02 11:29:08 +01:00
|
|
|
try:
|
|
|
|
os.remove(dst)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2020-07-31 09:26:11 +02:00
|
|
|
try:
|
|
|
|
os.symlink(src, dst)
|
|
|
|
except NotImplementedError:
|
|
|
|
# Not supported on this version of Windows
|
|
|
|
break
|
|
|
|
except OSError as e:
|
|
|
|
# Symlink privileges are not available
|
2021-01-30 01:17:38 +01:00
|
|
|
if platform.system().lower() == 'windows' and e.winerror == 1314:
|
2020-07-31 09:26:11 +02:00
|
|
|
break
|
|
|
|
raise
|