summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/scripts/get_relative_lib_dir.py44
-rw-r--r--lldb/source/Host/CMakeLists.txt23
-rw-r--r--lldb/source/Host/posix/HostInfoPosix.cpp15
-rwxr-xr-xlldb/www/build.html2
4 files changed, 83 insertions, 1 deletions
diff --git a/lldb/scripts/get_relative_lib_dir.py b/lldb/scripts/get_relative_lib_dir.py
new file mode 100644
index 00000000000..f7020d653fd
--- /dev/null
+++ b/lldb/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)
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index 7632c579229..2d518ca3991 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -41,6 +41,11 @@ add_host_subdirectory(common
common/XML.cpp
)
+# Keep track of whether we want to provide a define for the
+# Python's architecture-specific lib path (i.e. where a
+# Python lldb module would go).
+set (get_python_libdir 0)
+
if (NOT LLDB_DISABLE_LIBEDIT)
add_host_subdirectory(common
common/Editline.cpp
@@ -70,6 +75,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
windows/Windows.cpp
)
else()
+ if (NOT LLDB_DISABLE_PYTHON)
+ # We'll grab the arch-specific python libdir on POSIX systems.
+ set (get_python_libdir 1)
+ endif()
+
add_host_subdirectory(posix
posix/FileSystem.cpp
posix/HostInfoPosix.cpp
@@ -133,4 +143,17 @@ else()
endif()
endif()
+if (${get_python_libdir})
+ # Call a python script to gather the arch-specific libdir for
+ # modules like the lldb module.
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/get_relative_lib_dir.py
+ RESULT_VARIABLE get_libdir_status
+ OUTPUT_VARIABLE relative_libdir
+ )
+ if (get_libdir_status EQUAL 0)
+ add_definitions(-DLLDB_PYTHON_RELATIVE_LIBDIR="${relative_libdir}")
+ endif()
+endif()
+
add_lldb_library(lldbHost ${HOST_SOURCES})
diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp
index 7ca9f7da3fc..cfdbf5635ad 100644
--- a/lldb/source/Host/posix/HostInfoPosix.cpp
+++ b/lldb/source/Host/posix/HostInfoPosix.cpp
@@ -22,6 +22,7 @@
#include <mutex>
#include <netdb.h>
#include <pwd.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
@@ -214,6 +215,19 @@ HostInfoPosix::ComputePythonDirectory(FileSpec &file_spec)
char raw_path[PATH_MAX];
lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
+#if defined(LLDB_PYTHON_RELATIVE_LIBDIR)
+ // Build the path by backing out of the lib dir, then building
+ // with whatever the real python interpreter uses. (e.g. lib
+ // for most, lib64 on RHEL x86_64).
+ char python_path[PATH_MAX];
+ ::snprintf(python_path, sizeof(python_path), "%s/../%s", raw_path, LLDB_PYTHON_RELATIVE_LIBDIR);
+
+ char final_path[PATH_MAX];
+ realpath(python_path, final_path);
+ file_spec.GetDirectory().SetCString(final_path);
+
+ return true;
+#else
llvm::SmallString<256> python_version_dir;
llvm::raw_svector_ostream os(python_version_dir);
os << "/python" << PY_MAJOR_VERSION << '.' << PY_MINOR_VERSION << "/site-packages";
@@ -223,6 +237,7 @@ HostInfoPosix::ComputePythonDirectory(FileSpec &file_spec)
file_spec.GetDirectory().SetCString(raw_path);
return true;
+#endif
#else
return false;
#endif
diff --git a/lldb/www/build.html b/lldb/www/build.html
index e84c5b9b4cd..08373ce921d 100755
--- a/lldb/www/build.html
+++ b/lldb/www/build.html
@@ -202,7 +202,7 @@
<li><a href="http://www.python.org">Python</a></li>
</ul>
<p>So for example, on a Fedora system one might run:</p>
- <code>&gt; yum install swig python-devel libedit-devel</code>
+ <code>&gt; yum install libedit-devel libxml2-devel ncurses-devel python-devel swig</code>
<p>On a Debian or Ubuntu system one might run:</p>
<code>&gt; sudo apt-get install build-essential subversion swig python2.7-dev libedit-dev libncurses5-dev </code>
<p>or</p>
OpenPOWER on IntegriCloud