Akihiko Odaki | cf60ccc | 2022-06-24 23:50:37 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | from pathlib import PurePath |
| 4 | import errno |
| 5 | import json |
| 6 | import os |
| 7 | import subprocess |
| 8 | import sys |
| 9 | |
| 10 | def destdir_join(d1: str, d2: str) -> str: |
| 11 | if not d1: |
| 12 | return d2 |
| 13 | # c:\destdir + c:\prefix must produce c:\destdir\prefix |
| 14 | return str(PurePath(d1, *PurePath(d2).parts[1:])) |
| 15 | |
| 16 | introspect = os.environ.get('MESONINTROSPECT') |
| 17 | out = subprocess.run([*introspect.split(' '), '--installed'], |
| 18 | stdout=subprocess.PIPE, check=True).stdout |
| 19 | for source, dest in json.loads(out).items(): |
Akihiko Odaki | cf60ccc | 2022-06-24 23:50:37 +0900 | [diff] [blame] | 20 | bundle_dest = destdir_join('qemu-bundle', dest) |
| 21 | path = os.path.dirname(bundle_dest) |
| 22 | try: |
| 23 | os.makedirs(path, exist_ok=True) |
| 24 | except BaseException as e: |
| 25 | print(f'error making directory {path}', file=sys.stderr) |
| 26 | raise e |
| 27 | try: |
| 28 | os.symlink(source, bundle_dest) |
| 29 | except BaseException as e: |
| 30 | if not isinstance(e, OSError) or e.errno != errno.EEXIST: |
Mateusz Krawczuk | 1f8da02 | 2023-05-04 23:11:01 +0200 | [diff] [blame^] | 31 | if os.name == 'nt': |
| 32 | print('Please enable Developer Mode to support soft link ' |
| 33 | 'without Administrator permission') |
Akihiko Odaki | cf60ccc | 2022-06-24 23:50:37 +0900 | [diff] [blame] | 34 | print(f'error making symbolic link {dest}', file=sys.stderr) |
| 35 | raise e |