xref: /aosp_15_r20/prebuilts/build-tools/common/py3-stdlib/ctypes/macholib/framework.py (revision cda5da8d549138a6648c5ee6d7a49cf8f4a657be)
1"""
2Generic framework path manipulation
3"""
4
5import re
6
7__all__ = ['framework_info']
8
9STRICT_FRAMEWORK_RE = re.compile(r"""(?x)
10(?P<location>^.*)(?:^|/)
11(?P<name>
12    (?P<shortname>\w+).framework/
13    (?:Versions/(?P<version>[^/]+)/)?
14    (?P=shortname)
15    (?:_(?P<suffix>[^_]+))?
16)$
17""")
18
19def framework_info(filename):
20    """
21    A framework name can take one of the following four forms:
22        Location/Name.framework/Versions/SomeVersion/Name_Suffix
23        Location/Name.framework/Versions/SomeVersion/Name
24        Location/Name.framework/Name_Suffix
25        Location/Name.framework/Name
26
27    returns None if not found, or a mapping equivalent to:
28        dict(
29            location='Location',
30            name='Name.framework/Versions/SomeVersion/Name_Suffix',
31            shortname='Name',
32            version='SomeVersion',
33            suffix='Suffix',
34        )
35
36    Note that SomeVersion and Suffix are optional and may be None
37    if not present
38    """
39    is_framework = STRICT_FRAMEWORK_RE.match(filename)
40    if not is_framework:
41        return None
42    return is_framework.groupdict()
43