summaryrefslogtreecommitdiff
path: root/scripts/get_relative_lib_dir.py
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
commit9e6d35490a6542f9c97607f93c2ef8ca8e03cbcc (patch)
treedd2a1ddf0476664c2b823409c36cbccd52662ca7 /scripts/get_relative_lib_dir.py
parent3bd2e91faeb9eeec1aae82c64a3253afff551cfd (diff)
Notes
Diffstat (limited to 'scripts/get_relative_lib_dir.py')
-rw-r--r--scripts/get_relative_lib_dir.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/get_relative_lib_dir.py b/scripts/get_relative_lib_dir.py
new file mode 100644
index 0000000000000..f7020d653fddc
--- /dev/null
+++ b/scripts/get_relative_lib_dir.py
@@ -0,0 +1,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)