-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_subproject_symlink.py
More file actions
57 lines (48 loc) · 1.48 KB
/
create_subproject_symlink.py
File metadata and controls
57 lines (48 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# noqa: INP001
# ozi/scripts/create_subproject_symlink.py
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.9"
# dependencies = [
# 'pathvalidate~=3.2',
# ]
# ///
""":pep:`723` script: create symbolic link to subproject
Side-effects
^^^^^^^^^^^^
* Create symbolic link :file:`{MESON_BUILD_ROOT}/subprojects/ozi` to the
versioned OZI wrap directory.
Environment Variables
^^^^^^^^^^^^^^^^^^^^^
* :envvar:`MESON_BUILD_ROOT`
"""
import os
import pathlib
import sys
from contextlib import suppress
from glob import glob
from pathvalidate import validate_filepath
if __name__ == '__main__':
build_root = os.environ.get('MESON_BUILD_ROOT', '..')
source = pathlib.Path(build_root).resolve()
validate_filepath(source, platform='auto')
current_dir = os.getcwd()
# chdir to the resolved absolute path
os.chdir(source)
try:
matches = glob('subprojects/OZI-*')
if not matches:
raise IndexError
target = pathlib.Path('..', matches[0])
link_path = pathlib.Path('subprojects/ozi')
with suppress(FileExistsError):
link_path.symlink_to(
target,
target_is_directory=True,
)
except IndexError:
sys.exit(print('OZI subproject directory not found', file=sys.stderr))
finally:
os.chdir(current_dir)