File: get_relative_lib_dir.py

package info (click to toggle)
llvm-toolchain-4.0 1%3A4.0.1-10~deb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 493,332 kB
  • sloc: cpp: 2,698,100; ansic: 552,773; asm: 128,821; python: 121,589; objc: 105,054; sh: 21,174; lisp: 6,758; ml: 5,532; perl: 5,311; pascal: 5,245; makefile: 2,083; cs: 1,868; xml: 686; php: 212; csh: 117
file content (44 lines) | stat: -rw-r--r-- 1,433 bytes parent folder | download | duplicates (9)
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
import distutils.sysconfig
import os
import platform
import re
import sys


def get_python_relative_libdir():
    """Returns the appropropriate python libdir relative to the build directory.

    @param exe_path the path to the lldb executable

    @return the python path that needs to be added to sys.path (PYTHONPATH)
    in order to find the lldb python module.
    """
    if platform.system() != 'Linux':
        return None

    # We currently have a bug in lldb -P that does not account for
    # architecture variants in python paths for
    # architecture-specific modules.  Handle the lookup here.
    # When that bug is fixed, we should just ask lldb for the
    # right answer always.
    arch_specific_libdir = distutils.sysconfig.get_python_lib(True, False)
    split_libdir = arch_specific_libdir.split(os.sep)
    lib_re = re.compile(r"^lib.+$")

    for i in range(len(split_libdir)):
        match = lib_re.match(split_libdir[i])
        if match is not None:
            # We'll call this the relative root of the lib dir.
            # Things like RHEL will have an arch-specific python
            # lib dir, which isn't 'lib' on x86_64.
            return os.sep.join(split_libdir[i:])
    # Didn't resolve it.
    return None

if __name__ == '__main__':
    lib_dir = get_python_relative_libdir()
    if lib_dir is not None:
        sys.stdout.write(lib_dir)
        sys.exit(0)
    else:
        sys.exit(1)